@metamask-previews/multichain-account-service 0.3.0-preview-0910ff0 → 0.3.0-preview-43d47013

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/MultichainAccountGroup.cjs +192 -0
  3. package/dist/MultichainAccountGroup.cjs.map +1 -0
  4. package/dist/MultichainAccountGroup.d.cts +84 -0
  5. package/dist/MultichainAccountGroup.d.cts.map +1 -0
  6. package/dist/MultichainAccountGroup.d.mts +84 -0
  7. package/dist/MultichainAccountGroup.d.mts.map +1 -0
  8. package/dist/MultichainAccountGroup.mjs +188 -0
  9. package/dist/MultichainAccountGroup.mjs.map +1 -0
  10. package/dist/MultichainAccountService.cjs +36 -23
  11. package/dist/MultichainAccountService.cjs.map +1 -1
  12. package/dist/MultichainAccountService.d.cts +26 -15
  13. package/dist/MultichainAccountService.d.cts.map +1 -1
  14. package/dist/MultichainAccountService.d.mts +26 -15
  15. package/dist/MultichainAccountService.d.mts.map +1 -1
  16. package/dist/MultichainAccountService.mjs +35 -22
  17. package/dist/MultichainAccountService.mjs.map +1 -1
  18. package/dist/MultichainAccountWallet.cjs +237 -0
  19. package/dist/MultichainAccountWallet.cjs.map +1 -0
  20. package/dist/MultichainAccountWallet.d.cts +91 -0
  21. package/dist/MultichainAccountWallet.d.cts.map +1 -0
  22. package/dist/MultichainAccountWallet.d.mts +91 -0
  23. package/dist/MultichainAccountWallet.d.mts.map +1 -0
  24. package/dist/MultichainAccountWallet.mjs +233 -0
  25. package/dist/MultichainAccountWallet.mjs.map +1 -0
  26. package/dist/index.cjs +5 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +3 -1
  29. package/dist/index.d.cts.map +1 -1
  30. package/dist/index.d.mts +3 -1
  31. package/dist/index.d.mts.map +1 -1
  32. package/dist/index.mjs +2 -0
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/providers/BaseAccountProvider.cjs +20 -1
  35. package/dist/providers/BaseAccountProvider.cjs.map +1 -1
  36. package/dist/providers/BaseAccountProvider.d.cts +25 -5
  37. package/dist/providers/BaseAccountProvider.d.cts.map +1 -1
  38. package/dist/providers/BaseAccountProvider.d.mts +25 -5
  39. package/dist/providers/BaseAccountProvider.d.mts.map +1 -1
  40. package/dist/providers/BaseAccountProvider.mjs +18 -0
  41. package/dist/providers/BaseAccountProvider.mjs.map +1 -1
  42. package/dist/providers/EvmAccountProvider.cjs +35 -0
  43. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  44. package/dist/providers/EvmAccountProvider.d.cts +66 -0
  45. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  46. package/dist/providers/EvmAccountProvider.d.mts +66 -0
  47. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  48. package/dist/providers/EvmAccountProvider.mjs +36 -1
  49. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  50. package/dist/providers/SolAccountProvider.cjs +39 -0
  51. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  52. package/dist/providers/SolAccountProvider.d.cts +28 -1
  53. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  54. package/dist/providers/SolAccountProvider.d.mts +28 -1
  55. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  56. package/dist/providers/SolAccountProvider.mjs +40 -1
  57. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  58. package/dist/tests/accounts.cjs +89 -4
  59. package/dist/tests/accounts.cjs.map +1 -1
  60. package/dist/tests/accounts.d.cts +235 -36
  61. package/dist/tests/accounts.d.cts.map +1 -1
  62. package/dist/tests/accounts.d.mts +235 -36
  63. package/dist/tests/accounts.d.mts.map +1 -1
  64. package/dist/tests/accounts.mjs +89 -4
  65. package/dist/tests/accounts.mjs.map +1 -1
  66. package/dist/tests/index.cjs +1 -0
  67. package/dist/tests/index.cjs.map +1 -1
  68. package/dist/tests/index.d.cts +1 -0
  69. package/dist/tests/index.d.cts.map +1 -1
  70. package/dist/tests/index.d.mts +1 -0
  71. package/dist/tests/index.d.mts.map +1 -1
  72. package/dist/tests/index.mjs +1 -0
  73. package/dist/tests/index.mjs.map +1 -1
  74. package/dist/tests/providers.cjs +28 -0
  75. package/dist/tests/providers.cjs.map +1 -0
  76. package/dist/tests/providers.d.cts +16 -0
  77. package/dist/tests/providers.d.cts.map +1 -0
  78. package/dist/tests/providers.d.mts +16 -0
  79. package/dist/tests/providers.d.mts.map +1 -0
  80. package/dist/tests/providers.mjs +23 -0
  81. package/dist/tests/providers.mjs.map +1 -0
  82. package/dist/types.cjs.map +1 -1
  83. package/dist/types.d.cts +11 -7
  84. package/dist/types.d.cts.map +1 -1
  85. package/dist/types.d.mts +11 -7
  86. package/dist/types.d.mts.map +1 -1
  87. package/dist/types.mjs.map +1 -1
  88. package/package.json +7 -4
