@metamask-previews/multichain-account-service 0.3.0-preview-0910ff0 → 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/CHANGELOG.md +15 -0
- package/dist/MultichainAccountGroup.cjs +192 -0
- package/dist/MultichainAccountGroup.cjs.map +1 -0
- package/dist/MultichainAccountGroup.d.cts +84 -0
- package/dist/MultichainAccountGroup.d.cts.map +1 -0
- package/dist/MultichainAccountGroup.d.mts +84 -0
- package/dist/MultichainAccountGroup.d.mts.map +1 -0
- package/dist/MultichainAccountGroup.mjs +188 -0
- package/dist/MultichainAccountGroup.mjs.map +1 -0
- package/dist/MultichainAccountService.cjs +36 -23
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +26 -15
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +26 -15
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +35 -22
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +237 -0
- package/dist/MultichainAccountWallet.cjs.map +1 -0
- package/dist/MultichainAccountWallet.d.cts +91 -0
- package/dist/MultichainAccountWallet.d.cts.map +1 -0
- package/dist/MultichainAccountWallet.d.mts +91 -0
- package/dist/MultichainAccountWallet.d.mts.map +1 -0
- package/dist/MultichainAccountWallet.mjs +233 -0
- package/dist/MultichainAccountWallet.mjs.map +1 -0
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/providers/BaseAccountProvider.cjs +20 -1
- package/dist/providers/BaseAccountProvider.cjs.map +1 -1
- package/dist/providers/BaseAccountProvider.d.cts +25 -5
- package/dist/providers/BaseAccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseAccountProvider.d.mts +25 -5
- package/dist/providers/BaseAccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseAccountProvider.mjs +18 -0
- package/dist/providers/BaseAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +35 -0
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +66 -0
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +66 -0
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +36 -1
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +35 -0
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +27 -1
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +27 -1
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +37 -2
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/tests/accounts.cjs +89 -4
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +235 -36
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +235 -36
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +89 -4
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/index.cjs +1 -0
- package/dist/tests/index.cjs.map +1 -1
- package/dist/tests/index.d.cts +1 -0
- package/dist/tests/index.d.cts.map +1 -1
- package/dist/tests/index.d.mts +1 -0
- package/dist/tests/index.d.mts.map +1 -1
- package/dist/tests/index.mjs +1 -0
- package/dist/tests/index.mjs.map +1 -1
- package/dist/tests/providers.cjs +28 -0
- package/dist/tests/providers.cjs.map +1 -0
- package/dist/tests/providers.d.cts +16 -0
- package/dist/tests/providers.d.cts.map +1 -0
- package/dist/tests/providers.d.mts +16 -0
- package/dist/tests/providers.d.mts.map +1 -0
- package/dist/tests/providers.mjs +23 -0
- package/dist/tests/providers.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +11 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +11 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- 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;
|
|
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;
|
|
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":"
|
|
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"]}
|
|
@@ -9,6 +9,41 @@ class SolAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
|
|
|
9
9
|
return (account.type === keyring_api_1.SolAccountType.DataAccount &&
|
|
10
10
|
account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
|
|
11
11
|
}
|
|
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.
|
|
21
|
+
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
22
|
+
// type once ready.
|
|
23
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
24
|
+
const account = await createAccount(SolAccountProvider.SOLANA_SNAP_ID, {
|
|
25
|
+
entropySource,
|
|
26
|
+
derivationPath,
|
|
27
|
+
}, {
|
|
28
|
+
displayAccountNameSuggestion: false,
|
|
29
|
+
displayConfirmation: false,
|
|
30
|
+
setSelectedAccount: false,
|
|
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);
|
|
42
|
+
return [account];
|
|
43
|
+
}
|
|
44
|
+
async discoverAndCreateAccounts(_) {
|
|
45
|
+
return []; // TODO: Implement account discovery.
|
|
46
|
+
}
|
|
12
47
|
}
|
|
13
48
|
exports.SolAccountProvider = SolAccountProvider;
|
|
14
49
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
@@ -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"]}
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
import type
|
|
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 {
|
|
6
7
|
static SOLANA_SNAP_ID: SnapId;
|
|
7
8
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
9
|
+
createAccounts({ entropySource, groupIndex, }: {
|
|
10
|
+
entropySource: EntropySourceId;
|
|
11
|
+
groupIndex: number;
|
|
12
|
+
}): Promise<Bip44Account<{
|
|
13
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
|
|
14
|
+
id: string;
|
|
15
|
+
options: Record<string, import("@metamask/snaps-sdk").Json> & {
|
|
16
|
+
entropy?: {
|
|
17
|
+
type: "mnemonic";
|
|
18
|
+
id: string;
|
|
19
|
+
derivationPath: string;
|
|
20
|
+
groupIndex: number;
|
|
21
|
+
} | {
|
|
22
|
+
type: "private-key";
|
|
23
|
+
} | undefined;
|
|
24
|
+
exportable?: boolean | undefined;
|
|
25
|
+
};
|
|
26
|
+
address: string;
|
|
27
|
+
scopes: `${string}:${string}`[];
|
|
28
|
+
methods: string[];
|
|
29
|
+
}>[]>;
|
|
30
|
+
discoverAndCreateAccounts(_: {
|
|
31
|
+
entropySource: EntropySourceId;
|
|
32
|
+
groupIndex: number;
|
|
33
|
+
}): Promise<never[]>;
|
|
8
34
|
}
|
|
9
35
|
//# 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,
|
|
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"}
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
import type
|
|
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 {
|
|
6
7
|
static SOLANA_SNAP_ID: SnapId;
|
|
7
8
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
9
|
+
createAccounts({ entropySource, groupIndex, }: {
|
|
10
|
+
entropySource: EntropySourceId;
|
|
11
|
+
groupIndex: number;
|
|
12
|
+
}): Promise<Bip44Account<{
|
|
13
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
|
|
14
|
+
id: string;
|
|
15
|
+
options: Record<string, import("@metamask/snaps-sdk").Json> & {
|
|
16
|
+
entropy?: {
|
|
17
|
+
type: "mnemonic";
|
|
18
|
+
id: string;
|
|
19
|
+
derivationPath: string;
|
|
20
|
+
groupIndex: number;
|
|
21
|
+
} | {
|
|
22
|
+
type: "private-key";
|
|
23
|
+
} | undefined;
|
|
24
|
+
exportable?: boolean | undefined;
|
|
25
|
+
};
|
|
26
|
+
address: string;
|
|
27
|
+
scopes: `${string}:${string}`[];
|
|
28
|
+
methods: string[];
|
|
29
|
+
}>[]>;
|
|
30
|
+
discoverAndCreateAccounts(_: {
|
|
31
|
+
entropySource: EntropySourceId;
|
|
32
|
+
groupIndex: number;
|
|
33
|
+
}): Promise<never[]>;
|
|
8
34
|
}
|
|
9
35
|
//# 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,
|
|
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,11 +1,46 @@
|
|
|
1
|
-
import { SolAccountType } from "@metamask/keyring-api";
|
|
1
|
+
import { KeyringAccountEntropyTypeOption, SolAccountType } 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
4
|
export class SolAccountProvider extends BaseAccountProvider {
|
|
5
5
|
isAccountCompatible(account) {
|
|
6
6
|
return (account.type === SolAccountType.DataAccount &&
|
|
7
7
|
account.metadata.keyring.type === KeyringTypes.snap);
|
|
8
8
|
}
|
|
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.
|
|
18
|
+
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
19
|
+
// type once ready.
|
|
20
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
21
|
+
const account = await createAccount(SolAccountProvider.SOLANA_SNAP_ID, {
|
|
22
|
+
entropySource,
|
|
23
|
+
derivationPath,
|
|
24
|
+
}, {
|
|
25
|
+
displayAccountNameSuggestion: false,
|
|
26
|
+
displayConfirmation: false,
|
|
27
|
+
setSelectedAccount: false,
|
|
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);
|
|
39
|
+
return [account];
|
|
40
|
+
}
|
|
41
|
+
async discoverAndCreateAccounts(_) {
|
|
42
|
+
return []; // TODO: Implement account discovery.
|
|
43
|
+
}
|
|
9
44
|
}
|
|
10
45
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
11
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"]}
|
package/dist/tests/accounts.cjs
CHANGED
|
@@ -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.
|
|
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: '
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAuD;AAEvD,uDAQ+B;AAC/B,qEAA4D;AAG5D,MAAM,eAAe,GAAG;IACtB,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MA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yB;QAC9B,uBAAA,IAAI,mCAAS,CAAC,EAAE,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,aAA8B;QAC9C,IAAI,IAAA,4BAAc,EAAC,uBAAA,IAAI,mCAAS,CAAC,EAAE;YACjC,uBAAA,IAAI,mCAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,aAAa,CAAC;SAClD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc,CAAC,UAAkB;QAC/B,IAAI,IAAA,4BAAc,EAAC,uBAAA,IAAI,mCAAS,CAAC,EAAE;YACjC,uBAAA,IAAI,mCAAS,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;SACvD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG;QACD,OAAO,uBAAA,IAAI,mCAAS,CAAC;IACvB,CAAC;CACF;AAlCD,gDAkCC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nconst ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: InternalAccount = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: InternalAccount = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1: InternalAccount = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet],\n metadata: {\n name: 'Snap Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport class MockAccountBuilder {\n readonly #account: InternalAccount;\n\n constructor(account: InternalAccount) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from(account: InternalAccount): MockAccountBuilder {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAAuD;AAEvD,uDAW+B;AAC/B,qEAA4D;AAE5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C;IAED,GAAG;QACD,OAAO,uBAAA,IAAI,mCAAS,CAAC;IACvB,CAAC;CACF;AA9CD,gDA8CC;;AAEY,QAAA,4BAA4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { v4 as uuid } from 'uuid';\n\nconst ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: [BtcMethod.SendBitcoin],\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: [BtcMethod.SendBitcoin],\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n"]}
|