Skip to content

Commit 9b962ab

Browse files
committed
Better generateKeyPair
1 parent 381475a commit 9b962ab

File tree

6 files changed

+141
-246
lines changed

6 files changed

+141
-246
lines changed

packages/loopring-sdk/src/lib/generateKeyPair.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,49 @@ describe('generateKeyPair', () => {
4747
{ address: '0x2345', message: '0x3456', signature: '0x1234' },
4848
]);
4949
});
50+
51+
it('generateKeyPair - leading 0s', async () => {
52+
const signMessageAsync = jest.fn();
53+
const verifyMessage = jest.fn();
54+
const signature =
55+
'0x00c4fafca785d8b4da5e15265e4e58767a3f2502cdea2fcc4408cee5149e2a697fb7aaba14dceb096abd78cd4e9576859dcef262a4b51f2bb4554ebfd4fb72f5cf02';
56+
57+
signMessageAsync.mockResolvedValueOnce(signature);
58+
verifyMessage.mockResolvedValueOnce(true);
59+
60+
await expect(
61+
generateKeyPair({
62+
signMessageAsync,
63+
verifyMessage,
64+
keySeed: '0x3456',
65+
account: '0x2345',
66+
accountId: 1,
67+
chainId: 1,
68+
})
69+
).resolves.toEqual({
70+
keyPair: {
71+
publicKeyX:
72+
'13177128602008476316648007186770414467529839960903001891999762356783519376339',
73+
publicKeyY:
74+
'12345804151819755343032722751269003874303422211927604135345729794881772258791',
75+
secretKey:
76+
'110363126876775936939184191137732252584845853294910358210190810231166593026',
77+
},
78+
formatedPx:
79+
'0x1d21fd9096f5e99a270d0692b2e88127669a6980029513b1ca1459bea0e423d3',
80+
formatedPy:
81+
'0x1b4b7a3ef37cb12bdd53c1dd25e71c032c6a06ab1490dbafc7c304bbbf1305e7',
82+
sk: '0x3e769be3e46e6ca29d3b493f3ddfd7b66b18f404f4bd6e9f3d51a791f9e802',
83+
});
84+
85+
expect(signMessageAsync.mock.calls).toHaveLength(1);
86+
expect(verifyMessage.mock.calls).toHaveLength(1);
87+
88+
expect(signMessageAsync.mock.calls[0]).toStrictEqual([
89+
{ message: '0x3456' },
90+
]);
91+
expect(verifyMessage.mock.calls[0]).toStrictEqual([
92+
{ address: '0x2345', message: '0x3456', signature: signature },
93+
]);
94+
});
5095
});

packages/loopring-wasm/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ go 1.20
44

55
// go get -u github.com/loopexchange-labs/go-loopring-sig@main
66

7-
require github.com/loopexchange-labs/go-loopring-sig v0.0.0-20230816231954-06add9013afa
7+
require github.com/loopexchange-labs/go-loopring-sig v0.0.0-20231009203347-168cb91c8188

packages/loopring-wasm/go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/leppaludi/loopring-sig v0.0.0-20230131191428-8eb9916bfe31 h1:tEfYKFl8sYzfe3c2jhezPE//1KjXbsqp6hgKVomYghw=
3-
github.com/leppaludi/loopring-sig v0.0.0-20230131191428-8eb9916bfe31/go.mod h1:M1u/Cq6wJNeMQUuZCVU/1YZ2zwkfsaPpB7sxRSRzgQE=
4-
github.com/loopexchange-labs/go-loopring-sig v0.0.0-20230816231954-06add9013afa h1:pGpSUCVWh+zYqUrQxSSj487GfXP/8LDMbVNGfFIYF3k=
5-
github.com/loopexchange-labs/go-loopring-sig v0.0.0-20230816231954-06add9013afa/go.mod h1:r/OyK4TCoWGfBJ+kXChmk1jrt8ncsMlncT7nEatdf90=
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/loopexchange-labs/go-loopring-sig v0.0.0-20231009203347-168cb91c8188 h1:tdTiOC+VutJbfjSaC9wGhGZLWGMtFjFdKPNfpZRm+gg=
3+
github.com/loopexchange-labs/go-loopring-sig v0.0.0-20231009203347-168cb91c8188/go.mod h1:r/OyK4TCoWGfBJ+kXChmk1jrt8ncsMlncT7nEatdf90=
64
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7-
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
5+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
86
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

packages/loopring-wasm/lock.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

packages/loopring-wasm/nft_order.go

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)