@@ -1,7 +1,73 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
+ import type { EntropySourceId } from "@metamask/keyring-api";
2
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
3
4
  import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
4
5
  export declare class EvmAccountProvider extends BaseAccountProvider {
5
6
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
7
+ createAccounts({ entropySource, groupIndex, }: {
8
+ entropySource: EntropySourceId;
9
+ groupIndex: number;
10
+ }): Promise<({
11
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account";
12
+ id: string;
13
+ options: Record<string, import("@metamask/utils").Json> & {
14
+ entropy?: {
15
+ type: "mnemonic";
16
+ id: string;
17
+ derivationPath: string;
18
+ groupIndex: number;
19
+ } | {
20
+ type: "private-key";
21
+ } | undefined;
22
+ exportable?: boolean | undefined;
23
+ };
24
+ metadata: {
25
+ name: string;
26
+ importTime: number;
27
+ keyring: {
28
+ type: string;
29
+ };
30
+ nameLastUpdatedAt?: number | undefined;
31
+ snap?: {
32
+ name: string;
33
+ id: string;
34
+ enabled: boolean;
35
+ } | undefined;
36
+ lastSelected?: number | undefined;
37
+ };
38
+ address: string;
39
+ scopes: `${string}:${string}`[];
40
+ methods: string[];
41
+ } & {
42
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
43
+ id: string;
44
+ options: Record<string, import("@metamask/utils").Json> & {
45
+ entropy?: {
46
+ type: "mnemonic";
47
+ id: string;
48
+ derivationPath: string;
49
+ groupIndex: number;
50
+ } | {
51
+ type: "private-key";
52
+ } | undefined;
53
+ exportable?: boolean | undefined;
54
+ };
55
+ address: string;
56
+ scopes: `${string}:${string}`[];
57
+ methods: string[];
58
+ } & {
59
+ options: {
60
+ entropy: {
61
+ type: "mnemonic";
62
+ id: string;
63
+ derivationPath: string;
64
+ groupIndex: number;
65
+ };
66
+ };
67
+ })[]>;
68
+ discoverAndCreateAccounts(_: {
69
+ entropySource: EntropySourceId;
70
+ groupIndex: number;
71
+ }): Promise<never[]>;
6
72
  }
7
73
  //# sourceMappingURL=EvmAccountProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
