Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions yarn-project/foundation/src/fields/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,18 @@ export class Fr extends BaseField {
}

/**
* Creates a Fr instance from a hex string.
* @param buf - a hex encoded string.
* Creates a Fr instance from a string.
* @param buf - string with value.
* @param encoding - the encoding to use (default: hex)
* @returns the Fr instance
*/
static fromString(buf: string) {
return fromHexString(buf, Fr);
}
static fromString(buf: string, encoding: 'hex' | 'dec' = 'hex') {
if (encoding === 'hex') {
return fromHexString(buf, Fr);
}

return new Fr(BigInt(buf));
}
/** Arithmetic */

add(rhs: Fr) {
Expand Down Expand Up @@ -369,12 +373,17 @@ export class Fq extends BaseField {
}

/**
* Creates a Fq instance from a hex string.
* @param buf - a hex encoded string.
* Creates a Fq instance from a string.
* @param buf - string with value.
* @param encoding - the encoding to use (default: hex)
* @returns the Fq instance
*/
static fromString(buf: string) {
return fromHexString(buf, Fq);
static fromString(buf: string, encoding: 'hex' | 'dec' = 'hex') {
if (encoding === 'hex') {
return fromHexString(buf, Fq);
}

return new Fq(BigInt(buf));
}

static fromHighLow(high: Fr, low: Fr): Fq {
Expand Down