Skip to content

Commit

Permalink
refactor: allow BigNumber inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefbiiko committed Feb 21, 2024
1 parent 33fef57 commit c2af09c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ function total(...x) {
}, 0)
}

/**
* Coerces given (string) scalar(s) to bigints.
* @param {number|string|bigint} x Scalar
* @return {bigint}
*/
function toBigInt(x) {
if (Array.isArray(x)) {
return x.map(v =>
Array.isArray(v)
? toBigInt(v)
: typeof v !== "bigint"
? BigInt(v.toString())
: v,
)
} else {
return typeof x !== "bigint" ? BigInt(x.toString()) : x
}
}

/**
* Serializes given gnark inputs to a binary full witness.
* @param {Object} inputs Must only contain bigint (arrays), no nested objects.
Expand All @@ -76,7 +95,7 @@ export default function serialize(
? opts.publicOnly
: false
const out = []
console.log("PUB ONLY", publicOnly)

// sort public/secret inputs
const pubs = []
const secs = []
Expand All @@ -85,9 +104,9 @@ export default function serialize(
throw Error("nested objects not supported")
}
if (publics[k] === true) {
pubs.push(v)
pubs.push(toBigInt(v))
} else if (!publicOnly) {
secs.push(v)
secs.push(toBigInt(v))
}
}

Expand Down

0 comments on commit c2af09c

Please sign in to comment.