1
+ {"version":3,"file":"EvmAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAEV,eAAe,EAChB,uCAAuC;AAGxC,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAgB/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiCK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
@@ -1,7 +1,73 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
+ import type { EntropySourceId } from "@metamask/keyring-api";
2
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
3
4
  import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
4
5
  export declare class EvmAccountProvider extends BaseAccountProvider {
5
6
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
7
+ createAccounts({ entropySource, groupIndex, }: {
8
+ entropySource: EntropySourceId;
9
+ groupIndex: number;
10
+ }): Promise<({
11
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account";
12
+ id: string;
13
+ options: Record<string, import("@metamask/utils").Json> & {
14
+ entropy?: {
15
+ type: "mnemonic";
16
+ id: string;
17
+ derivationPath: string;
18
+ groupIndex: number;
19
+ } | {
20
+ type: "private-key";
21
+ } | undefined;
22
+ exportable?: boolean | undefined;
23
+ };
24
+ metadata: {
25
+ name: string;
26
+ importTime: number;
27
+ keyring: {
28
+ type: string;
29
+ };
30
+ nameLastUpdatedAt?: number | undefined;
31
+ snap?: {
32
+ name: string;
33
+ id: string;
34
+ enabled: boolean;
35
+ } | undefined;
36
+ lastSelected?: number | undefined;
37
+ };
38
+ address: string;
39
+ scopes: `${string}:${string}`[];
40
+ methods: string[];
41
+ } & {
42
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
43
+ id: string;
44
+ options: Record<string, import("@metamask/utils").Json> & {
45
+ entropy?: {
46
+ type: "mnemonic";
47
+ id: string;
48
+ derivationPath: string;
49
+ groupIndex: number;
50
+ } | {
51
+ type: "private-key";
52
+ } | undefined;
53
+ exportable?: boolean | undefined;
54
+ };
55
+ address: string;
56
+ scopes: `${string}:${string}`[];
57
+ methods: string[];
58
+ } & {
59
+ options: {
60
+ entropy: {
61
+ type: "mnemonic";
62
+ id: string;
63
+ derivationPath: string;
64
+ groupIndex: number;
65
+ };
66
+ };
67
+ })[]>;
68
+ discoverAndCreateAccounts(_: {
69
+ entropySource: EntropySourceId;
70
+ groupIndex: number;
71
+ }): Promise<never[]>;
6
72
  }
7
73
  //# sourceMappingURL=EvmAccountProvider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
1
+ {"version":3,"file":"EvmAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAEV,eAAe,EAChB,uCAAuC;AAGxC,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAgB/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiCK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
@@ -1,10 +1,45 @@
1
1
  import { EthAccountType } from "@metamask/keyring-api";
2
2
  import { KeyringTypes } from "@metamask/keyring-controller";
3
- import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
3
+ import { assertIsBip44Account, BaseAccountProvider } from "./BaseAccountProvider.mjs";
4
+ /**
5
+ * Asserts an internal account exists.
6
+ *
7
+ * @param account - The internal account to check.
8
+ * @throws An error if the internal account does not exist.
9
+ */
10
+ function assertInternalAccountExists(account) {
11
+ if (!account) {
12
+ throw new Error('Internal account does not exist');
13
+ }
14
+ }
4
15
  export class EvmAccountProvider extends BaseAccountProvider {
5
16
  isAccountCompatible(account) {
6
17
  return (account.type === EthAccountType.Eoa &&
7
18
  account.metadata.keyring.type === KeyringTypes.hd);
8
19
  }
20
+ async createAccounts({ entropySource, groupIndex, }) {
21
+ const [address] = await this.withKeyring({ id: entropySource }, async ({ keyring }) => {
22
+ const accounts = await keyring.getAccounts();
23
+ if (groupIndex < accounts.length) {
24
+ // Nothing new to create, we just re-use the existing accounts here,
25
+ return [accounts[groupIndex]];
26
+ }
27
+ // For now, we don't allow for gap, so if we need to create a new
28
+ // account, this has to be the next one.
29
+ if (groupIndex !== accounts.length) {
30
+ throw new Error('Trying to create too many accounts');
31
+ }
32
+ // Create next account (and returns their addresses).
33
+ return await keyring.addAccounts(1);
34
+ });
35
+ const account = this.messenger.call('AccountsController:getAccountByAddress', address);
36
+ // We MUST have the associated internal account.
37
+ assertInternalAccountExists(account);
38
+ assertIsBip44Account(account);
39
+ return [account];
40
+ }
41
+ async discoverAndCreateAccounts(_) {
42
+ return []; // TODO: Implement account discovery.
43
+ }
9
44
  }
10
45
  //# sourceMappingURL=EvmAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n}\n"]}
1
+ {"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAO5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACpB,kCAA8B;AAE/B;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC,WAAW,CACtC,EAAE,EAAE,EAAE,aAAa,EAAE,EACrB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE;gBAChC,oEAAoE;gBACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;aAC/B;YAED,iEAAiE;YACjE,wCAAwC;YACxC,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;aACvD;YAED,qDAAqD;YACrD,OAAO,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,CACF,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACjC,wCAAwC,EACxC,OAAO,CACR,CAAC;QAEF,gDAAgD;QAChD,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACrC,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;CACF","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n EthKeyring,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\n/**\n * Asserts an internal account exists.\n *\n * @param account - The internal account to check.\n * @throws An error if the internal account does not exist.\n */\nfunction assertInternalAccountExists(\n account: InternalAccount | undefined,\n): asserts account is InternalAccount {\n if (!account) {\n throw new Error('Internal account does not exist');\n }\n}\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n const [address] = await this.withKeyring<EthKeyring, Hex[]>(\n { id: entropySource },\n async ({ keyring }) => {\n const accounts = await keyring.getAccounts();\n if (groupIndex < accounts.length) {\n // Nothing new to create, we just re-use the existing accounts here,\n return [accounts[groupIndex]];\n }\n\n // For now, we don't allow for gap, so if we need to create a new\n // account, this has to be the next one.\n if (groupIndex !== accounts.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n // Create next account (and returns their addresses).\n return await keyring.addAccounts(1);\n },\n );\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n\n // We MUST have the associated internal account.\n assertInternalAccountExists(account);\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"]}
@@ -1,15 +1,54 @@
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;
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.SolAccountProvider = void 0;
4
10
  const keyring_api_1 = require("@metamask/keyring-api");
5
11
  const keyring_controller_1 = require("@metamask/keyring-controller");
6
12
  const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
7
13
  class SolAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
14
+ constructor() {
15
+ super(...arguments);
16
+ _SolAccountProvider_instances.add(this);
17
+ }
8
18
  isAccountCompatible(account) {
9
19
  return (account.type === keyring_api_1.SolAccountType.DataAccount &&
10
20
  account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
11
21
  }
22
+ async createAccounts({ entropySource, groupIndex, }) {
23
+ // TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
24
+ // type once ready.
25
+ const account = await __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_createAccount).call(this, {
26
+ entropySource,
27
+ derivationPath: `m/44'/501'/${groupIndex}'/0'`,
28
+ });
29
+ return [account];
30
+ }
31
+ async discoverAndCreateAccounts(_) {
32
+ return []; // TODO: Implement account discovery.
33
+ }
12
34
  }
