Skip to content

Commit 3d7bdaf

Browse files
committed
feat(SIP-30): Add SIP-30
1 parent d2a8c29 commit 3d7bdaf

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

SIPS/sip-30.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
sip: 30
3+
title: Entropy Source Identifiers
4+
status: Draft
5+
author: Shane T Odlum (@shane-t)
6+
created: 2024-12-17
7+
---
8+
9+
## Abstract
10+
11+
This SIP proposes additions to entropy retrieval APIs that allows snaps to request entropy from a specific source.
12+
13+
## Motivation
14+
15+
Interoperability snaps and account management snaps use the methods `snap_getEntropy`, `snap_getBip44Entropy`, `snap_getBip32Entropy`, and `snap_getBip32PublicKey` to generate addresses and other key material.
16+
17+
These methods assume the client contains a single entropy source (the user's primary keyring mnemonic). The proposed API will allow snaps to request entropy from a specific source such as a secondary mnemonic.
18+
19+
## Specification
20+
21+
> Formal specifications are written in TypeScript.
22+
23+
### Language
24+
25+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED",
26+
"NOT RECOMMENDED", "MAY", and "OPTIONAL" written in uppercase in this document are to be interpreted as described in
27+
[RFC 2119](https://www.ietf.org/rfc/rfc2119.txt)
28+
29+
30+
### Common Types
31+
```typescript
32+
type Slip10Node = {
33+
depth: number;
34+
parentFingerprint: number;
35+
index: number;
36+
privateKey: string;
37+
publicKey: string;
38+
chainCode: string;
39+
curve: "ed25519" | "secp256k1";
40+
};
41+
```
42+
43+
```typescript
44+
export type BIP44Node = {
45+
coin_type: number;
46+
depth: number;
47+
privateKey: string;
48+
publicKey: string;
49+
chainCode: string;
50+
path: string[];
51+
};
52+
```
53+
54+
### Scope
55+
56+
This SIP applies to snaps that implement the [Keyring API][keyring-api] and any others which use the `snap_getEntropy`, `snap_getBip44Entropy`, `snap_getBip32Entropy`, and `snap_getBip32PublicKey` methods.
57+
58+
### Snap Manifest
59+
60+
No changes are required to the snap manifest.
61+
62+
### Client wallet implementation
63+
64+
A client wallet MAY invoke the `keyring.createAccount` method with an `entropySource` parameter in the `options` object.
65+
66+
The `entropySource` parameter MUST be a string which uniquely identifies the entropy source to use. It is not guaranteed to be the same string visible to any other snap, but should always refer to the same source in the context of interactions between the snap and the client wallet.
67+
68+
#### Snap implementation
69+
70+
If a snap is asked to create an account via `keyring.createAccount`, and the `entropySource` parameter is provided, and the snap requires entropy to create an account,the snap SHOULD request the entropy from the specified source.
71+
72+
### RPC Methods
73+
74+
#### `snap_getEntropy`
75+
76+
##### Parameters
77+
An object containing:
78+
79+
- `version` - The number 2. Version `2` is the first version that allows specifying a source ID.
80+
- `salt` (optional) - An arbitrary string to be used as a salt for the entropy. This can be used to generate different entropy for different purposes.
81+
- `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used.
82+
83+
#### Returns
84+
The entropy as a hexadecimal string.
85+
86+
#### Example
87+
88+
```typescript
89+
const entropy = await snap.request({
90+
method: "snap_getEntropy",
91+
params: {
92+
version: 2,
93+
salt: "my-salt",
94+
source: "1234-5678-9012-3456-7890",
95+
},
96+
});
97+
// '0x1234567890abcdef'
98+
```
99+
100+
#### `snap_getBip32Entropy`
101+
102+
##### Parameters
103+
104+
- `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve.
105+
- `source`: The ID of the entropy source to use.
106+
- `curve`: The curve to use - `secp256k1` or `ed25519`.
107+
108+
##### Returns
109+
110+
A `Slip10Node` object representing the BIP-32 HD tree node and containing its corresponding key material.
111+
112+
##### Example
113+
114+
```typescript
115+
const node = await snap.request({
116+
method: "snap_getBip32Entropy",
117+
params: {
118+
path: ["m", "44", "0", "0", "0"],
119+
source: "1234-5678-9012-3456-7890",
120+
curve: "secp256k1",
121+
},
122+
});
123+
// {
124+
// depth: 5,
125+
// parentFingerprint: 1234567890,
126+
// index: 0,
127+
// privateKey: '0x1234567890abcdef',
128+
// publicKey: '0x1234567890abcdef',
129+
// chainCode: '0x1234567890abcdef',
130+
// curve: 'secp256k1',
131+
// }
132+
```
133+
134+
#### `snap_getBip32PublicKeyFromSource`
135+
136+
##### Parameters
137+
138+
- `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve.
139+
- `source`: The ID of the entropy source to use.
140+
- `curve`: The curve to use - `secp256k1` or `ed25519`.
141+
- `compressed`: Whether to return the public key in compressed format. (defaults to `false`)
142+
143+
##### Returns
144+
145+
The public key as a hexadecimal string.
146+
147+
##### Example
148+
149+
```typescript
150+
const publicKey = await snap.request({
151+
method: "snap_getBip32PublicKeyFromSource",
152+
params: {
153+
path: ["m", "44", "0", "0", "0"],
154+
source: "1234-5678-9012-3456-7890",
155+
curve: "secp256k1",
156+
compressed: true,
157+
},
158+
});
159+
// '0x1234567890abcdef'
160+
```
161+
162+
#### `snap_getBip44Entropy`
163+
164+
##### Parameters
165+
An object containing:
166+
167+
- `coin_type`: The BIP-44 coin type value of the node.
168+
- `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used.
169+
170+
##### Returns
171+
A `BIP44Node` object representing the BIP-44 `coin_type` HD tree node and containing its corresponding key material.
172+
173+
##### Example
174+
175+
```typescript
176+
const node = await snap.request({
177+
method: "snap_getBip44Entropy",
178+
params: {
179+
coin_type: 1,
180+
source: "1234-5678-9012-3456-7890",
181+
},
182+
});
183+
// {
184+
// coin_type: 1,
185+
// depth: 5,
186+
// privateKey: '0x1234567890abcdef',
187+
// publicKey: '0x1234567890abcdef',
188+
// chainCode: '0x1234567890abcdef',
189+
// path: ['m', '44', '0', '0', '0'],
190+
// }
191+
```
192+
193+
194+
## Copyright
195+
196+
Copyright and related rights waived via [CC0](../LICENSE).
197+
198+
[keyring-api]: https://github.com/MetaMask/accounts/tree/main/packages/keyring-api

0 commit comments

Comments
 (0)