@metamask-previews/multichain-account-service 0.3.0-preview-43d47013 → 0.3.0-preview-98faf75a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/providers/SolAccountProvider.cjs +25 -29
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +0 -1
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +0 -1
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +26 -30
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _SolAccountProvider_instances, _a, _SolAccountProvider_createAccount;
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.SolAccountProvider = void 0;
|
|
10
4
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
11
5
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
12
6
|
const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
|
|
13
7
|
class SolAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
_SolAccountProvider_instances.add(this);
|
|
17
|
-
}
|
|
18
8
|
isAccountCompatible(account) {
|
|
19
9
|
return (account.type === keyring_api_1.SolAccountType.DataAccount &&
|
|
20
10
|
account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
|
|
21
11
|
}
|
|
22
12
|
async createAccounts({ entropySource, groupIndex, }) {
|
|
13
|
+
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
14
|
+
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
15
|
+
// without triggering UI confirmation.
|
|
16
|
+
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
17
|
+
// account will get created and persisted properly with the Snap account creation
|
|
18
|
+
// flow "asynchronously" (with `notify:accountCreated`).
|
|
19
|
+
const createAccount = await this.withKeyring({ type: keyring_controller_1.KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
20
|
+
// Create account without any confirmation nor selecting it.
|
|
23
21
|
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
24
22
|
// type once ready.
|
|
25
|
-
const
|
|
23
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
24
|
+
const account = await createAccount(SolAccountProvider.SOLANA_SNAP_ID, {
|
|
26
25
|
entropySource,
|
|
27
|
-
derivationPath
|
|
26
|
+
derivationPath,
|
|
27
|
+
}, {
|
|
28
|
+
displayAccountNameSuggestion: false,
|
|
29
|
+
displayConfirmation: false,
|
|
30
|
+
setSelectedAccount: false,
|
|
28
31
|
});
|
|
32
|
+
// Solana Snap does not use BIP-44 typed options for the moment
|
|
33
|
+
// so we "inject" them (the `AccountsController` does a similar thing
|
|
34
|
+
// for the moment).
|
|
35
|
+
account.options.entropy = {
|
|
36
|
+
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
|
|
37
|
+
id: entropySource,
|
|
38
|
+
groupIndex,
|
|
39
|
+
derivationPath,
|
|
40
|
+
};
|
|
41
|
+
(0, BaseAccountProvider_1.assertIsBip44Account)(account);
|
|
29
42
|
return [account];
|
|
30
43
|
}
|
|
31
44
|
async discoverAndCreateAccounts(_) {
|
|
@@ -33,22 +46,5 @@ class SolAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
|
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
exports.SolAccountProvider = SolAccountProvider;
|
|
36
|
-
_a = SolAccountProvider, _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_createAccount = async function _SolAccountProvider_createAccount(opts) {
|
|
37
|
-
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
38
|
-
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
39
|
-
// without triggering UI confirmation.
|
|
40
|
-
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
41
|
-
// account will get created and persisted properly with the Snap account creation
|
|
42
|
-
// flow "asynchronously" (with `notify:accountCreated`).
|
|
43
|
-
const createAccount = await this.withKeyring({ type: keyring_controller_1.KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
44
|
-
// Create account without any confirmation nor selecting it.
|
|
45
|
-
const account = await createAccount(_a.SOLANA_SNAP_ID, opts, {
|
|
46
|
-
displayAccountNameSuggestion: false,
|
|
47
|
-
displayConfirmation: false,
|
|
48
|
-
setSelectedAccount: false,
|
|
49
|
-
});
|
|
50
|
-
(0, BaseAccountProvider_1.assertIsBip44Account)(account);
|
|
51
|
-
return account;
|
|
52
|
-
};
|
|
53
49
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
54
50
|
//# sourceMappingURL=SolAccountProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AAGA,uDAG+B;AAC/B,qEAA4D;AAI5D,mEAG+B;AAE/B,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,iCAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,4DAA4D;QAC5D,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CACjC,kBAAkB,CAAC,cAAc,EACjC;YACE,aAAa;YACb,cAAc;SACf,EACD;YACE,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CACF,CAAC;QAEF,+DAA+D;QAC/D,qEAAqE;QACrE,mBAAmB;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AAnEH,gDAoEC;AAnEQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\nexport class SolAccountProvider extends BaseAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount(\n SolAccountProvider.SOLANA_SNAP_ID,\n {\n entropySource,\n derivationPath,\n },\n {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n },\n );\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n\n return [account];\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|
|
@@ -4,7 +4,6 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
|
4
4
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
5
5
|
import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
|
|
6
6
|
export declare class SolAccountProvider extends BaseAccountProvider {
|
|
7
|
-
#private;
|
|
8
7
|
static SOLANA_SNAP_ID: SnapId;
|
|
9
8
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
10
9
|
createAccounts({ entropySource, groupIndex, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAE/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;IAErE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;IA8CK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
|
|
@@ -4,7 +4,6 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
|
4
4
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
5
5
|
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
6
6
|
export declare class SolAccountProvider extends BaseAccountProvider {
|
|
7
|
-
#private;
|
|
8
7
|
static SOLANA_SNAP_ID: SnapId;
|
|
9
8
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
10
9
|
createAccounts({ entropySource, groupIndex, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAE/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;IAErE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;IA8CK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _SolAccountProvider_instances, _a, _SolAccountProvider_createAccount;
|
|
7
|
-
import { SolAccountType } from "@metamask/keyring-api";
|
|
1
|
+
import { KeyringAccountEntropyTypeOption, SolAccountType } from "@metamask/keyring-api";
|
|
8
2
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
9
3
|
import { assertIsBip44Account, BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
10
4
|
export class SolAccountProvider extends BaseAccountProvider {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
_SolAccountProvider_instances.add(this);
|
|
14
|
-
}
|
|
15
5
|
isAccountCompatible(account) {
|
|
16
6
|
return (account.type === SolAccountType.DataAccount &&
|
|
17
7
|
account.metadata.keyring.type === KeyringTypes.snap);
|
|
18
8
|
}
|
|
19
9
|
async createAccounts({ entropySource, groupIndex, }) {
|
|
10
|
+
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
11
|
+
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
12
|
+
// without triggering UI confirmation.
|
|
13
|
+
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
14
|
+
// account will get created and persisted properly with the Snap account creation
|
|
15
|
+
// flow "asynchronously" (with `notify:accountCreated`).
|
|
16
|
+
const createAccount = await this.withKeyring({ type: KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
17
|
+
// Create account without any confirmation nor selecting it.
|
|
20
18
|
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
21
19
|
// type once ready.
|
|
22
|
-
const
|
|
20
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
21
|
+
const account = await createAccount(SolAccountProvider.SOLANA_SNAP_ID, {
|
|
23
22
|
entropySource,
|
|
24
|
-
derivationPath
|
|
23
|
+
derivationPath,
|
|
24
|
+
}, {
|
|
25
|
+
displayAccountNameSuggestion: false,
|
|
26
|
+
displayConfirmation: false,
|
|
27
|
+
setSelectedAccount: false,
|
|
25
28
|
});
|
|
29
|
+
// Solana Snap does not use BIP-44 typed options for the moment
|
|
30
|
+
// so we "inject" them (the `AccountsController` does a similar thing
|
|
31
|
+
// for the moment).
|
|
32
|
+
account.options.entropy = {
|
|
33
|
+
type: KeyringAccountEntropyTypeOption.Mnemonic,
|
|
34
|
+
id: entropySource,
|
|
35
|
+
groupIndex,
|
|
36
|
+
derivationPath,
|
|
37
|
+
};
|
|
38
|
+
assertIsBip44Account(account);
|
|
26
39
|
return [account];
|
|
27
40
|
}
|
|
28
41
|
async discoverAndCreateAccounts(_) {
|
|
29
42
|
return []; // TODO: Implement account discovery.
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
|
-
_a = SolAccountProvider, _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_createAccount = async function _SolAccountProvider_createAccount(opts) {
|
|
33
|
-
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
34
|
-
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
35
|
-
// without triggering UI confirmation.
|
|
36
|
-
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
37
|
-
// account will get created and persisted properly with the Snap account creation
|
|
38
|
-
// flow "asynchronously" (with `notify:accountCreated`).
|
|
39
|
-
const createAccount = await this.withKeyring({ type: KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
40
|
-
// Create account without any confirmation nor selecting it.
|
|
41
|
-
const account = await createAccount(_a.SOLANA_SNAP_ID, opts, {
|
|
42
|
-
displayAccountNameSuggestion: false,
|
|
43
|
-
displayConfirmation: false,
|
|
44
|
-
setSelectedAccount: false,
|
|
45
|
-
});
|
|
46
|
-
assertIsBip44Account(account);
|
|
47
|
-
return account;
|
|
48
|
-
};
|
|
49
45
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
50
46
|
//# sourceMappingURL=SolAccountProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACpB,kCAA8B;AAE/B,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAGzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,4DAA4D;QAC5D,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CACjC,kBAAkB,CAAC,cAAc,EACjC;YACE,aAAa;YACb,cAAc;SACf,EACD;YACE,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CACF,CAAC;QAEF,+DAA+D;QAC/D,qEAAqE;QACrE,mBAAmB;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AAlEM,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\nexport class SolAccountProvider extends BaseAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount(\n SolAccountProvider.SOLANA_SNAP_ID,\n {\n entropySource,\n derivationPath,\n },\n {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n },\n );\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n\n return [account];\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|