13
35
  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
+ };
14
53
  SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
15
54
  //# sourceMappingURL=SolAccountProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,qEAA4D;AAI5D,mEAA4D;AAE5D,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;;AARH,gDASC;AARQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { SolAccountType } 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 { BaseAccountProvider } 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"]}
1
+ {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAGA,uDAAuD;AACvD,qEAA4D;AAI5D,mEAG+B;AAE/B,MAAa,kBAAmB,SAAQ,yCAAmB;IAA3D;;;IAkEA,CAAC;IA/DC,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;IAmCD,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,wEAAe,MAAnB,IAAI,EAAgB;YACxC,aAAa;YACb,cAAc,EAAE,cAAc,UAAU,MAAM;SAC/C,CAAC,CAAC;QAEH,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AAjEH,gDAkEC;4GAxDC,KAAK,4CAAgB,IAGpB;IACC,iFAAiF;IACjF,gFAAgF;IAChF,sCAAsC;IACtC,+EAA+E;IAC/E,iFAAiF;IACjF,wDAAwD;IACxD,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;IAEF,4DAA4D;IAC5D,MAAM,OAAO,GAAG,MAAM,aAAa,CACjC,EAAkB,CAAC,cAAc,EACjC,IAAI,EACJ;QACE,4BAA4B,EAAE,KAAK;QACnC,mBAAmB,EAAE,KAAK;QAC1B,kBAAkB,EAAE,KAAK;KAC1B,CACF,CAAC;IAEF,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;IAE9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAxCM,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { SolAccountType } 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 #createAccount(opts: {\n entropySource: EntropySourceId;\n derivationPath: `m/${string}`;\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 const account = await createAccount(\n SolAccountProvider.SOLANA_SNAP_ID,\n opts,\n {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n },\n );\n\n assertIsBip44Account(account);\n\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const account = await this.#createAccount({\n entropySource,\n derivationPath: `m/44'/501'/${groupIndex}'/0'`,\n });\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"]}
@@ -1,9 +1,36 @@
1
- import type { Bip44Account } from "@metamask/account-api";
1
+ import { type Bip44Account } from "@metamask/account-api";
2
+ import type { EntropySourceId } from "@metamask/keyring-api";
2
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
3
4
  import type { SnapId } from "@metamask/snaps-sdk";
4
5
  import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
5
6
  export declare class SolAccountProvider extends BaseAccountProvider {
7
+ #private;
6
8
  static SOLANA_SNAP_ID: SnapId;
7
9
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
10
+ createAccounts({ entropySource, groupIndex, }: {
11
+ entropySource: EntropySourceId;
12
+ groupIndex: number;
13
+ }): Promise<Bip44Account<{
14
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
15
+ id: string;
16
+ options: Record<string, import("@metamask/snaps-sdk").Json> & {
17
+ entropy?: {
18
+ type: "mnemonic";
19
+ id: string;
20
+ derivationPath: string;
21
+ groupIndex: number;
22
+ } | {
23
+ type: "private-key";
24
+ } | undefined;
25
+ exportable?: boolean | undefined;
26
+ };
27
+ address: string;
28
+ scopes: `${string}:${string}`[];
29
+ methods: string[];
30
+ }>[]>;
31
+ discoverAndCreateAccounts(_: {
32
+ entropySource: EntropySourceId;
33
+ groupIndex: number;
34
+ }): Promise<never[]>;
8
35
  }
9
36
  //# sourceMappingURL=SolAccountProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;IAErE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
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;AAG7D,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;IAwC9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;IAWK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
@@ -1,9 +1,36 @@
1
- import type { Bip44Account } from "@metamask/account-api";
1
+ import { type Bip44Account } from "@metamask/account-api";
2
+ import type { EntropySourceId } from "@metamask/keyring-api";
2
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
3
4
  import type { SnapId } from "@metamask/snaps-sdk";
4
5
  import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
5
6
  export declare class SolAccountProvider extends BaseAccountProvider {
7
+ #private;
6
8
  static SOLANA_SNAP_ID: SnapId;
7
9
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
10
+ createAccounts({ entropySource, groupIndex, }: {
11
+ entropySource: EntropySourceId;
12
+ groupIndex: number;
13
+ }): Promise<Bip44Account<{
14
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
15
+ id: string;
16
+ options: Record<string, import("@metamask/snaps-sdk").Json> & {
17
+ entropy?: {
18
+ type: "mnemonic";
19
+ id: string;
20
+ derivationPath: string;
21
+ groupIndex: number;
22
+ } | {
23
+ type: "private-key";
24
+ } | undefined;
25
+ exportable?: boolean | undefined;
26
+ };
27
+ address: string;
28
+ scopes: `${string}:${string}`[];
29
+ methods: string[];
30
+ }>[]>;
31
+ discoverAndCreateAccounts(_: {
32
+ entropySource: EntropySourceId;
33
+ groupIndex: number;
34
+ }): Promise<never[]>;
8
35
  }
9
36
  //# sourceMappingURL=SolAccountProvider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;IAErE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
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;AAG7D,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;IAwC9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;IAWK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
@@ -1,11 +1,50 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
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;
1
7
  import { SolAccountType } from "@metamask/keyring-api";
2
8
  import { KeyringTypes } from "@metamask/keyring-controller";
3
- import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
9
+ import { assertIsBip44Account, BaseAccountProvider } from "./BaseAccountProvider.mjs";
4
10
  export class SolAccountProvider extends BaseAccountProvider {
11
+ constructor() {
12
+ super(...arguments);
13
+ _SolAccountProvider_instances.add(this);
14
+ }
5
15
  isAccountCompatible(account) {
6
16
  return (account.type === SolAccountType.DataAccount &&
7
17
  account.metadata.keyring.type === KeyringTypes.snap);
8
18
  }
19
+ async createAccounts({ entropySource, groupIndex, }) {
20
+ // TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
21
+ // type once ready.
22
+ const account = await __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_createAccount).call(this, {
23
+ entropySource,
24
+ derivationPath: `m/44'/501'/${groupIndex}'/0'`,
25
+ });
26
+ return [account];
27
+ }
28
+ async discoverAndCreateAccounts(_) {
29
+ return []; // TODO: Implement account discovery.
30
+ }
9
31
  }
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
+ };
10
49
  SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
