Skip to content

Commit

Permalink
Fixed the bug in P256Lib caused by reference type
Browse files Browse the repository at this point in the history
  • Loading branch information
jayden-sudo authored Oct 19, 2023
2 parents 5e656c8 + 16fbc61 commit bbf49d6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-garlics-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@soulwallet/sdk": patch
---

Fix a bug in P256Lib caused by reference type
46 changes: 46 additions & 0 deletions packages/soulwallet-sdk/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,50 @@ describe('SDK', () => {
const expectSignature = '0x00022ae3ddfe4cc414dc0fad7ff3a5c960d1cee1211722d3099ade76e5ac1826731a87e5d654f357e4cd6cb52512b2da4d91eae0ae48e9d892ce532b9352f63a55d61c0025000049960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000222c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a35353030222c2263726f73734f726967696e223a66616c73657d';
expect(signature.OK).toBe(expectSignature);
});

test('packUserOpP256Signature-1', async () => {
const soulwallet = new SoulWallet('https://localhost/', 'https://localhost/', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000');
const signature = await soulwallet.packUserOpP256Signature({
messageHash: '0xd45f9c36f42a0a149e3b77dec8597563235ff5463bf2c9af2f3e75cbd6eb6935',
publicKey: {
x: '0x6af4a0dbda88d45e4c6d0c97784671e44df2896a06b1200bf5ab9c2f54c7aca3',
y: '0xa439bdd51a1af33dbd97cc917ba103ce0694e46c4ad56d079991a0307364f956'
},
r: '0x8da3e1aa957bbefb34926bf9ee3892e4a27ee96cd54309deb23ba0151fb255c7',
s: '0xb2587548067b70aee24b25424aa515bd5b452424e3ab0451834da7d43928ee3e',
authenticatorData: '0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000',
clientDataSuffix: '","origin":"http://localhost:8000","crossOrigin":false}'
}, '0x653120f7000065312f070000000000000000000000000000000000000000', undefined);
expect(signature.isOk()).toBe(true);
});
test('packUserOpP256Signature-2', async () => {
const soulwallet = new SoulWallet('https://localhost/', 'https://localhost/', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000');
const signature = await soulwallet.packUserOpP256Signature({
messageHash: '0xb494f6738df235dea972d9f88139ff6c1bec48a97cbf12a44e5f39562b20c34c',
publicKey: {
x: '0x6af4a0dbda88d45e4c6d0c97784671e44df2896a06b1200bf5ab9c2f54c7aca3',
y: '0xa439bdd51a1af33dbd97cc917ba103ce0694e46c4ad56d079991a0307364f956'
},
r: '0xd2d8837118f0063d3552b02734a749e52484d397ed1b4e35f0e01668b9942bb3',
s: '0x9a31d197eb2a3f05e616639efd116daa4cdd68d7124062cc22f83852e6422d6e',
authenticatorData: '0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000',
clientDataSuffix: '","origin":"http://localhost:8000","crossOrigin":false}'
}, '0x653120f7000065312f070000000000000000000000000000000000000000', undefined);
expect(signature.isOk()).toBe(true);
});
test('packUserOpP256Signature-3', async () => {
const soulwallet = new SoulWallet('https://localhost/', 'https://localhost/', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000');
const signature = await soulwallet.packUserOpP256Signature({
messageHash: '0x371406a3e3929737d36f8dfe36befd83f090d4975a520320a6c471dd61b9810b',
publicKey: {
x: '0x6af4a0dbda88d45e4c6d0c97784671e44df2896a06b1200bf5ab9c2f54c7aca3',
y: '0xa439bdd51a1af33dbd97cc917ba103ce0694e46c4ad56d079991a0307364f956'
},
r: '0x0d9263333c04157e474092d1700414e2fe5fe118948dddd17fd1f7c8f0f648f3',
s: '0x774875e034be9cb380630b9311d85ff4837d424a32dd6800772ab022cbaae627',
authenticatorData: '0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000',
clientDataSuffix: '","origin":"http://localhost:8000","crossOrigin":false}'
}, '0x653120f7000065312f070000000000000000000000000000000000000000', undefined);
expect(signature.isOk()).toBe(true);
});
});
5 changes: 3 additions & 2 deletions packages/soulwallet-sdk/src/tools/p256lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class P256Lib {
}
const H = P256Lib.ecAff_add(new Point(gx, gy), point); //will not work if Q=P, obvious forbidden private key
let index: bigint = BigInt(255);
let _point: Point = new Point(BigInt(0), BigInt(0));
const _point: Point = new Point(BigInt(0), BigInt(0));
{
let T4 = (((scalar_v >> index) & BigInt(1)) << BigInt(1)) + ((scalar_u >> index) & BigInt(1));
while (T4 === BigInt(0)) {
Expand All @@ -197,7 +197,8 @@ export class P256Lib {
_point.x = point.x;
_point.y = point.y;
} else if (T4 == BigInt(3)) {
_point = H;
_point.x = H.x;
_point.y = H.y;
}
}
index--;
Expand Down

0 comments on commit bbf49d6

Please sign in to comment.