-
Notifications
You must be signed in to change notification settings - Fork 17
SIP-30: Entropy Source Identifiers #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3d7bdaf
feat(SIP-30): Add SIP-30
shane-t 43d32b7
Include a section describing the default behaviour
shane-t b4d37c6
chore: add new method to list available entropy sources
shane-t a737142
chore: implement changes requested by @FredrikBolding
shane-t 207518f
chore: change snap_listAvailableEntropySources to snap_listEntropySou…
shane-t 3165fef
chore: allow all entropy requestors to list entropy souces
shane-t 5bcb037
chore: standardise formatting of params + mark source optional
shane-t b02b615
chore: formatting changes, alphabetise curves, fix errors
shane-t fe52f7d
chore: add suggestions from @FrederikBolding
shane-t 17586db
chore: fix EntropySource type
shane-t 7207f07
chore: s/wallet/client
shane-t b50371a
chore: fix some markdown spacing issues suggested by @Mrtenz
shane-t 90b8c3a
Remove additional newline
FrederikBolding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| --- | ||
| sip: 30 | ||
| title: Entropy Source Identifiers | ||
| status: Draft | ||
| author: Shane T Odlum (@shane-t) | ||
| created: 2024-12-17 | ||
| --- | ||
|
|
||
| ## Abstract | ||
|
|
||
| This SIP proposes additions to entropy retrieval APIs that allows snaps to request entropy from a specific source. | ||
|
|
||
| ## Motivation | ||
|
|
||
| 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. | ||
|
|
||
| These methods assume the client contains a single entropy source (the user's primary keyring mnemonic). The proposed API changes will allow snaps to request entropy from a specific source such as a secondary mnemonic. A new method `snap_listEntropySources` will be added to allow snaps to request a list of available entropy sources. | ||
|
|
||
| ## Specification | ||
|
|
||
| > Formal specifications are written in TypeScript. | ||
|
|
||
| ### Language | ||
|
|
||
| The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", | ||
| "NOT RECOMMENDED", "MAY", and "OPTIONAL" written in uppercase in this document are to be interpreted as described in | ||
| [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) | ||
|
|
||
| ### Snap Manifest | ||
|
|
||
| A new set permission is added to the snap manifest: | ||
|
|
||
| ```json | ||
| { | ||
| "initialPermissions": { | ||
| "snap_listEntropySources": {} | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| ### Common Types | ||
|
|
||
| ```typescript | ||
| type Slip10Node = { | ||
| depth: number; | ||
| parentFingerprint: number; | ||
| index: number; | ||
| privateKey: string; | ||
| publicKey: string; | ||
| chainCode: string; | ||
| curve: "ed25519" | "secp256k1"; | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export type BIP44Node = { | ||
| coin_type: number; | ||
| depth: number; | ||
| privateKey: string; | ||
| publicKey: string; | ||
| chainCode: string; | ||
| path: string[]; | ||
| }; | ||
|
|
||
| interface EntropySource { | ||
FrederikBolding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
danroc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: string; | ||
| id: string; | ||
| type: "mnemonic"; | ||
| primary: boolean; | ||
| } | ||
| ``` | ||
|
|
||
| ### Scope | ||
|
|
||
| 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. | ||
|
|
||
| ### Snap Manifest | ||
|
|
||
| No changes are required to the snap manifest. | ||
|
|
||
| ### Client Implementation | ||
|
|
||
| #### Entropy Sources | ||
|
|
||
| If a snap requests a list of available entropy sources, and it has the permission to do so, the wallet MUST return a list of `EntropySource` objects. | ||
|
|
||
| The client MUST have a primary entropy source, which is used when no source is specified. In the list of available entropy sources, the primary source MUST be marked as `primary: true`. | ||
|
|
||
| #### Handling Entropy Requests | ||
shane-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| If a snap requests entropy and includes the `source` parameter for an entropy source of type `mnemonic`, the wallet MUST return entropy corresponding to that source, if it exists. | ||
|
|
||
| If the source does not exist, the wallet MUST respond with an error. | ||
|
|
||
| If the request does not include the `source` parameter, the wallet MUST return entropy from the primary source. | ||
|
|
||
| #### Creating Accounts | ||
|
|
||
| A client MAY invoke the `keyring.createAccount` method with an `entropySource` parameter in the `options` object. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| ### Snap Implementation | ||
|
|
||
| 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. | ||
|
|
||
| ### New RPC Methods | ||
|
|
||
| #### `snap_listEntropySources` | ||
|
|
||
| The method returns an array of `EntropySource` objects, each representing an available entropy source. The Snap MAY choose to display this list to the user. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```typescript | ||
| const entropySources = await snap.request({ | ||
| method: "snap_listEntropySources", | ||
| }); | ||
| // [ | ||
| // { name: "Phrase 1", id: "phrase-1" }, | ||
| // { name: "Phrase 2", id: "phrase-2" }, | ||
| // ] | ||
| ``` | ||
|
|
||
| ### Existing RPC Methods | ||
|
|
||
| #### `snap_getEntropy` | ||
|
|
||
| ##### Parameters | ||
shane-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| An object containing: | ||
|
|
||
| - `version` - The number 1 | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `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. | ||
| - `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Returns | ||
shane-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| The entropy as a hexadecimal string. | ||
|
|
||
| #### Example | ||
|
|
||
| ```typescript | ||
| const entropy = await snap.request({ | ||
| method: "snap_getEntropy", | ||
| params: { | ||
| version: 2, | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| salt: "my-salt", | ||
| source: "1234-5678-9012-3456-7890", | ||
| }, | ||
| }); | ||
| // '0x1234567890abcdef' | ||
| ``` | ||
|
|
||
| #### `snap_getBip32Entropy` | ||
|
|
||
| ##### Parameters | ||
|
|
||
| - `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve. | ||
| - `source`: The ID of the entropy source to use. | ||
FrederikBolding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `curve`: The curve to use - `secp256k1` or `ed25519`. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ##### Returns | ||
|
|
||
| A `Slip10Node` object representing the BIP-32 HD tree node and containing its corresponding key material. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ##### Example | ||
|
|
||
| ```typescript | ||
| const node = await snap.request({ | ||
| method: "snap_getBip32Entropy", | ||
| params: { | ||
| path: ["m", "44", "0", "0", "0"], | ||
| source: "1234-5678-9012-3456-7890", | ||
| curve: "secp256k1", | ||
| }, | ||
| }); | ||
| // { | ||
| // depth: 5, | ||
| // parentFingerprint: 1234567890, | ||
| // index: 0, | ||
| // privateKey: '0x1234567890abcdef', | ||
| // publicKey: '0x1234567890abcdef', | ||
| // chainCode: '0x1234567890abcdef', | ||
| // curve: 'secp256k1', | ||
| // } | ||
| ``` | ||
|
|
||
| #### `snap_getBip32PublicKey` | ||
|
|
||
| ##### Parameters | ||
|
|
||
| - `path`: An array starting with `m` containing the BIP-32 derivation path of the key to retrieve. | ||
| - `source`: The ID of the entropy source to use. | ||
| - `curve`: The curve to use - `secp256k1` or `ed25519`. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `compressed`: Whether to return the public key in compressed format. (defaults to `false`) | ||
|
|
||
| ##### Returns | ||
|
|
||
| The public key as a hexadecimal string. | ||
|
|
||
| ##### Example | ||
|
|
||
| ```typescript | ||
| const publicKey = await snap.request({ | ||
| method: "snap_getBip32PublicKey", | ||
| params: { | ||
| path: ["m", "44", "0", "0", "0"], | ||
| source: "1234-5678-9012-3456-7890", | ||
| curve: "secp256k1", | ||
| compressed: true, | ||
| }, | ||
| }); | ||
| // '0x1234567890abcdef' | ||
| ``` | ||
|
|
||
| #### `snap_getBip44Entropy` | ||
|
|
||
| ##### Parameters | ||
shane-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| An object containing: | ||
|
|
||
| - `coin_type`: The BIP-44 coin type value of the node. | ||
| - `source` (optional) - The ID of the entropy source to use. If not specified, the default entropy source will be used. | ||
shane-t marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ##### Returns | ||
shane-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| A `BIP44Node` object representing the BIP-44 `coin_type` HD tree node and containing its corresponding key material. | ||
|
|
||
| ##### Example | ||
|
|
||
| ```typescript | ||
| const node = await snap.request({ | ||
| method: "snap_getBip44Entropy", | ||
| params: { | ||
| coin_type: 1, | ||
| source: "1234-5678-9012-3456-7890", | ||
| }, | ||
| }); | ||
| // { | ||
| // coin_type: 1, | ||
| // depth: 5, | ||
| // privateKey: '0x1234567890abcdef', | ||
| // publicKey: '0x1234567890abcdef', | ||
| // chainCode: '0x1234567890abcdef', | ||
| // path: ['m', '44', '0', '0', '0'], | ||
| // } | ||
| ``` | ||
|
|
||
|
|
||
danroc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Copyright | ||
|
|
||
| Copyright and related rights waived via [CC0](../LICENSE). | ||
|
|
||
| [keyring-api]: https://github.com/MetaMask/accounts/tree/main/packages/keyring-api | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.