Skip to content

Commit

Permalink
Merge pull request #6 from gaetbout/byte-array
Browse files Browse the repository at this point in the history
first draft
  • Loading branch information
gaetbout authored Jul 5, 2024
2 parents 21f0a15 + b4fb47b commit c11a38c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 115 deletions.
2 changes: 0 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createStore } from 'vuex'
import util from '@/store/modules/util'
import stark from '@/store/modules/stark'

export default createStore({
modules: {
util,
stark,
},
})
107 changes: 0 additions & 107 deletions src/store/modules/stark.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/store/modules/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// import { getStarknet } from "@argent/get-starknet";
// import { stark } from "starknet";
// const getSelectorFromName = stark.getSelectorFromName;

const state = {
utilPane: 1,
}
Expand Down
10 changes: 9 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BN from 'bn.js'
import { hash } from 'starknet'
import { hash, byteArray, CallData } from 'starknet'

function asciiToHex(str) {
let arr1 = ['0x']
Expand All @@ -17,6 +17,13 @@ function toSelector(val) {
return toBN(hash.getSelectorFromName(val))
}

function toByteArray(val) {
if (!val) {
return ''
}
return CallData.compile(byteArray.byteArrayFromString(val)).toString()
}

function toBN(val) {
if (!val) {
return ''
Expand Down Expand Up @@ -113,6 +120,7 @@ export default {
toBig3,
isDecimal,
toHex,
toByteArray,
toSelector,
startWith0xAndIsHex,
}
8 changes: 7 additions & 1 deletion src/views/Converter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
:dataBag="feltArrayComp"
title="felt array:"
/>
<SimpleCopyComponent
:dataBag="byteArrayComp"
title="byte array:"
/>
<ToggleComponent :dataBag="outSelectorComp" title="selector:" />
<ToggleComponent
:dataBag="out256Comp"
Expand Down Expand Up @@ -90,9 +94,11 @@ export default {
.slice(0, -1)
return { val }
},
byteArrayComp() {
return { val: utils.toByteArray(this.input) }
},
outSelectorComp() {
const val = utils.toSelector(this.input)
console.log(val)
const inFmt = !utils.isDecimal(this.input) && !this.isHexInput()
const test = new BN(utils.toBN(val))
const valid = this.isLessThanMaxVal(test)
Expand Down

0 comments on commit c11a38c

Please sign in to comment.