11
50
  //# sourceMappingURL=SolAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,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;;AAPM,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { SolAccountType } 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 { BaseAccountProvider } 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"]}
1
+ {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;AAGA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACpB,kCAA8B;AAE/B,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAA3D;;;IAkEA,CAAC;IA/DC,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;IAmCD,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,wEAAe,MAAnB,IAAI,EAAgB;YACxC,aAAa;YACb,cAAc,EAAE,cAAc,UAAU,MAAM;SAC/C,CAAC,CAAC;QAEH,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;4GAvDD,KAAK,4CAAgB,IAGpB;IACC,iFAAiF;IACjF,gFAAgF;IAChF,sCAAsC;IACtC,+EAA+E;IAC/E,iFAAiF;IACjF,wDAAwD;IACxD,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;IAEF,4DAA4D;IAC5D,MAAM,OAAO,GAAG,MAAM,aAAa,CACjC,EAAkB,CAAC,cAAc,EACjC,IAAI,EACJ;QACE,4BAA4B,EAAE,KAAK;QACnC,mBAAmB,EAAE,KAAK;QAC1B,kBAAkB,EAAE,KAAK;KAC1B,CACF,CAAC;IAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAE9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAxCM,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { SolAccountType } 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 #createAccount(opts: {\n entropySource: EntropySourceId;\n derivationPath: `m/${string}`;\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 const account = await createAccount(\n SolAccountProvider.SOLANA_SNAP_ID,\n opts,\n {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n },\n );\n\n assertIsBip44Account(account);\n\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const account = await this.#createAccount({\n entropySource,\n derivationPath: `m/44'/501'/${groupIndex}'/0'`,\n });\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"]}
@@ -12,10 +12,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  };
13
13
  var _MockAccountBuilder_account;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MockAccountBuilder = exports.MOCK_HARDWARE_ACCOUNT_1 = exports.MOCK_SNAP_ACCOUNT_2 = exports.MOCK_SNAP_ACCOUNT_1 = exports.MOCK_HD_ACCOUNT_2 = exports.MOCK_HD_ACCOUNT_1 = exports.MOCK_HD_KEYRING_2 = exports.MOCK_HD_KEYRING_1 = exports.MOCK_ENTROPY_SOURCE_2 = exports.MOCK_ENTROPY_SOURCE_1 = exports.MOCK_SNAP_2 = exports.MOCK_SNAP_1 = void 0;
