Skip to content

Commit 7083782

Browse files
committed
Add SIP-30 source to all examples and test-snaps
1 parent 734b76d commit 7083782

File tree

23 files changed

+280
-125
lines changed

23 files changed

+280
-125
lines changed

packages/examples/packages/bip32/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ JSON-RPC methods:
5656
(ECDSA for `secp256k1` and EdDSA for `ed25519`).
5757

5858
For more information, you can refer to
59-
[the end-to-end tests](./src/index.test.ts).
59+
[the end-to-end tests](./src/index.test.tsx).

packages/examples/packages/bip32/snap.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SnapConfig } from '@metamask/snaps-cli';
22
import { resolve } from 'path';
33

44
const config: SnapConfig = {
5-
input: resolve(__dirname, 'src/index.ts'),
5+
input: resolve(__dirname, 'src/index.tsx'),
66
server: {
77
port: 8001,
88
},

packages/examples/packages/bip32/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "dzOD3mPn8PgVXC3LT3OtKqs09WIcvuYo/mIZGfhsTPw=",
10+
"shasum": "8dCMTEaTarO8HLw6wttq8EWYcBkG1F/d+gv/OG6sgts=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/bip32/src/index.test.ts renamed to packages/examples/packages/bip32/src/index.test.tsx

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@jest/globals';
22
import { assertIsConfirmationDialog, installSnap } from '@metamask/snaps-jest';
3-
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';
3+
import { Box, Copyable, Heading, Text } from '@metamask/snaps-sdk/jsx';
44

55
describe('onRpcRequest', () => {
66
it('throws an error if the requested method does not exist', async () => {
@@ -38,6 +38,23 @@ describe('onRpcRequest', () => {
3838
);
3939
});
4040

41+
it('returns an secp256k1 public key for a given BIP-32 path with a different source', async () => {
42+
const { request } = await installSnap();
43+
44+
const response = await request({
45+
method: 'getPublicKey',
46+
params: {
47+
path: ['m', "44'", "0'"],
48+
curve: 'secp256k1',
49+
source: 'alternative',
50+
},
51+
});
52+
53+
expect(response).toRespondWith(
54+
'0x04f72f0e3684b0d7295f391616f12a469070bfcd175c55366239047495a2c1c410b4d820fb4147de213a2d25fb19f9451354ad5949fc881a2d219529703416de73',
55+
);
56+
});
57+
4158
it('returns a compressed secp256k1 public key for a given BIP-32 path', async () => {
4259
const { request } = await installSnap();
4360

@@ -110,15 +127,14 @@ describe('onRpcRequest', () => {
110127
const ui = await response.getInterface();
111128
assertIsConfirmationDialog(ui);
112129
expect(ui).toRender(
113-
panel([
114-
heading('Signature request'),
115-
text(
116-
`Do you want to secp256k1 sign "Hello, world!" with the following public key?`,
117-
),
118-
copyable(
119-
'0x0423a6a6f8800b2d0710595969f40148a28953c9eebc0c0da78a89be3b3935f59c0069dfe1cace1a083e9c962c9f2ef932e9346cd907e647d993d787c4e59d03d1',
120-
),
121-
]),
130+
<Box>
131+
<Heading>Signature request</Heading>
132+
<Text>
133+
Do you want to {'secp256k1'} sign "{'Hello, world!'}" with the
134+
following public key?
135+
</Text>
136+
<Copyable value="0x0423a6a6f8800b2d0710595969f40148a28953c9eebc0c0da78a89be3b3935f59c0069dfe1cace1a083e9c962c9f2ef932e9346cd907e647d993d787c4e59d03d1" />
137+
</Box>,
122138
);
123139

124140
await ui.ok();
@@ -128,6 +144,39 @@ describe('onRpcRequest', () => {
128144
);
129145
});
130146

147+
it('signs a message for the given BIP-32 path using secp256k1 with a different source', async () => {
148+
const { request } = await installSnap();
149+
150+
const response = request({
151+
method: 'signMessage',
152+
params: {
153+
path: ['m', "44'", "0'"],
154+
curve: 'secp256k1',
155+
message: 'Hello, world!',
156+
source: 'alternative',
157+
},
158+
});
159+
160+
const ui = await response.getInterface();
161+
assertIsConfirmationDialog(ui);
162+
expect(ui).toRender(
163+
<Box>
164+
<Heading>Signature request</Heading>
165+
<Text>
166+
Do you want to {'secp256k1'} sign "{'Hello, world!'}" with the
167+
following public key?
168+
</Text>
169+
<Copyable value="0x04f72f0e3684b0d7295f391616f12a469070bfcd175c55366239047495a2c1c410b4d820fb4147de213a2d25fb19f9451354ad5949fc881a2d219529703416de73" />
170+
</Box>,
171+
);
172+
173+
await ui.ok();
174+
175+
expect(await response).toRespondWith(
176+
'0x3044022049a3e74ed526df8b2a8e16e95a181d909255c90f6f63eb8efc16625af917b07d022014f2b203b0749058cbfc3ad0456c7b2bdf1ab809fd5913c6ee272cfc56f30ef2',
177+
);
178+
});
179+
131180
it('signs a message for the given BIP-32 path using ed25519', async () => {
132181
const { request } = await installSnap();
133182

@@ -143,15 +192,14 @@ describe('onRpcRequest', () => {
143192
const ui = await response.getInterface();
144193
assertIsConfirmationDialog(ui);
145194
expect(ui).toRender(
146-
panel([
147-
heading('Signature request'),
148-
text(
149-
`Do you want to ed25519 sign "Hello, world!" with the following public key?`,
150-
),
151-
copyable(
152-
'0x000b96ba23cae9597de51e0187d7ef1b2d1a782dc2d5ceac770a327de3844dd533',
153-
),
154-
]),
195+
<Box>
196+
<Heading>Signature request</Heading>
197+
<Text>
198+
Do you want to {'ed25519'} sign "{'Hello, world!'}" with the
199+
following public key?
200+
</Text>
201+
<Copyable value="0x000b96ba23cae9597de51e0187d7ef1b2d1a782dc2d5ceac770a327de3844dd533" />
202+
</Box>,
155203
);
156204

157205
await ui.ok();
@@ -176,15 +224,14 @@ describe('onRpcRequest', () => {
176224
const ui = await response.getInterface();
177225
assertIsConfirmationDialog(ui);
178226
expect(ui).toRender(
179-
panel([
180-
heading('Signature request'),
181-
text(
182-
`Do you want to ed25519Bip32 sign "Hello, world!" with the following public key?`,
183-
),
184-
copyable(
185-
'0x2c3ac523b470dead7981df46c93d894ed4381e94c23aa1ec3806a320ff8ceb42',
186-
),
187-
]),
227+
<Box>
228+
<Heading>Signature request</Heading>
229+
<Text>
230+
Do you want to {'ed25519Bip32'} sign "{'Hello, world!'}" with the
231+
following public key?
232+
</Text>
233+
<Copyable value="0x2c3ac523b470dead7981df46c93d894ed4381e94c23aa1ec3806a320ff8ceb42" />
234+
</Box>,
188235
);
189236

190237
await ui.ok();

packages/examples/packages/bip32/src/index.ts renamed to packages/examples/packages/bip32/src/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
22
import {
33
DialogType,
4-
panel,
5-
text,
6-
heading,
7-
copyable,
84
InvalidParamsError,
95
UserRejectedRequestError,
106
MethodNotFoundError,
117
} from '@metamask/snaps-sdk';
8+
import { Box, Copyable, Heading, Text } from '@metamask/snaps-sdk/jsx';
129
import {
1310
add0x,
1411
assert,
@@ -62,13 +59,16 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
6259
method: 'snap_dialog',
6360
params: {
6461
type: DialogType.Confirmation,
65-
content: panel([
66-
heading('Signature request'),
67-
text(
68-
`Do you want to ${curve} sign "${message}" with the following public key?`,
69-
),
70-
copyable(add0x(node.publicKey)),
71-
]),
62+
content: (
63+
<Box>
64+
<Heading>Signature request</Heading>
65+
<Text>
66+
Do you want to {curve} sign "{message}" with the following
67+
public key?
68+
</Text>
69+
<Copyable value={add0x(node.publicKey)} />
70+
</Box>
71+
),
7272
},
7373
});
7474

packages/examples/packages/bip32/src/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export type GetBip32PublicKeyParams = {
2020
*/
2121
compressed?: boolean | undefined;
2222

23+
/**
24+
* The entropy source to use for the signature. If not provided, the primary
25+
* entropy source will be used.
26+
*/
27+
source?: string | undefined;
28+
2329
/**
2430
* Miscellaneous parameters, which are passed to `snap_getBip32PublicKey`.
2531
*/
@@ -47,4 +53,10 @@ export type SignMessageParams = {
4753
* The curve used to derive the account.
4854
*/
4955
curve: 'secp256k1' | 'ed25519' | 'ed25519Bip32';
56+
57+
/**
58+
* The entropy source to use for the signature. If not provided, the primary
59+
* entropy source will be used.
60+
*/
61+
source?: string | undefined;
5062
};

packages/examples/packages/bip44/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ JSON-RPC methods:
4444
elliptic curve to sign the message.
4545

4646
For more information, you can refer to
47-
[the end-to-end tests](./src/index.test.ts).
47+
[the end-to-end tests](./src/index.test.tsx).

packages/examples/packages/bip44/snap.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SnapConfig } from '@metamask/snaps-cli';
22
import { resolve } from 'path';
33

44
const config: SnapConfig = {
5-
input: resolve(__dirname, 'src/index.ts'),
5+
input: resolve(__dirname, 'src/index.tsx'),
66
server: {
77
port: 8002,
88
},

packages/examples/packages/bip44/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "t0+OXVvAOnJOEgxjLB9Gz9CtAhNJr0nj9WC7nEeEZUs=",
10+
"shasum": "cCHLwOkIhbtImq9IkpDZhuNmE/sLspy4WWTMRLiCiDw=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/bip44/src/index.test.ts renamed to packages/examples/packages/bip44/src/index.test.tsx

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@jest/globals';
22
import { assertIsConfirmationDialog, installSnap } from '@metamask/snaps-jest';
3-
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';
3+
import { Box, Copyable, Heading, Text } from '@metamask/snaps-sdk/jsx';
44

55
describe('onRpcRequest', () => {
66
it('throws an error if the requested method does not exist', async () => {
@@ -38,6 +38,23 @@ describe('onRpcRequest', () => {
3838
);
3939
});
4040

41+
it('returns a BIP-44 public key for a given coin type and address index with a different source', async () => {
42+
const { request } = await installSnap();
43+
44+
const response = await request({
45+
method: 'getPublicKey',
46+
params: {
47+
coinType: 3,
48+
addressIndex: 5,
49+
source: 'alternative',
50+
},
51+
});
52+
53+
expect(response).toRespondWith(
54+
'0xadf494f336c373de010491dfb442a9dda4b6f640fbb81f0139deed7edb236817eaf8621722b01553134c4c91fbe89c45',
55+
);
56+
});
57+
4158
it('returns a BIP-44 public key for the default coin type and address index if no parameters are provided', async () => {
4259
const { request } = await installSnap();
4360

@@ -86,15 +103,14 @@ describe('onRpcRequest', () => {
86103
assertIsConfirmationDialog(ui);
87104

88105
expect(ui).toRender(
89-
panel([
90-
heading('Signature request'),
91-
text(
92-
`Do you want to BLS sign "Hello, world!" with the following public key?`,
93-
),
94-
copyable(
95-
'0x96e2b36a8af526928326683f6d8ddb82fbfcd1ba1cd3f0382a4f092a19fcb46b87e836dd34075514c9b1a3b8f7bdc4f0',
96-
),
97-
]),
106+
<Box>
107+
<Heading>Signature request</Heading>
108+
<Text>
109+
Do you want to BLS sign "{'Hello, world!'}" with the following
110+
public key?
111+
</Text>
112+
<Copyable value="0x96e2b36a8af526928326683f6d8ddb82fbfcd1ba1cd3f0382a4f092a19fcb46b87e836dd34075514c9b1a3b8f7bdc4f0" />
113+
</Box>,
98114
);
99115

100116
await ui.ok();
@@ -104,6 +120,40 @@ describe('onRpcRequest', () => {
104120
);
105121
});
106122

123+
it('signs a message for the given coin type and address index with a different source', async () => {
124+
const { request } = await installSnap();
125+
126+
const response = request({
127+
method: 'signMessage',
128+
params: {
129+
coinType: 3,
130+
addressIndex: 5,
131+
message: 'Hello, world!',
132+
source: 'alternative',
133+
},
134+
});
135+
136+
const ui = await response.getInterface();
137+
assertIsConfirmationDialog(ui);
138+
139+
expect(ui).toRender(
140+
<Box>
141+
<Heading>Signature request</Heading>
142+
<Text>
143+
Do you want to BLS sign "{'Hello, world!'}" with the following
144+
public key?
145+
</Text>
146+
<Copyable value="0xadf494f336c373de010491dfb442a9dda4b6f640fbb81f0139deed7edb236817eaf8621722b01553134c4c91fbe89c45" />
147+
</Box>,
148+
);
149+
150+
await ui.ok();
151+
152+
expect(await response).toRespondWith(
153+
'0xb01b6dd84f1aae227b25f8679d739508112c304819276843d057806e436cc0ccba16966e7b5b1bef1d55699531f31ed40908ce2a8d349e0bb5a8a5d840fb928b3fad499c6f117afdc740ac205d76c1ece8d4134822f88156243e926ddac99ab0',
154+
);
155+
});
156+
107157
it('signs a message using the default coin type and address index', async () => {
108158
const { request } = await installSnap();
109159

@@ -118,15 +168,14 @@ describe('onRpcRequest', () => {
118168
assertIsConfirmationDialog(ui);
119169

120170
expect(ui).toRender(
121-
panel([
122-
heading('Signature request'),
123-
text(
124-
`Do you want to BLS sign "Hello, world!" with the following public key?`,
125-
),
126-
copyable(
127-
'0xa9ad546540fca1662bdf3de110a456f2d825271e6d960cc5028224d4dc37c0e7fdd806b22fe94d9325548933e9c1ee68',
128-
),
129-
]),
171+
<Box>
172+
<Heading>Signature request</Heading>
173+
<Text>
174+
Do you want to BLS sign "{'Hello, world!'}" with the following
175+
public key?
176+
</Text>
177+
<Copyable value="0xa9ad546540fca1662bdf3de110a456f2d825271e6d960cc5028224d4dc37c0e7fdd806b22fe94d9325548933e9c1ee68" />
178+
</Box>,
130179
);
131180

132181
await ui.ok();

0 commit comments

Comments
 (0)