Skip to content

Commit

Permalink
support bigint constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-korotya committed Nov 7, 2024
1 parent ccf6422 commit aa33f7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ export class Claim {
return this;
}

fromBigInts(raw: bigint[]): Claim {
if (raw.length !== this._index.length + this._value.length) {
throw new Error("invalid number of claim's slots");
}
for (let i = 0; i < 4; i++) {
this._index[i].setBigInt(raw[i]);
this._value[i].setBigInt(raw[i + 4]);
}
return this;
}

unMarshalBinary(data: Uint8Array): void {
const wantLen = 2 * Constants.ELEM_BYTES_LENGTH * Constants.BYTES_LENGTH;
if (data.length !== wantLen) {
Expand Down
19 changes: 19 additions & 0 deletions tests/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,25 @@ describe('claim test', () => {
});
});

describe('from constructors', () => {
it('fromBigInts', () => {
// this test was synthesized with golang test
const ints = [
BigInt("3537648966163034177119037898189471968122"),
BigInt("25999649578069426716666405683037372395789852830344252783677755850030715394"),
BigInt("657065114158124047812701241180089030040156354062"),
BigInt("1995762661"),
BigInt("58718019808110235945021734914"),
BigInt("0"),
BigInt("0"),
BigInt("0"),
]
const c = (new Claim).fromBigInts(ints);
const userId = c.getId();
expect(userId.string()).toEqual("2qNkLwz97jdzZBkdJYwVdXyGARGfVSGLJxELVC9ceH");
});
});

it('set index ID value', () => {
const id = Id.fromString('ww9xPmW6U3k6XatpaPPWbqPgUqW2Ct6AhsGNuYGm2');
const claim = new Claim();
Expand Down

0 comments on commit aa33f7a

Please sign in to comment.