15
+ exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = exports.MOCK_WALLET_1_SOL_ACCOUNT = exports.MOCK_WALLET_1_EVM_ACCOUNT = exports.MOCK_WALLET_1_ENTROPY_SOURCE = exports.MockAccountBuilder = exports.MOCK_HARDWARE_ACCOUNT_1 = exports.MOCK_SNAP_ACCOUNT_4 = exports.MOCK_SNAP_ACCOUNT_3 = exports.MOCK_SNAP_ACCOUNT_2 = exports.MOCK_SNAP_ACCOUNT_1 = exports.MOCK_BTC_P2TR_ACCOUNT_1 = exports.MOCK_BTC_P2WPKH_ACCOUNT_1 = exports.MOCK_SOL_ACCOUNT_1 = exports.MOCK_HD_ACCOUNT_2 = exports.MOCK_HD_ACCOUNT_1 = exports.MOCK_HD_KEYRING_2 = exports.MOCK_HD_KEYRING_1 = exports.MOCK_ENTROPY_SOURCE_2 = exports.MOCK_ENTROPY_SOURCE_1 = exports.MOCK_SNAP_2 = exports.MOCK_SNAP_1 = void 0;
16
16
  const account_api_1 = require("@metamask/account-api");
17
17
  const keyring_api_1 = require("@metamask/keyring-api");
