Skip to content

Commit 9571b7a

Browse files
committed
feat(SIP-30): Add SIP-30
1 parent d2a8c29 commit 9571b7a

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

SIPS/sip-30.md

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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+
### Snap Manifest
55+
56+
No changes are required to the snap manifest.
57+
58+
### Client wallet implementation
59+
60+
A client wallet MAY invoke the `keyring.createAccount` method with an `entropySource` parameter in the `options` object.
61+
62+
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.
63+
64+
#### Snap implementation
65+
66+
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.
67+
68+
### RPC Methods
69+
70+
#### `snap_getEntropy`
71+
72+
##### Parameters
73+
An object containing:
74+
75+
- `version` - The number 2. Version `2` is the first version that allows specifying a source ID.
76+
- `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.
77+
- `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used.
78+
79+
#### Returns
80+
The entropy as a hexadecimal string.
81+
82+
#### Example
83+
84+
```typescript
85+
const entropy = await snap.request({
86+
method: "snap_getEntropy",
87+
params: {
88+
version: 2,
89+
salt: "my-salt",
90+
source: "1234-5678-9012-3456-7890",
91+
},
92+
});
93+
// '0x1234567890abcdef'
94+
```
95+
96+
#### `snap_getBip32Entropy`
97+
98+
##### Parameters
99+
100+
- `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve.
101+
- `source`: The ID of the entropy source to use.
102+
- `curve`: The curve to use - `secp256k1` or `ed25519`.
103+
104+
##### Returns
105+
106+
A `Slip10Node` object representing the BIP-32 HD tree node and containing its corresponding key material.
107+
108+
##### Example
109+
110+
```typescript
111+
const node = await snap.request({
112+
method: "snap_getBip32Entropy",
113+
params: {
114+
path: ["m", "44", "0", "0", "0"],
115+
source: "1234-5678-9012-3456-7890",
116+
curve: "secp256k1",
117+
},
118+
});
119+
// {
120+
// depth: 5,
121+
// parentFingerprint: 1234567890,
122+
// index: 0,
123+
// privateKey: '0x1234567890abcdef',
124+
// publicKey: '0x1234567890abcdef',
125+
// chainCode: '0x1234567890abcdef',
126+
// curve: 'secp256k1',
127+
// }
128+
```
129+
130+
#### `snap_getBip32PublicKeyFromSource`
131+
132+
##### Parameters
133+
134+
- `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve.
135+
- `source`: The ID of the entropy source to use.
136+
- `curve`: The curve to use - `secp256k1` or `ed25519`.
137+
- `compressed`: Whether to return the public key in compressed format. (defaults to `false`)
138+
139+
##### Returns
140+
141+
The public key as a hexadecimal string.
142+
143+
##### Example
144+
145+
```typescript
146+
const publicKey = await snap.request({
147+
method: "snap_getBip32PublicKeyFromSource",
148+
params: {
149+
path: ["m", "44", "0", "0", "0"],
150+
source: "1234-5678-9012-3456-7890",
151+
curve: "secp256k1",
152+
compressed: true,
153+
},
154+
});
155+
// '0x1234567890abcdef'
156+
```
157+
158+
#### `snap_getBip44Entropy`
159+
160+
##### Parameters
161+
An object containing:
162+
163+
- `coin_type`: The BIP-44 coin type value of the node.
164+
- `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used.
165+
166+
##### Returns
167+
A `BIP44Node` object representing the BIP-44 `coin_type` HD tree node and containing its corresponding key material.
168+
169+
##### Example
170+
171+
```typescript
172+
const node = await snap.request({
173+
method: "snap_getBip44Entropy",
174+
params: {
175+
coin_type: 1,
176+
source: "1234-5678-9012-3456-7890",
177+
},
178+
});
179+
// {
180+
// coin_type: 1,
181+
// depth: 5,
182+
// privateKey: '0x1234567890abcdef',
183+
// publicKey: '0x1234567890abcdef',
184+
// chainCode: '0x1234567890abcdef',
185+
// path: ['m', '44', '0', '0', '0'],
186+
// }
187+
```
188+
189+
190+
## Copyright
191+
192+
Copyright and related rights waived via [CC0](../LICENSE).
193+
194+
[keyring-api]: https://github.com/MetaMask/accounts/tree/main/packages/keyring-api

0 commit comments

Comments
 (0)