18
18
  const keyring_controller_1 = require("@metamask/keyring-controller");
19
+ const uuid_1 = require("uuid");
19
20
  const ETH_EOA_METHODS = [
20
21
  keyring_api_1.EthMethod.PersonalSign,
21
22
  keyring_api_1.EthMethod.Sign,
@@ -97,7 +98,7 @@ exports.MOCK_HD_ACCOUNT_2 = {
97
98
  nameLastUpdatedAt: 0,
98
99
  },
99
100
  };
100
- exports.MOCK_SNAP_ACCOUNT_1 = {
101
+ exports.MOCK_SOL_ACCOUNT_1 = {
101
102
  id: 'mock-snap-id-1',
102
103
  address: 'aabbccdd',
103
104
  options: {
@@ -111,15 +112,72 @@ exports.MOCK_SNAP_ACCOUNT_1 = {
111
112
  },
112
113
  methods: SOL_METHODS,
113
114
  type: keyring_api_1.SolAccountType.DataAccount,
114
- scopes: [keyring_api_1.SolScope.Mainnet],
115
+ scopes: [keyring_api_1.SolScope.Mainnet, keyring_api_1.SolScope.Testnet, keyring_api_1.SolScope.Devnet],
115
116
  metadata: {
116
- name: 'Snap Account 1',
117
+ name: 'Solana Account 1',
117
118
  keyring: { type: keyring_controller_1.KeyringTypes.snap },
118
119
  snap: exports.MOCK_SNAP_1,
119
120
  importTime: 0,
120
121
  lastSelected: 0,
121
122
  },
122
123
  };
124
+ exports.MOCK_BTC_P2WPKH_ACCOUNT_1 = {
125
+ id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',
126
+ type: keyring_api_1.BtcAccountType.P2wpkh,
127
+ methods: [keyring_api_1.BtcMethod.SendBitcoin],
128
+ address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',
129
+ options: {
130
+ entropy: {
131
+ type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
132
+ // NOTE: shares entropy with MOCK_HD_ACCOUNT_2
133
+ id: exports.MOCK_HD_KEYRING_2.metadata.id,
134
+ groupIndex: 0,
135
+ derivationPath: '',
136
+ },
137
+ },
138
+ scopes: [keyring_api_1.BtcScope.Mainnet],
139
+ metadata: {
140
+ name: 'Bitcoin Native Segwit Account 1',
141
+ importTime: 0,
142
+ keyring: {
143
+ type: 'Snap keyring',
144
+ },
145
+ snap: {
146
+ id: 'mock-btc-snap-id',
147
+ enabled: true,
148
+ name: 'Mock Bitcoin Snap',
149
+ },
150
+ },
151
+ };
152
+ exports.MOCK_BTC_P2TR_ACCOUNT_1 = {
153
+ id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',
154
+ type: keyring_api_1.BtcAccountType.P2tr,
155
+ methods: [keyring_api_1.BtcMethod.SendBitcoin],
156
+ address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',
157
+ options: {
158
+ entropy: {
159
+ type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
160
+ // NOTE: shares entropy with MOCK_HD_ACCOUNT_2
161
+ id: exports.MOCK_HD_KEYRING_2.metadata.id,
162
+ groupIndex: 0,
163
+ derivationPath: '',
164
+ },
165
+ },
166
+ scopes: [keyring_api_1.BtcScope.Testnet],
167
+ metadata: {
168
+ name: 'Bitcoin Taproot Account 1',
169
+ importTime: 0,
170
+ keyring: {
171
+ type: 'Snap keyring',
172
+ },
173
+ snap: {
174
+ id: 'mock-btc-snap-id',
175
+ enabled: true,
176
+ name: 'Mock Bitcoin Snap',
177
+ },
178
+ },
179
+ };
180
+ exports.MOCK_SNAP_ACCOUNT_1 = exports.MOCK_SOL_ACCOUNT_1;
123
181
  exports.MOCK_SNAP_ACCOUNT_2 = {
124
182
  id: 'mock-snap-id-2',
125
183
  address: '0x789',
@@ -135,6 +193,8 @@ exports.MOCK_SNAP_ACCOUNT_2 = {
135
193
  lastSelected: 0,
136
194
  },
137
195
  };
196
+ exports.MOCK_SNAP_ACCOUNT_3 = exports.MOCK_BTC_P2WPKH_ACCOUNT_1;
197
+ exports.MOCK_SNAP_ACCOUNT_4 = exports.MOCK_BTC_P2TR_ACCOUNT_1;
138
198
  exports.MOCK_HARDWARE_ACCOUNT_1 = {
139
199
  id: 'mock-hardware-id-1',
140
200
  address: '0xABC',
@@ -162,6 +222,14 @@ class MockAccountBuilder {
162
222
  __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = id;
163
223
  return this;
164
224
  }
225
+ withUuid() {
226
+ __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = (0, uuid_1.v4)();
227
+ return this;
228
+ }
229
+ withAddressSuffix(suffix) {
230
+ __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address += suffix;
231
+ return this;
232
+ }
165
233
  withEntropySource(entropySource) {
166
234
  if ((0, account_api_1.isBip44Account)(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
167
235
  __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.id = entropySource;
@@ -180,4 +248,21 @@ class MockAccountBuilder {
180
248
  }
181
249
  exports.MockAccountBuilder = MockAccountBuilder;
182
250
  _MockAccountBuilder_account = new WeakMap();
251
+ exports.MOCK_WALLET_1_ENTROPY_SOURCE = exports.MOCK_ENTROPY_SOURCE_1;
252
+ exports.MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(exports.MOCK_HD_ACCOUNT_1)
253
+ .withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
254
+ .withGroupIndex(0)
255
+ .get();
256
+ exports.MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(exports.MOCK_SOL_ACCOUNT_1)
257
+ .withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
258
+ .withGroupIndex(0)
259
+ .get();
260
+ exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(exports.MOCK_BTC_P2WPKH_ACCOUNT_1)
261
+ .withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
262
+ .withGroupIndex(0)
263
+ .get();
264
+ exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(exports.MOCK_BTC_P2TR_ACCOUNT_1)
265
+ .withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
266
+ .withGroupIndex(0)
267
+ .get();
183
268
  //# sourceMappingURL=accounts.cjs.map