@talismn/keyring 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,26 +1,26 @@
1
1
  import { KeypairCurve } from "@talismn/crypto";
2
2
  //#region src/types/account.d.ts
3
- type LedgerPolkadotCurve = "ed25519" | "ethereum";
4
- type AccountBase = {
3
+ export type LedgerPolkadotCurve = "ed25519" | "ethereum";
4
+ export type AccountBase = {
5
5
  address: string;
6
6
  name: string;
7
7
  createdAt: number;
8
8
  };
9
- type AccountKeypair = AccountBase & {
9
+ export type AccountKeypair = AccountBase & {
10
10
  type: "keypair";
11
11
  curve: KeypairCurve;
12
12
  mnemonicId?: string;
13
13
  derivationPath?: string;
14
14
  };
15
- type AccountContact = AccountBase & {
15
+ export type AccountContact = AccountBase & {
16
16
  type: "contact";
17
17
  genesisHash?: `0x${string}`;
18
18
  };
19
- type AccountWatchOnly = AccountBase & {
19
+ export type AccountWatchOnly = AccountBase & {
20
20
  type: "watch-only";
21
21
  isPortfolio: boolean;
22
22
  };
23
- type AccountLedgerPolkadot = AccountBase & {
23
+ export type AccountLedgerPolkadot = AccountBase & {
24
24
  type: "ledger-polkadot";
25
25
  curve: LedgerPolkadotCurve;
26
26
  app: string;
@@ -28,33 +28,33 @@ type AccountLedgerPolkadot = AccountBase & {
28
28
  addressOffset: number;
29
29
  genesisHash?: `0x${string}`;
30
30
  };
31
- type AccountLedgerEthereum = AccountBase & {
31
+ export type AccountLedgerEthereum = AccountBase & {
32
32
  type: "ledger-ethereum";
33
33
  derivationPath: string;
34
34
  };
35
- type AccountLedgerSolana = AccountBase & {
35
+ export type AccountLedgerSolana = AccountBase & {
36
36
  type: "ledger-solana";
37
37
  derivationPath: string;
38
38
  };
39
- type AccountPolkadotVault = AccountBase & {
39
+ export type AccountPolkadotVault = AccountBase & {
40
40
  type: "polkadot-vault";
41
41
  genesisHash: `0x${string}` | null;
42
42
  };
43
- type AccountSignet = AccountBase & {
43
+ export type AccountSignet = AccountBase & {
44
44
  type: "signet";
45
45
  genesisHash: `0x${string}`;
46
46
  url: string;
47
47
  };
48
- type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
49
- type AccountType = Account["type"];
48
+ export type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
49
+ export type AccountType = Account["type"];
50
50
  //#endregion
51
51
  //#region src/types/keyring.d.ts
52
- type AddMnemonicOptions = {
52
+ export type AddMnemonicOptions = {
53
53
  mnemonic: string;
54
54
  name: string;
55
55
  confirmed: boolean;
56
56
  };
57
- type UpdateMnemonicOptions = {
57
+ export type UpdateMnemonicOptions = {
58
58
  name?: string;
59
59
  confirmed?: boolean;
60
60
  };
@@ -73,20 +73,20 @@ type DeriveFromExistingMnemonic = {
73
73
  derivationPath: string;
74
74
  };
75
75
  type DeriveFromMnemonicOptions = DeriveFromNewMnemonic | DeriveFromExistingMnemonic;
76
- type AddAccountDeriveOptions = Omit<AccountBase, "createdAt" | "address"> & DeriveFromMnemonicOptions;
77
- type AddAccountKeypairOptions = Omit<AccountBase, "createdAt" | "address"> & {
76
+ export type AddAccountDeriveOptions = Omit<AccountBase, "createdAt" | "address"> & DeriveFromMnemonicOptions;
77
+ export type AddAccountKeypairOptions = Omit<AccountBase, "createdAt" | "address"> & {
78
78
  curve: KeypairCurve;
79
79
  secretKey: Uint8Array;
80
80
  };
81
- type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountLedgerSolana, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
82
- type UpdateAccountOptions = {
81
+ export type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountLedgerSolana, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
82
+ export type UpdateAccountOptions = {
83
83
  name?: string;
84
84
  isPortfolio?: boolean;
85
85
  genesisHash?: `0x${string}`;
86
86
  };
87
87
  //#endregion
88
88
  //#region src/types/mnemonic.d.ts
89
- type Mnemonic = {
89
+ export type Mnemonic = {
90
90
  id: string;
91
91
  name: string;
92
92
  confirmed: boolean;
@@ -94,11 +94,11 @@ type Mnemonic = {
94
94
  };
95
95
  //#endregion
96
96
  //#region src/types/utils.d.ts
97
- type AccountOfType<Type extends AccountType> = Extract<Account, {
97
+ export type AccountOfType<Type extends AccountType> = Extract<Account, {
98
98
  type: Type;
99
99
  }>;
100
- declare const isAccountOfType: <Type extends AccountType>(account: Account | null | undefined, type: Type) => account is AccountOfType<Type>;
101
- declare const isAccountInTypes: <Types extends AccountType[]>(account: Account | null | undefined, types: Types) => account is AccountOfType<Types[number]>;
100
+ export declare const isAccountOfType: <Type extends AccountType>(account: Account | null | undefined, type: Type) => account is AccountOfType<Type>;
101
+ export declare const isAccountInTypes: <Types extends AccountType[]>(account: Account | null | undefined, types: Types) => account is AccountOfType<Types[number]>;
102
102
  declare const ACCOUNT_TYPES_OWNED: readonly ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
103
103
  declare const ACCOUNT_TYPES_EXTERNAL: readonly ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
104
104
  declare const ACCOUNT_TYPES_ADDRESS_ETHEREUM: readonly ["contact", "watch-only", "keypair", "ledger-ethereum", "ledger-polkadot"];
@@ -107,50 +107,50 @@ declare const ACCOUNT_TYPES_PLATFORM_POLKADOT: readonly ["contact", "watch-only"
107
107
  declare const ACCOUNT_TYPES_ADDRESS_SS58: readonly ["contact", "watch-only", "keypair", "ledger-polkadot", "polkadot-vault", "signet"];
108
108
  declare const ACCOUNT_TYPES_PLATFORM_SOLANA: readonly ["contact", "watch-only", "keypair", "ledger-solana"];
109
109
  declare const ACCOUNT_TYPES_BITCOIN: readonly ["contact", "watch-only"];
110
- declare const isAccountExternal: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]>;
111
- declare const isAccountOwned: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]>;
112
- declare const isAccountPortfolio: (account: Account | null | undefined) => account is Account;
113
- declare const isAccountNotContact: (acc: Account) => acc is AccountKeypair | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet | AccountWatchOnly;
110
+ export declare const isAccountExternal: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]>;
111
+ export declare const isAccountOwned: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]>;
112
+ export declare const isAccountPortfolio: (account: Account | null | undefined) => account is Account;
113
+ export declare const isAccountNotContact: (acc: Account) => acc is AccountKeypair | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet | AccountWatchOnly;
114
114
  type AccountAddressEthereum = Extract<Account, {
115
115
  type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number];
116
116
  }> & {
117
117
  address: `0x${string}`;
118
118
  };
119
- declare const isAccountAddressEthereum: (account: Account | null | undefined) => account is AccountAddressEthereum;
119
+ export declare const isAccountAddressEthereum: (account: Account | null | undefined) => account is AccountAddressEthereum;
120
120
  type AccountPlatformEthereum = Extract<Account, {
121
121
  type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number];
122
122
  }> & {
123
123
  address: `0x${string}`;
124
124
  };
125
- declare const isAccountPlatformEthereum: (account: Account | null | undefined) => account is AccountPlatformEthereum;
125
+ export declare const isAccountPlatformEthereum: (account: Account | null | undefined) => account is AccountPlatformEthereum;
126
126
  type AccountPlatformSolana = Extract<Account, {
127
127
  type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number];
128
128
  }>;
129
- declare const isAccountPlatformSolana: (account: Account | null | undefined) => account is AccountPlatformSolana;
129
+ export declare const isAccountPlatformSolana: (account: Account | null | undefined) => account is AccountPlatformSolana;
130
130
  type AccountPlatformPolkadot = Extract<Account, {
131
131
  type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number];
132
132
  }>;
133
- declare const isAccountPlatformPolkadot: (account: Account | null | undefined) => account is AccountPlatformPolkadot;
133
+ export declare const isAccountPlatformPolkadot: (account: Account | null | undefined) => account is AccountPlatformPolkadot;
134
134
  type AccountAddressSs58 = Extract<Account, {
135
135
  type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number];
136
136
  }> & {
137
137
  genesisHash?: `0x${string}`;
138
138
  };
139
- declare const isAccountAddressSs58: (account: Account | null | undefined) => account is AccountAddressSs58;
140
- declare const isAccountLedgerPolkadot: (account: Account | null | undefined) => account is AccountLedgerPolkadot;
141
- declare const isAccountLedgerPolkadotGeneric: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
139
+ export declare const isAccountAddressSs58: (account: Account | null | undefined) => account is AccountAddressSs58;
140
+ export declare const isAccountLedgerPolkadot: (account: Account | null | undefined) => account is AccountLedgerPolkadot;
141
+ export declare const isAccountLedgerPolkadotGeneric: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
142
142
  genesisHash: undefined;
143
143
  };
144
- declare const isAccountLedgerPolkadotLegacy: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
144
+ export declare const isAccountLedgerPolkadotLegacy: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
145
145
  genesisHash: `0x${string}`;
146
146
  };
147
147
  type AccountBitcoin = Extract<Account, {
148
148
  type: (typeof ACCOUNT_TYPES_BITCOIN)[number];
149
149
  }>;
150
- declare const isAccountBitcoin: (account: Account | null | undefined) => account is AccountBitcoin;
151
- declare const getAccountGenesisHash: (account: Account | null | undefined) => `0x${string}` | undefined;
152
- declare const getAccountSignetUrl: (account: Account | null | undefined) => string | undefined;
153
- declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").AccountPlatform | undefined;
150
+ export declare const isAccountBitcoin: (account: Account | null | undefined) => account is AccountBitcoin;
151
+ export declare const getAccountGenesisHash: (account: Account | null | undefined) => `0x${string}` | undefined;
152
+ export declare const getAccountSignetUrl: (account: Account | null | undefined) => string | undefined;
153
+ export declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").AccountPlatform | undefined;
154
154
  //#endregion
155
155
  //#region src/keyring/types.d.ts
156
156
  type MnemonicStorage = Mnemonic & {
@@ -162,12 +162,12 @@ type AccountKeypairStorage = AccountKeypair & {
162
162
  type AccountStorage = AccountKeypairStorage | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
163
163
  //#endregion
164
164
  //#region src/keyring/Keyring.d.ts
165
- type KeyringStorage = {
165
+ export type KeyringStorage = {
166
166
  passwordCheck: string | null;
167
167
  mnemonics: MnemonicStorage[];
168
168
  accounts: AccountStorage[];
169
169
  };
170
- declare class Keyring {
170
+ export declare class Keyring {
171
171
  #private;
172
172
  protected constructor(data: KeyringStorage);
173
173
  static create(): Keyring;
@@ -216,5 +216,4 @@ declare class Keyring {
216
216
  getDerivedAddress(mnemonicId: string, derivationPath: string, curve: KeypairCurve, password: string): Promise<string>;
217
217
  }
218
218
  //#endregion
219
- export { Account, AccountBase, AccountContact, AccountKeypair, AccountLedgerEthereum, AccountLedgerPolkadot, AccountLedgerSolana, AccountOfType, AccountPolkadotVault, AccountSignet, AccountType, AccountWatchOnly, AddAccountDeriveOptions, AddAccountExternalOptions, AddAccountKeypairOptions, AddMnemonicOptions, Keyring, KeyringStorage, LedgerPolkadotCurve, Mnemonic, UpdateAccountOptions, UpdateMnemonicOptions, getAccountGenesisHash, getAccountPlatform, getAccountSignetUrl, isAccountAddressEthereum, isAccountAddressSs58, isAccountBitcoin, isAccountExternal, isAccountInTypes, isAccountLedgerPolkadot, isAccountLedgerPolkadotGeneric, isAccountLedgerPolkadotLegacy, isAccountNotContact, isAccountOfType, isAccountOwned, isAccountPlatformEthereum, isAccountPlatformPolkadot, isAccountPlatformSolana, isAccountPortfolio };
220
219
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/account.ts","../src/types/keyring.ts","../src/types/mnemonic.ts","../src/types/utils.ts","../src/keyring/types.ts","../src/keyring/Keyring.ts"],"mappings":";;KAEY;KAEA;EAIV;EACA;EACA;;KAGU,iBAAiB;EAC3B;EACA,OAAO;EACP;EACA;;KAGU,iBAAiB;EAC3B;EACA;;KAGU,mBAAmB;EAC7B;EACA;;KAGU,wBAAwB;EAClC;EACA,OAAO;EACP;EACA;EACA;EACA;;KAGU,wBAAwB;EAClC;EACA;;KAGU,sBAAsB;EAChC;EACA;;KAGU,uBAAuB;EACjC;EACA;;KAGU,gBAAgB;EAC1B;EACA;EACA;;KAsBU,UACR,iBACA,iBACA,mBACA,wBACA,wBACA,sBACA,uBACA;KAEQ,cAAc;;;KC5Ed;EACV;EACA;EACA;;KAGU;EACV;EACA;;KAGG;EACH;EACA;EACA;EACA;EACA,OAAO;EACP;;KAGG;EACH;EACA;EACA,OAAO;EACP;;KAGG,4BAA4B,wBAAwB;KAE7C,0BAA0B,KAAK,wCACzC;KAEU,2BAA2B,KAAK;EAC1C,OAAO;EACP,WAAW;;KAGD,4BACR,KAAK,+BACL,KAAK,iCACL,KAAK,sCACL,KAAK,sCACL,KAAK,oCACL,KAAK,qCACL,KAAK;KAEG;EACV;EACA;EACA;;;;KC9DU;EACV;EACA;EACA;EACA;;;;KCOU,cAA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EAsBP;;;;;;EASM,eAAe,mBAAmB;;;;;EAgBlC,mBAAmB,mBAAmB;EAO5C,UAAM;EAIA,OAAO,kBAAkB,uBAAuB,QAAQ;EAoB9D,gBAAgB;EAIV,cACT,MAAM,UAAU,aAAa,oBAC/B,mBACC,QAAQ;EA4BJ,YAAY,aAAa;EAKzB,eAAe,cAAc,MAAM,aAAa,wBAAqB;EAcrE,eAAe;EAMhB,gBAAgB,YAAY,mBAAmB;EAS9C,sBAAsB;EAMtB,eAAe;EAIf,WAAW,kBAAkB;EAK7B,cAAc,mBAAmB,MAAM,aAAa,eAAe,uBAAoB;EAuBvF,cAAc;EAMd,mBAAmB,SAAS,4BAA4B;;;;;;;;;;UA2BjD;EAiCD,iBACX,SAAS,yBACT,mBACC,QAAQ;EAgCE,oBACT,OAAO,MAAM,aAAa,0BAC5B,mBACC,QAAQ;EAuBJ,oBAAoB,iBAAiB,mBAAmB,QAAQ;EAW1D,kBACX,oBACA,wBACA,OAAO,cACP,mBACC"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/account.ts","../src/types/keyring.ts","../src/types/mnemonic.ts","../src/types/utils.ts","../src/keyring/types.ts","../src/keyring/Keyring.ts"],"mappings":";;YAEY;YAEA;EAIV;EACA;EACA;;YAGU,iBAAiB;EAC3B;EACA,OAAO;EACP;EACA;;YAGU,iBAAiB;EAC3B;EACA;;YAGU,mBAAmB;EAC7B;EACA;;YAGU,wBAAwB;EAClC;EACA,OAAO;EACP;EACA;EACA;EACA;;YAGU,wBAAwB;EAClC;EACA;;YAGU,sBAAsB;EAChC;EACA;;YAGU,uBAAuB;EACjC;EACA;;YAGU,gBAAgB;EAC1B;EACA;EACA;;YAsBU,UACR,iBACA,iBACA,mBACA,wBACA,wBACA,sBACA,uBACA;YAEQ,cAAc;;;YC5Ed;EACV;EACA;EACA;;YAGU;EACV;EACA;;KAGG;EACH;EACA;EACA;EACA;EACA,OAAO;EACP;;KAGG;EACH;EACA;EACA,OAAO;EACP;;K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SAAa;qBAKlC,sBAAmB,SAAa;qBAIhC,qBAAkB,SAAa,yDAA0B;;;KCrL1D,kBAAkB;EAC5B;;KAGU,wBAAwB;EAClC;;KAGU,iBACR,wBACA,iBACA,mBACA,wBACA,wBACA,sBACA,uBACA;;;YCCQ;EACV;EACA,WAAW;EACX,UAAU;;qBAGC;;YAGF,YAAa,MAAM;SAId,UAAU;SAQV,KAAK,MAAM,iBAAiB;UAY5B;;EAsBP;;;;;;EASM,eAAe,mBAAmB;;;;;EAgBlC,mBAAmB,mBAAmB;EAO5C,UAAM;EAIA,OAAO,kBAAkB,uBAAuB,QAAQ;EAoB9D,gBAAgB;EAIV,cACT,MAAM,UAAU,aAAa,oBAC/B,mBACC,QAAQ;EA4BJ,YAAY,aAAa;EAKzB,eAAe,cAAc,MAAM,aAAa,wBAAqB;EAcrE,eAAe;EAMhB,gBAAgB,YAAY,mBAAmB;EAS9C,sBAAsB;EAMtB,eAAe;EAIf,WAAW,kBAAkB;EAK7B,cAAc,mBAAmB,MAAM,aAAa,eAAe,uBAAoB;EAuBvF,cAAc;EAMd,mBAAmB,SAAS,4BAA4B;;;;;;;;;;UA2BjD;EAiCD,iBACX,SAAS,yBACT,mBACC,QAAQ;EAgCE,oBACT,OAAO,MAAM,aAAa,0BAC5B,mBACC,QAAQ;EAuBJ,oBAAoB,iBAAiB,mBAAmB,QAAQ;EAW1D,kBACX,oBACA,wBACA,OAAO,cACP,mBACC"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  import { KeypairCurve } from "@talismn/crypto";
2
2
  //#region src/types/account.d.ts
3
- type LedgerPolkadotCurve = "ed25519" | "ethereum";
4
- type AccountBase = {
3
+ export type LedgerPolkadotCurve = "ed25519" | "ethereum";
4
+ export type AccountBase = {
5
5
  address: string;
6
6
  name: string;
7
7
  createdAt: number;
8
8
  };
9
- type AccountKeypair = AccountBase & {
9
+ export type AccountKeypair = AccountBase & {
10
10
  type: "keypair";
11
11
  curve: KeypairCurve;
12
12
  mnemonicId?: string;
13
13
  derivationPath?: string;
14
14
  };
15
- type AccountContact = AccountBase & {
15
+ export type AccountContact = AccountBase & {
16
16
  type: "contact";
17
17
  genesisHash?: `0x${string}`;
18
18
  };
19
- type AccountWatchOnly = AccountBase & {
19
+ export type AccountWatchOnly = AccountBase & {
20
20
  type: "watch-only";
21
21
  isPortfolio: boolean;
22
22
  };
23
- type AccountLedgerPolkadot = AccountBase & {
23
+ export type AccountLedgerPolkadot = AccountBase & {
24
24
  type: "ledger-polkadot";
25
25
  curve: LedgerPolkadotCurve;
26
26
  app: string;
@@ -28,33 +28,33 @@ type AccountLedgerPolkadot = AccountBase & {
28
28
  addressOffset: number;
29
29
  genesisHash?: `0x${string}`;
30
30
  };
31
- type AccountLedgerEthereum = AccountBase & {
31
+ export type AccountLedgerEthereum = AccountBase & {
32
32
  type: "ledger-ethereum";
33
33
  derivationPath: string;
34
34
  };
35
- type AccountLedgerSolana = AccountBase & {
35
+ export type AccountLedgerSolana = AccountBase & {
36
36
  type: "ledger-solana";
37
37
  derivationPath: string;
38
38
  };
39
- type AccountPolkadotVault = AccountBase & {
39
+ export type AccountPolkadotVault = AccountBase & {
40
40
  type: "polkadot-vault";
41
41
  genesisHash: `0x${string}` | null;
42
42
  };
43
- type AccountSignet = AccountBase & {
43
+ export type AccountSignet = AccountBase & {
44
44
  type: "signet";
45
45
  genesisHash: `0x${string}`;
46
46
  url: string;
47
47
  };
48
- type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
49
- type AccountType = Account["type"];
48
+ export type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
49
+ export type AccountType = Account["type"];
50
50
  //#endregion
51
51
  //#region src/types/keyring.d.ts
52
- type AddMnemonicOptions = {
52
+ export type AddMnemonicOptions = {
53
53
  mnemonic: string;
54
54
  name: string;
55
55
  confirmed: boolean;
56
56
  };
57
- type UpdateMnemonicOptions = {
57
+ export type UpdateMnemonicOptions = {
58
58
  name?: string;
59
59
  confirmed?: boolean;
60
60
  };
@@ -73,20 +73,20 @@ type DeriveFromExistingMnemonic = {
73
73
  derivationPath: string;
74
74
  };
75
75
  type DeriveFromMnemonicOptions = DeriveFromNewMnemonic | DeriveFromExistingMnemonic;
76
- type AddAccountDeriveOptions = Omit<AccountBase, "createdAt" | "address"> & DeriveFromMnemonicOptions;
77
- type AddAccountKeypairOptions = Omit<AccountBase, "createdAt" | "address"> & {
76
+ export type AddAccountDeriveOptions = Omit<AccountBase, "createdAt" | "address"> & DeriveFromMnemonicOptions;
77
+ export type AddAccountKeypairOptions = Omit<AccountBase, "createdAt" | "address"> & {
78
78
  curve: KeypairCurve;
79
79
  secretKey: Uint8Array;
80
80
  };
81
- type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountLedgerSolana, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
82
- type UpdateAccountOptions = {
81
+ export type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountLedgerSolana, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
82
+ export type UpdateAccountOptions = {
83
83
  name?: string;
84
84
  isPortfolio?: boolean;
85
85
  genesisHash?: `0x${string}`;
86
86
  };
87
87
  //#endregion
88
88
  //#region src/types/mnemonic.d.ts
89
- type Mnemonic = {
89
+ export type Mnemonic = {
90
90
  id: string;
91
91
  name: string;
92
92
  confirmed: boolean;
@@ -94,11 +94,11 @@ type Mnemonic = {
94
94
  };
95
95
  //#endregion
96
96
  //#region src/types/utils.d.ts
97
- type AccountOfType<Type extends AccountType> = Extract<Account, {
97
+ export type AccountOfType<Type extends AccountType> = Extract<Account, {
98
98
  type: Type;
99
99
  }>;
100
- declare const isAccountOfType: <Type extends AccountType>(account: Account | null | undefined, type: Type) => account is AccountOfType<Type>;
101
- declare const isAccountInTypes: <Types extends AccountType[]>(account: Account | null | undefined, types: Types) => account is AccountOfType<Types[number]>;
100
+ export declare const isAccountOfType: <Type extends AccountType>(account: Account | null | undefined, type: Type) => account is AccountOfType<Type>;
101
+ export declare const isAccountInTypes: <Types extends AccountType[]>(account: Account | null | undefined, types: Types) => account is AccountOfType<Types[number]>;
102
102
  declare const ACCOUNT_TYPES_OWNED: readonly ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
103
103
  declare const ACCOUNT_TYPES_EXTERNAL: readonly ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
104
104
  declare const ACCOUNT_TYPES_ADDRESS_ETHEREUM: readonly ["contact", "watch-only", "keypair", "ledger-ethereum", "ledger-polkadot"];
@@ -107,50 +107,50 @@ declare const ACCOUNT_TYPES_PLATFORM_POLKADOT: readonly ["contact", "watch-only"
107
107
  declare const ACCOUNT_TYPES_ADDRESS_SS58: readonly ["contact", "watch-only", "keypair", "ledger-polkadot", "polkadot-vault", "signet"];
108
108
  declare const ACCOUNT_TYPES_PLATFORM_SOLANA: readonly ["contact", "watch-only", "keypair", "ledger-solana"];
109
109
  declare const ACCOUNT_TYPES_BITCOIN: readonly ["contact", "watch-only"];
110
- declare const isAccountExternal: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]>;
111
- declare const isAccountOwned: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]>;
112
- declare const isAccountPortfolio: (account: Account | null | undefined) => account is Account;
113
- declare const isAccountNotContact: (acc: Account) => acc is AccountKeypair | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet | AccountWatchOnly;
110
+ export declare const isAccountExternal: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]>;
111
+ export declare const isAccountOwned: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]>;
112
+ export declare const isAccountPortfolio: (account: Account | null | undefined) => account is Account;
113
+ export declare const isAccountNotContact: (acc: Account) => acc is AccountKeypair | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet | AccountWatchOnly;
114
114
  type AccountAddressEthereum = Extract<Account, {
115
115
  type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number];
116
116
  }> & {
117
117
  address: `0x${string}`;
118
118
  };
119
- declare const isAccountAddressEthereum: (account: Account | null | undefined) => account is AccountAddressEthereum;
119
+ export declare const isAccountAddressEthereum: (account: Account | null | undefined) => account is AccountAddressEthereum;
120
120
  type AccountPlatformEthereum = Extract<Account, {
121
121
  type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number];
122
122
  }> & {
123
123
  address: `0x${string}`;
124
124
  };
125
- declare const isAccountPlatformEthereum: (account: Account | null | undefined) => account is AccountPlatformEthereum;
125
+ export declare const isAccountPlatformEthereum: (account: Account | null | undefined) => account is AccountPlatformEthereum;
126
126
  type AccountPlatformSolana = Extract<Account, {
127
127
  type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number];
128
128
  }>;
129
- declare const isAccountPlatformSolana: (account: Account | null | undefined) => account is AccountPlatformSolana;
129
+ export declare const isAccountPlatformSolana: (account: Account | null | undefined) => account is AccountPlatformSolana;
130
130
  type AccountPlatformPolkadot = Extract<Account, {
131
131
  type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number];
132
132
  }>;
133
- declare const isAccountPlatformPolkadot: (account: Account | null | undefined) => account is AccountPlatformPolkadot;
133
+ export declare const isAccountPlatformPolkadot: (account: Account | null | undefined) => account is AccountPlatformPolkadot;
134
134
  type AccountAddressSs58 = Extract<Account, {
135
135
  type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number];
136
136
  }> & {
137
137
  genesisHash?: `0x${string}`;
138
138
  };
139
- declare const isAccountAddressSs58: (account: Account | null | undefined) => account is AccountAddressSs58;
140
- declare const isAccountLedgerPolkadot: (account: Account | null | undefined) => account is AccountLedgerPolkadot;
141
- declare const isAccountLedgerPolkadotGeneric: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
139
+ export declare const isAccountAddressSs58: (account: Account | null | undefined) => account is AccountAddressSs58;
140
+ export declare const isAccountLedgerPolkadot: (account: Account | null | undefined) => account is AccountLedgerPolkadot;
141
+ export declare const isAccountLedgerPolkadotGeneric: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
142
142
  genesisHash: undefined;
143
143
  };
144
- declare const isAccountLedgerPolkadotLegacy: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
144
+ export declare const isAccountLedgerPolkadotLegacy: (account: Account | null | undefined) => account is AccountLedgerPolkadot & {
145
145
  genesisHash: `0x${string}`;
146
146
  };
147
147
  type AccountBitcoin = Extract<Account, {
148
148
  type: (typeof ACCOUNT_TYPES_BITCOIN)[number];
149
149
  }>;
150
- declare const isAccountBitcoin: (account: Account | null | undefined) => account is AccountBitcoin;
151
- declare const getAccountGenesisHash: (account: Account | null | undefined) => `0x${string}` | undefined;
152
- declare const getAccountSignetUrl: (account: Account | null | undefined) => string | undefined;
153
- declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").AccountPlatform | undefined;
150
+ export declare const isAccountBitcoin: (account: Account | null | undefined) => account is AccountBitcoin;
151
+ export declare const getAccountGenesisHash: (account: Account | null | undefined) => `0x${string}` | undefined;
152
+ export declare const getAccountSignetUrl: (account: Account | null | undefined) => string | undefined;
153
+ export declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").AccountPlatform | undefined;
154
154
  //#endregion
155
155
  //#region src/keyring/types.d.ts
156
156
  type MnemonicStorage = Mnemonic & {
@@ -162,12 +162,12 @@ type AccountKeypairStorage = AccountKeypair & {
162
162
  type AccountStorage = AccountKeypairStorage | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
163
163
  //#endregion
164
164
  //#region src/keyring/Keyring.d.ts
165
- type KeyringStorage = {
165
+ export type KeyringStorage = {
166
166
  passwordCheck: string | null;
167
167
  mnemonics: MnemonicStorage[];
168
168
  accounts: AccountStorage[];
169
169
  };
170
- declare class Keyring {
170
+ export declare class Keyring {
171
171
  #private;
172
172
  protected constructor(data: KeyringStorage);
173
173
  static create(): Keyring;
@@ -216,5 +216,4 @@ declare class Keyring {
216
216
  getDerivedAddress(mnemonicId: string, derivationPath: string, curve: KeypairCurve, password: string): Promise<string>;
217
217
  }
218
218
  //#endregion
219
- export { Account, AccountBase, AccountContact, AccountKeypair, AccountLedgerEthereum, AccountLedgerPolkadot, AccountLedgerSolana, AccountOfType, AccountPolkadotVault, AccountSignet, AccountType, AccountWatchOnly, AddAccountDeriveOptions, AddAccountExternalOptions, AddAccountKeypairOptions, AddMnemonicOptions, Keyring, KeyringStorage, LedgerPolkadotCurve, Mnemonic, UpdateAccountOptions, UpdateMnemonicOptions, getAccountGenesisHash, getAccountPlatform, getAccountSignetUrl, isAccountAddressEthereum, isAccountAddressSs58, isAccountBitcoin, isAccountExternal, isAccountInTypes, isAccountLedgerPolkadot, isAccountLedgerPolkadotGeneric, isAccountLedgerPolkadotLegacy, isAccountNotContact, isAccountOfType, isAccountOwned, isAccountPlatformEthereum, isAccountPlatformPolkadot, isAccountPlatformSolana, isAccountPortfolio };
220
219
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/account.ts","../src/types/keyring.ts","../src/types/mnemonic.ts","../src/types/utils.ts","../src/keyring/types.ts","../src/keyring/Keyring.ts"],"mappings":";;KAEY;KAEA;EAIV;EACA;EACA;;KAGU,iBAAiB;EAC3B;EACA,OAAO;EACP;EACA;;KAGU,iBAAiB;EAC3B;EACA;;KAGU,mBAAmB;EAC7B;EACA;;KAGU,wBAAwB;EAClC;EACA,OAAO;EACP;EACA;EACA;EACA;;KAGU,wBAAwB;EAClC;EACA;;KAGU,sBAAsB;EAChC;EACA;;KAGU,uBAAuB;EACjC;EACA;;KAGU,gBAAgB;EAC1B;EACA;EACA;;KAsBU,UACR,iBACA,iBACA,mBACA,wBACA,wBACA,sBACA,uBACA;KAEQ,cAAc;;;KC5Ed;EACV;EACA;EACA;;KAGU;EACV;EACA;;KAGG;EACH;EACA;EACA;EACA;EACA,OAAO;EACP;;KAGG;EACH;EACA;EACA,OAAO;EACP;;KAGG,4BAA4B,wBAAwB;KAE7C,0BAA0B,KAAK,wCACzC;KAEU,2BAA2B,KAAK;EAC1C,OAAO;EACP,WAAW;;KAGD,4BACR,KAAK,+BACL,KAAK,iCACL,KAAK,sCACL,KAAK,sCACL,KAAK,oCACL,KAAK,qCACL,KAAK;KAEG;EACV;EACA;EACA;;;;KC9DU;EACV;EACA;EACA;EACA;;;;KCOU,cAAc,aAAa,eAAe,QAAQ;EAAW,MAAM;;cAElE,kBAAmB,aAAa,aAAW,SAC7C,4BAA0B,MAC7B,SACL,WAAW,cAAc;cAIf,mBAAoB,cAAc,eAAa,SACjD,4BAA0B,OAC5B,UACN,WAAW,cAAc;cAItB;cAQA;cAUA;cAQA;cAOA;cASA;cASA;cAEA;cAEO,oBAAiB,SACnB,+BACR,WAAW,sBAAsB;cAIvB,iBAAc,SAChB,+BACR,WAAW,sBAAsB;cAIvB,qBAAkB,SAAa,+BAA6B,WAAW;cAIvE,sBAAmB,KAAS,YAAO,OAAP,iBAAO,wBAAA,wBAAA,sBAAA,uBAAA,gBAAA;KAE3C,yBAAyB,QAC5B;EACE,cAAc;;EAEhB;;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iBACX,SAAS,yBACT,mBACC,QAAQ;EAgCE,oBACT,OAAO,MAAM,aAAa,0BAC5B,mBACC,QAAQ;EAuBJ,oBAAoB,iBAAiB,mBAAmB,QAAQ;EAW1D,kBACX,oBACA,wBACA,OAAO,cACP,mBACC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/account.ts","../src/types/keyring.ts","../src/types/mnemonic.ts","../src/types/utils.ts","../src/keyring/types.ts","../src/keyring/Keyring.ts"],"mappings":";;YAEY;YAEA;EAIV;EACA;EACA;;YAGU,iBAAiB;EAC3B;EACA,OAAO;EACP;EACA;;YAGU,iBAAiB;EAC3B;EACA;;YAGU,mBAAmB;EAC7B;EACA;;YAGU,wBAAwB;EAClC;EACA,OAAO;EACP;EACA;EACA;EACA;;YAGU,wBAAwB;EAClC;EACA;;YAGU,sBAAsB;EAChC;EACA;;YAGU,uBAAuB;EACjC;EACA;;YAGU,gBAAgB;EAC1B;EACA;EACA;;YAsBU,UACR,iBACA,iBACA,mBACA,wBACA,wBACA,sBACA,uBACA;YAEQ,cAAc;;;YC5Ed;EACV;EACA;EACA;;YAGU;EACV;EACA;;KAGG;EACH;EACA;EACA;EACA;EACA,OAAO;EACP;;KAGG;EACH;EACA;EACA,OAAO;EACP;;KAGG,4BAA4B,wBAAwB;YAE7C,0BAA0B,KAAK,wCACzC;YAEU,2BAA2B,KAAK;EAC1C,OAAO;EACP,WAAW;;YAGD,4BACR,KAAK,+BACL,KAAK,iCACL,KAAK,sCACL,KAAK,sCACL,KAAK,oCACL,KAAK,qCACL,KAAK;YAEG;EACV;EACA;EACA;;;;YC9DU;EACV;EACA;EACA;EACA;;;;YCOU,cAAc,aAAa,eAAe,QAAQ;EAAW,MAAM;;qBAElE,kBAAmB,aAAa,aAAW,SAC7C,4BAA0B,MAC7B,SACL,WAAW,cAAc;qBAIf,mBAAoB,cAAc,eAAa,SACjD,4BAA0B,OAC5B,UACN,WAAW,cAAc;cAItB;cAQA;cAUA;cAQA;cAOA;c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;EA4BJ,YAAY,aAAa;EAKzB,eAAe,cAAc,MAAM,aAAa,wBAAqB;EAcrE,eAAe;EAMhB,gBAAgB,YAAY,mBAAmB;EAS9C,sBAAsB;EAMtB,eAAe;EAIf,WAAW,kBAAkB;EAK7B,cAAc,mBAAmB,MAAM,aAAa,eAAe,uBAAoB;EAuBvF,cAAc;EAMd,mBAAmB,SAAS,4BAA4B;;;;;;;;;;UA2BjD;EAiCD,iBACX,SAAS,yBACT,mBACC,QAAQ;EAgCE,oBACT,OAAO,MAAM,aAAa,0BAC5B,mBACC,QAAQ;EAuBJ,oBAAoB,iBAAiB,mBAAmB,QAAQ;EAW1D,kBACX,oBACA,wBACA,OAAO,cACP,mBACC"}
package/dist/index.js CHANGED
@@ -241,7 +241,8 @@ var Keyring = class Keyring {
241
241
  async getMnemonicText(id, password) {
242
242
  const mnemonic = this.#data.mnemonics.find((s) => s.id === id);
243
243
  if (!mnemonic) throw new Error("Mnemonic not found");
244
- return (0, _talismn_crypto.entropyToMnemonic)(await decryptData(mnemonic.entropy, password));
244
+ const entropy = await decryptData(mnemonic.entropy, password);
245
+ return (0, _talismn_crypto.entropyToMnemonic)(entropy);
245
246
  }
246
247
  getExistingMnemonicId(mnemonic) {
247
248
  const entropy = (0, _talismn_crypto.mnemonicToEntropy)(mnemonic);
@@ -266,10 +267,12 @@ var Keyring = class Keyring {
266
267
  if (typeof isPortfolio !== "boolean") throw new Error("isPortfolio must be a boolean");
267
268
  account.isPortfolio = isPortfolio;
268
269
  }
269
- if (account.type === "contact") if (genesisHash) {
270
- if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
271
- account.genesisHash = genesisHash;
272
- } else delete account.genesisHash;
270
+ if (account.type === "contact") {
271
+ if (genesisHash) {
272
+ if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
273
+ account.genesisHash = genesisHash;
274
+ } else delete account.genesisHash;
275
+ }
273
276
  return accountFromStorage(account);
274
277
  }
275
278
  removeAccount(address) {
@@ -325,7 +328,9 @@ var Keyring = class Keyring {
325
328
  const mnemonicId = await this.ensureMnemonic(options, password);
326
329
  const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId);
327
330
  if (!mnemonic) throw new Error("Mnemonic not found");
328
- const pair = (0, _talismn_crypto.deriveKeypair)(await (0, _talismn_crypto.entropyToSeed)(await decryptData(mnemonic.entropy, password), curve), derivationPath, curve);
331
+ const entropy = await decryptData(mnemonic.entropy, password);
332
+ const seed = await (0, _talismn_crypto.entropyToSeed)(entropy, curve);
333
+ const pair = (0, _talismn_crypto.deriveKeypair)(seed, derivationPath, curve);
329
334
  if (this.getAccount(pair.address)) throw new Error("Account already exists");
330
335
  const account = {
331
336
  type: "keypair",
@@ -342,7 +347,9 @@ var Keyring = class Keyring {
342
347
  }
343
348
  async addAccountKeypair({ curve, name, secretKey }, password) {
344
349
  await this.checkPassword(password);
345
- const address = (0, _talismn_crypto.addressFromPublicKey)((0, _talismn_crypto.getPublicKeyFromSecret)(secretKey, curve), (0, _talismn_crypto.addressEncodingFromCurve)(curve));
350
+ const publicKey = (0, _talismn_crypto.getPublicKeyFromSecret)(secretKey, curve);
351
+ const encoding = (0, _talismn_crypto.addressEncodingFromCurve)(curve);
352
+ const address = (0, _talismn_crypto.addressFromPublicKey)(publicKey, encoding);
346
353
  if (this.getAccount(address)) throw new Error("Account already exists");
347
354
  const account = {
348
355
  type: "keypair",
@@ -368,7 +375,9 @@ var Keyring = class Keyring {
368
375
  if (typeof password !== "string" || !password) throw new Error("password is required");
369
376
  const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId);
370
377
  if (!mnemonic) throw new Error("Mnemonic not found");
371
- return (0, _talismn_crypto.deriveKeypair)(await (0, _talismn_crypto.entropyToSeed)(await decryptData(mnemonic.entropy, password), curve), derivationPath, curve).address;
378
+ const entropy = await decryptData(mnemonic.entropy, password);
379
+ const seed = await (0, _talismn_crypto.entropyToSeed)(entropy, curve);
380
+ return (0, _talismn_crypto.deriveKeypair)(seed, derivationPath, curve).address;
372
381
  }
373
382
  };
374
383
  const oneWayHash = (bytes) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#data","utf8","base58"],"sources":["../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts","../src/keyring/Keyring.ts"],"sourcesContent":["import {\n detectAddressEncoding,\n getAccountPlatformFromAddress,\n getAccountPlatformFromCurve,\n isBitcoinAddress,\n isEthereumAddress,\n isSolanaAddress,\n} from \"@talismn/crypto\"\n\nimport type { Account, AccountLedgerPolkadot, AccountType } from \"./account\"\n\nexport type AccountOfType<Type extends AccountType> = Extract<Account, { type: Type }>\n\nexport const isAccountOfType = <Type extends AccountType>(\n account: Account | null | undefined,\n type: Type\n): account is AccountOfType<Type> => {\n return account?.type === type\n}\n\nexport const isAccountInTypes = <Types extends AccountType[]>(\n account: Account | null | undefined,\n types: Types\n): account is AccountOfType<Types[number]> => {\n return !!account && types.includes(account.type)\n}\n\nconst ACCOUNT_TYPES_OWNED = [\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n] as const\n\nconst ACCOUNT_TYPES_EXTERNAL = [\n \"contact\",\n \"watch-only\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_POLKADOT = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_SS58 = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_SOLANA = [\"contact\", \"watch-only\", \"keypair\", \"ledger-solana\"] as const\n\nconst ACCOUNT_TYPES_BITCOIN = [\"contact\", \"watch-only\"] as const\n\nexport const isAccountExternal = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL as unknown as AccountType[])\n}\n\nexport const isAccountOwned = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_OWNED as unknown as AccountType[])\n}\n\nexport const isAccountPortfolio = (account: Account | null | undefined): account is Account => {\n return isAccountOwned(account) || (isAccountOfType(account, \"watch-only\") && account.isPortfolio)\n}\n\nexport const isAccountNotContact = (acc: Account) => acc.type !== \"contact\"\n\ntype AccountAddressEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountAddressEthereum = (\n account: Account | null | undefined\n): account is AccountAddressEthereum => {\n return !!account && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountPlatformEthereum = (\n account: Account | null | undefined\n): account is AccountPlatformEthereum => {\n return !!account && account.type !== \"ledger-polkadot\" && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformSolana = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number] }\n>\n\nexport const isAccountPlatformSolana = (\n account: Account | null | undefined\n): account is AccountPlatformSolana => {\n return !!account && isSolanaAddress(account.address)\n}\n\ntype AccountPlatformPolkadot = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number] }\n>\nexport const isAccountPlatformPolkadot = (\n account: Account | null | undefined\n): account is AccountPlatformPolkadot => {\n return (\n !!account &&\n account.type !== \"ledger-ethereum\" &&\n (isAccountAddressEthereum(account) || isAccountAddressSs58(account))\n )\n}\n\ntype AccountAddressSs58 = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number] }\n> & {\n genesisHash?: `0x${string}`\n}\nexport const isAccountAddressSs58 = (\n account: Account | null | undefined\n): account is AccountAddressSs58 => {\n return !!account && detectAddressEncoding(account.address) === \"ss58\"\n}\n\nexport const isAccountLedgerPolkadot = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot => {\n return isAccountOfType(account, \"ledger-polkadot\")\n}\n\nexport const isAccountLedgerPolkadotGeneric = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: undefined } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !account.genesisHash\n}\n\nexport const isAccountLedgerPolkadotLegacy = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: `0x${string}` } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !!account.genesisHash\n}\n\ntype AccountBitcoin = Extract<Account, { type: (typeof ACCOUNT_TYPES_BITCOIN)[number] }>\nexport const isAccountBitcoin = (\n account: Account | null | undefined\n): account is AccountBitcoin => {\n return !!account && isBitcoinAddress(account.address)\n}\n\nexport const getAccountGenesisHash = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"genesisHash\" in account ? account.genesisHash || undefined : undefined\n}\n\nexport const getAccountSignetUrl = (account: Account | null | undefined) => {\n return isAccountOfType(account, \"signet\") ? account.url : undefined\n}\n\nexport const getAccountPlatform = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"curve\" in account\n ? getAccountPlatformFromCurve(account.curve)\n : getAccountPlatformFromAddress(account.address)\n}\n","import { pbkdf2 } from \"@talismn/crypto\"\n\n// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption\nconst deriveKey = async (password: string, salt: Uint8Array): Promise<CryptoKey> =>\n // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256\n await crypto.subtle.importKey(\n \"raw\",\n await pbkdf2(\n \"SHA-256\",\n new TextEncoder().encode(password),\n salt,\n 100_000, // 100,000 iterations\n 32 // 32 bytes (32 * 8 == 256 bits)\n ),\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"encrypt\", \"decrypt\"]\n )\n\nexport const encryptData = async (data: Uint8Array, password: string): Promise<string> => {\n try {\n const salt = crypto.getRandomValues(new Uint8Array(16)) // 16 bytes of salt\n const iv = crypto.getRandomValues(new Uint8Array(12)) // 12-byte IV for AES-GCM\n const key = await deriveKey(password, salt)\n\n // encrypt\n const encryptedSeed = await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv },\n key,\n data as Uint8Array<ArrayBuffer>\n )\n\n // Combine salt, IV, and encrypted seed\n const combined = new Uint8Array(salt.length + iv.length + encryptedSeed.byteLength)\n combined.set(salt, 0)\n combined.set(iv, salt.length)\n combined.set(new Uint8Array(encryptedSeed), salt.length + iv.length)\n\n // Base64 encode the combined data\n return btoa(String.fromCharCode(...combined))\n } catch (cause) {\n throw new Error(\"Failed to encrypt data\", { cause })\n }\n}\n\nexport const decryptData = async (encryptedData: string, password: string): Promise<Uint8Array> => {\n try {\n // Decode Base64 and parse the combined data\n const combined = Uint8Array.from(atob(encryptedData), (c) => c.charCodeAt(0))\n\n // Extract salt, IV, and encrypted seed\n const salt = combined.slice(0, 16) // First 16 bytes\n const iv = combined.slice(16, 28) // Next 12 bytes\n const encryptedSeed = combined.slice(28) // Remaining bytes\n\n const key = await deriveKey(password, salt)\n\n // Decrypt the seed\n const decryptedSeed = await crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, key, encryptedSeed)\n\n return new Uint8Array(decryptedSeed)\n } catch (cause) {\n throw new Error(\"Failed to decrypt data\", { cause })\n }\n}\n\nexport const changeEncryptedDataPassword = async (\n encryptedData: string,\n oldPassword: string,\n newPassword: string\n) => {\n try {\n const decrypted = await decryptData(encryptedData, oldPassword)\n return await encryptData(decrypted, newPassword)\n } catch (cause) {\n throw new Error(\"Failed to change password on encrypted data\", { cause })\n }\n}\n","// we dont want to reference @talismn/util in the keyring, so we copy this here\ntype HexString = `0x${string}`\n\nconst REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/\n\nexport const isHexString = (value: unknown): value is HexString => {\n return typeof value === \"string\" && REGEX_HEX_STRING.test(value)\n}\n","import {\n addressEncodingFromCurve,\n addressFromPublicKey,\n base58,\n blake3,\n deriveKeypair,\n entropyToMnemonic,\n entropyToSeed,\n getPublicKeyFromSecret,\n isAddressEqual,\n isValidMnemonic,\n type KeypairCurve,\n mnemonicToEntropy,\n normalizeAddress,\n utf8,\n} from \"@talismn/crypto\"\n\nimport type { Account, Mnemonic } from \"../types\"\nimport { isAccountExternal } from \"../types\"\nimport type {\n AddAccountDeriveOptions,\n AddAccountExternalOptions,\n AddAccountKeypairOptions,\n AddMnemonicOptions,\n UpdateAccountOptions,\n UpdateMnemonicOptions,\n} from \"../types/keyring\"\nimport { changeEncryptedDataPassword, decryptData, encryptData } from \"./encryption\"\nimport type { AccountStorage, MnemonicStorage } from \"./types\"\nimport { isHexString } from \"./utils\"\n\nexport type KeyringStorage = {\n passwordCheck: string | null // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: MnemonicStorage[]\n accounts: AccountStorage[]\n}\n\nexport class Keyring {\n #data: KeyringStorage\n\n protected constructor(data: KeyringStorage) {\n this.#data = structuredClone(data)\n }\n\n public static create(): Keyring {\n return new Keyring({\n passwordCheck: null, // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: [],\n accounts: [],\n })\n }\n\n public static load(data: KeyringStorage): Keyring {\n if (!data.accounts || !data.mnemonics) throw new Error(\"Invalid data\")\n\n // automatic upgrade : set default values for newly introduced properties\n for (const account of data.accounts) {\n // @ts-expect-error\n if (account.type === \"ledger-polkadot\" && !account.curve) account.curve = \"ed25519\"\n }\n\n return new Keyring(data)\n }\n\n private async checkPassword(password: string, reset = false) {\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const passwordHash = oneWayHash(password)\n const PASSWORD_CHECK_PHRASE = \"PASSWORD_CHECK_PHRASE\"\n\n // run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets\n if (!this.#data.passwordCheck || reset) {\n const bytes = utf8.decode(PASSWORD_CHECK_PHRASE)\n this.#data.passwordCheck = await encryptData(bytes, passwordHash)\n } else {\n try {\n const bytes = await decryptData(this.#data.passwordCheck, passwordHash)\n const text = utf8.encode(bytes)\n if (text !== PASSWORD_CHECK_PHRASE) throw new Error(\"Invalid password\")\n } catch {\n throw new Error(\"Invalid password\")\n }\n }\n }\n\n /** Returns true if a password has been set on this keyring. */\n public hasPassword(): boolean {\n return this.#data.passwordCheck !== null\n }\n\n /**\n * Verify a password against the keyring's passwordCheck blob.\n * Returns true on success, false on wrong password.\n * Throws if no password has been set (caller should check hasPassword() first).\n */\n public async verifyPassword(password: string): Promise<boolean> {\n if (!this.#data.passwordCheck) {\n throw new Error(\"No password set — call hasPassword() before verifyPassword()\")\n }\n try {\n await this.checkPassword(password)\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Initialize the password on a fresh keyring that has no password set.\n * Throws if a password is already set (use changePassword flow instead).\n */\n public async initializePassword(password: string): Promise<void> {\n if (this.#data.passwordCheck !== null) {\n throw new Error(\"Password already set — cannot re-initialize\")\n }\n await this.checkPassword(password, true)\n }\n\n public toJson() {\n return structuredClone(this.#data)\n }\n\n public async export(password: string, jsonPassword: string): Promise<KeyringStorage> {\n const keyring = new Keyring(structuredClone(this.#data))\n\n for (const mnemonic of keyring.#data.mnemonics)\n mnemonic.entropy = await changeEncryptedDataPassword(mnemonic.entropy, password, jsonPassword)\n\n for (const account of keyring.#data.accounts)\n if (account.type === \"keypair\")\n account.secretKey = await changeEncryptedDataPassword(\n account.secretKey,\n password,\n jsonPassword\n )\n\n // reset password check\n await keyring.checkPassword(jsonPassword, true)\n\n return keyring.toJson()\n }\n\n public getMnemonics(): Mnemonic[] {\n return this.#data.mnemonics.map(mnemonicFromStorage)\n }\n\n public async addMnemonic(\n { name, mnemonic, confirmed }: AddMnemonicOptions,\n password: string\n ): Promise<Mnemonic> {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n if (typeof mnemonic !== \"string\") throw new Error(\"mnemonic is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n if (!isValidMnemonic(mnemonic)) throw new Error(\"Invalid mnemonic\")\n\n await this.checkPassword(password)\n\n const entropy = mnemonicToEntropy(mnemonic)\n\n // id is a hash of the entropy, helps us prevent having duplicates and allows automatic remapping of accounts/mnemonics if mnemonics are deleted then re-added\n const id = oneWayHash(entropy)\n\n if (this.#data.mnemonics.find((s) => s.id === id)) throw new Error(\"Mnemonic already exists\")\n\n const storage: MnemonicStorage = {\n id,\n name,\n entropy: await encryptData(entropy, password),\n confirmed,\n createdAt: Date.now(),\n }\n\n this.#data.mnemonics.push(storage)\n\n return mnemonicFromStorage(storage)\n }\n\n public getMnemonic(id: string): Mnemonic | null {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n return mnemonic ? mnemonicFromStorage(mnemonic) : null\n }\n\n public updateMnemonic(id: string, { name, confirmed }: UpdateMnemonicOptions) {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n if (name !== undefined) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name must be a string\")\n mnemonic.name = name\n }\n if (confirmed !== undefined) {\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed must be a boolean\")\n mnemonic.confirmed = confirmed\n }\n return mnemonicFromStorage(mnemonic)\n }\n\n public removeMnemonic(id: string) {\n const index = this.#data.mnemonics.findIndex((mnemonic) => mnemonic.id === id)\n if (index === -1) throw new Error(\"Mnemonic not found\")\n this.#data.mnemonics.splice(index, 1)\n }\n\n async getMnemonicText(id: string, password: string): Promise<string> {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n\n return entropyToMnemonic(entropy)\n }\n\n public getExistingMnemonicId(mnemonic: string): string | null {\n const entropy = mnemonicToEntropy(mnemonic)\n const mnemonicId = oneWayHash(entropy)\n return this.#data.mnemonics.some((s) => s.id === mnemonicId) ? mnemonicId : null\n }\n\n public getAccounts(): Account[] {\n return this.#data.accounts.map(accountFromStorage)\n }\n\n public getAccount(address: string): Account | null {\n const account = this.#data.accounts.find((s) => isAddressEqual(s.address, address))\n return account ? accountFromStorage(account) : null\n }\n\n public updateAccount(address: string, { name, isPortfolio, genesisHash }: UpdateAccountOptions) {\n const account = this.#data.accounts.find((s) => s.address === address)\n if (!account) throw new Error(\"Account not found\")\n\n if (name) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n account.name = name\n }\n if (account.type === \"watch-only\" && isPortfolio !== undefined) {\n if (typeof isPortfolio !== \"boolean\") throw new Error(\"isPortfolio must be a boolean\")\n account.isPortfolio = isPortfolio\n }\n // allow updating genesisHash only for contacts\n if (account.type === \"contact\") {\n if (genesisHash) {\n if (!isHexString(genesisHash)) throw new Error(\"genesisHash must be a hex string\")\n account.genesisHash = genesisHash\n } else delete account.genesisHash\n }\n\n return accountFromStorage(account)\n }\n\n public removeAccount(address: string) {\n const index = this.#data.accounts.findIndex((s) => isAddressEqual(s.address, address))\n if (index === -1) throw new Error(\"Account not found\")\n this.#data.accounts.splice(index, 1)\n }\n\n public addAccountExternal(options: AddAccountExternalOptions): Account {\n const address = normalizeAddress(options.address) // breaks if invalid address\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n ...options,\n address,\n createdAt: Date.now(),\n }\n\n if (!isAccountExternal(account)) throw new Error(\"Invalid account type\")\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n /**\n * Needs to be called before deriving an account from a mnemonic.\n *\n * This will ensure that it is present (or add it if possible) in the keyring before actually creating the account.\n *\n * @param options\n * @param password\n * @returns the id of the mnemonic\n */\n private async ensureMnemonic(options: AddAccountDeriveOptions, password: string) {\n await this.checkPassword(password)\n\n switch (options.type) {\n case \"new-mnemonic\": {\n const { mnemonic, mnemonicName: name, confirmed } = options\n\n if (typeof name !== \"string\" || !name) throw new Error(\"mnemonicName is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n\n const mnemonicId = this.getExistingMnemonicId(mnemonic)\n if (mnemonicId) return mnemonicId\n\n const { id } = await this.addMnemonic(\n {\n name,\n mnemonic,\n confirmed,\n },\n password\n )\n\n return id\n }\n case \"existing-mnemonic\": {\n if (typeof options.mnemonicId !== \"string\" || !options.mnemonicId)\n throw new Error(\"mnemonicId must be a string\")\n\n return options.mnemonicId\n }\n }\n }\n\n public async addAccountDerive(\n options: AddAccountDeriveOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const { curve, derivationPath, name } = options\n\n const mnemonicId = await this.ensureMnemonic(options, password)\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n if (this.getAccount(pair.address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(pair.address),\n secretKey: await encryptData(pair.secretKey, password),\n mnemonicId,\n derivationPath,\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public async addAccountKeypair(\n { curve, name, secretKey }: AddAccountKeypairOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const publicKey = getPublicKeyFromSecret(secretKey, curve)\n const encoding = addressEncodingFromCurve(curve)\n const address = addressFromPublicKey(publicKey, encoding)\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(address),\n secretKey: await encryptData(secretKey, password),\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public getAccountSecretKey(address: string, password: string): Promise<Uint8Array> {\n if (typeof address !== \"string\" || !address) throw new Error(\"address is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const account = this.#data.accounts.find((a) => a.address === normalizeAddress(address))\n if (!account) throw new Error(\"Account not found\")\n if (account.type !== \"keypair\") throw new Error(\"Secret key unavailable\")\n\n return decryptData(account.secretKey, password)\n }\n\n public async getDerivedAddress(\n mnemonicId: string,\n derivationPath: string,\n curve: KeypairCurve,\n password: string\n ): Promise<string> {\n if (typeof mnemonicId !== \"string\" || !mnemonicId) throw new Error(\"mnemonicId is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n return pair.address\n }\n}\n\nconst oneWayHash = (bytes: Uint8Array | string) => {\n if (typeof bytes === \"string\") bytes = utf8.decode(bytes)\n\n // cryptographically secure one way hash\n // outputs 44 characters without special characters\n return base58.encode(blake3(bytes))\n}\n\nconst mnemonicFromStorage = (data: MnemonicStorage): Mnemonic => {\n const copy = structuredClone(data) as Mnemonic\n if (\"entropy\" in copy) delete copy.entropy\n return Object.freeze(copy)\n}\n\nconst accountFromStorage = (data: AccountStorage): Account => {\n const copy = structuredClone(data) as Account\n if (\"secretKey\" in copy) delete copy.secretKey\n return Object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AAU;EACrE,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,oBAAoB;EAMnD,QAAA,GAAA,gBAAA,cAAA,CAF2B,OAAA,GAAA,gBAAA,cAAA,CADM,MADX,YAAY,SAAS,SAAS,QAAQ,GAClB,KAAK,GACd,gBAAgB,KAEvC,CAAC,CAAC;CACd;AACF;AAEA,MAAM,cAAc,UAA+B;CACjD,IAAI,OAAO,UAAU,UAAU,QAAQC,gBAAAA,KAAK,OAAO,KAAK;CAIxD,OAAOC,gBAAAA,OAAO,QAAA,GAAA,gBAAA,OAAA,CAAc,KAAK,CAAC;AACpC;AAEA,MAAM,uBAAuB,SAAoC;CAC/D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,aAAa,MAAM,OAAO,KAAK;CACnC,OAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,MAAM,sBAAsB,SAAkC;CAC5D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,eAAe,MAAM,OAAO,KAAK;CACrC,OAAO,OAAO,OAAO,IAAI;AAC3B"}
1
+ {"version":3,"file":"index.js","names":["isEthereumAddress","isSolanaAddress","detectAddressEncoding","isBitcoinAddress","getAccountPlatformFromCurve","getAccountPlatformFromAddress","pbkdf2","utf8","isValidMnemonic","mnemonicToEntropy","entropyToMnemonic","isAddressEqual","normalizeAddress","entropyToSeed","deriveKeypair","getPublicKeyFromSecret","addressEncodingFromCurve","addressFromPublicKey","base58","blake3"],"sources":["../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts","../src/keyring/Keyring.ts"],"sourcesContent":["import {\n detectAddressEncoding,\n getAccountPlatformFromAddress,\n getAccountPlatformFromCurve,\n isBitcoinAddress,\n isEthereumAddress,\n isSolanaAddress,\n} from \"@talismn/crypto\"\n\nimport type { Account, AccountLedgerPolkadot, AccountType } from \"./account\"\n\nexport type AccountOfType<Type extends AccountType> = Extract<Account, { type: Type }>\n\nexport const isAccountOfType = <Type extends AccountType>(\n account: Account | null | undefined,\n type: Type\n): account is AccountOfType<Type> => {\n return account?.type === type\n}\n\nexport const isAccountInTypes = <Types extends AccountType[]>(\n account: Account | null | undefined,\n types: Types\n): account is AccountOfType<Types[number]> => {\n return !!account && types.includes(account.type)\n}\n\nconst ACCOUNT_TYPES_OWNED = [\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n] as const\n\nconst ACCOUNT_TYPES_EXTERNAL = [\n \"contact\",\n \"watch-only\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_POLKADOT = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_SS58 = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_SOLANA = [\"contact\", \"watch-only\", \"keypair\", \"ledger-solana\"] as const\n\nconst ACCOUNT_TYPES_BITCOIN = [\"contact\", \"watch-only\"] as const\n\nexport const isAccountExternal = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL as unknown as AccountType[])\n}\n\nexport const isAccountOwned = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_OWNED as unknown as AccountType[])\n}\n\nexport const isAccountPortfolio = (account: Account | null | undefined): account is Account => {\n return isAccountOwned(account) || (isAccountOfType(account, \"watch-only\") && account.isPortfolio)\n}\n\nexport const isAccountNotContact = (acc: Account) => acc.type !== \"contact\"\n\ntype AccountAddressEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountAddressEthereum = (\n account: Account | null | undefined\n): account is AccountAddressEthereum => {\n return !!account && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountPlatformEthereum = (\n account: Account | null | undefined\n): account is AccountPlatformEthereum => {\n return !!account && account.type !== \"ledger-polkadot\" && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformSolana = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number] }\n>\n\nexport const isAccountPlatformSolana = (\n account: Account | null | undefined\n): account is AccountPlatformSolana => {\n return !!account && isSolanaAddress(account.address)\n}\n\ntype AccountPlatformPolkadot = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number] }\n>\nexport const isAccountPlatformPolkadot = (\n account: Account | null | undefined\n): account is AccountPlatformPolkadot => {\n return (\n !!account &&\n account.type !== \"ledger-ethereum\" &&\n (isAccountAddressEthereum(account) || isAccountAddressSs58(account))\n )\n}\n\ntype AccountAddressSs58 = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number] }\n> & {\n genesisHash?: `0x${string}`\n}\nexport const isAccountAddressSs58 = (\n account: Account | null | undefined\n): account is AccountAddressSs58 => {\n return !!account && detectAddressEncoding(account.address) === \"ss58\"\n}\n\nexport const isAccountLedgerPolkadot = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot => {\n return isAccountOfType(account, \"ledger-polkadot\")\n}\n\nexport const isAccountLedgerPolkadotGeneric = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: undefined } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !account.genesisHash\n}\n\nexport const isAccountLedgerPolkadotLegacy = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: `0x${string}` } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !!account.genesisHash\n}\n\ntype AccountBitcoin = Extract<Account, { type: (typeof ACCOUNT_TYPES_BITCOIN)[number] }>\nexport const isAccountBitcoin = (\n account: Account | null | undefined\n): account is AccountBitcoin => {\n return !!account && isBitcoinAddress(account.address)\n}\n\nexport const getAccountGenesisHash = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"genesisHash\" in account ? account.genesisHash || undefined : undefined\n}\n\nexport const getAccountSignetUrl = (account: Account | null | undefined) => {\n return isAccountOfType(account, \"signet\") ? account.url : undefined\n}\n\nexport const getAccountPlatform = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"curve\" in account\n ? getAccountPlatformFromCurve(account.curve)\n : getAccountPlatformFromAddress(account.address)\n}\n","import { pbkdf2 } from \"@talismn/crypto\"\n\n// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption\nconst deriveKey = async (password: string, salt: Uint8Array): Promise<CryptoKey> =>\n // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256\n await crypto.subtle.importKey(\n \"raw\",\n await pbkdf2(\n \"SHA-256\",\n new TextEncoder().encode(password),\n salt,\n 100_000, // 100,000 iterations\n 32 // 32 bytes (32 * 8 == 256 bits)\n ),\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"encrypt\", \"decrypt\"]\n )\n\nexport const encryptData = async (data: Uint8Array, password: string): Promise<string> => {\n try {\n const salt = crypto.getRandomValues(new Uint8Array(16)) // 16 bytes of salt\n const iv = crypto.getRandomValues(new Uint8Array(12)) // 12-byte IV for AES-GCM\n const key = await deriveKey(password, salt)\n\n // encrypt\n const encryptedSeed = await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv },\n key,\n data as Uint8Array<ArrayBuffer>\n )\n\n // Combine salt, IV, and encrypted seed\n const combined = new Uint8Array(salt.length + iv.length + encryptedSeed.byteLength)\n combined.set(salt, 0)\n combined.set(iv, salt.length)\n combined.set(new Uint8Array(encryptedSeed), salt.length + iv.length)\n\n // Base64 encode the combined data\n return btoa(String.fromCharCode(...combined))\n } catch (cause) {\n throw new Error(\"Failed to encrypt data\", { cause })\n }\n}\n\nexport const decryptData = async (encryptedData: string, password: string): Promise<Uint8Array> => {\n try {\n // Decode Base64 and parse the combined data\n const combined = Uint8Array.from(atob(encryptedData), (c) => c.charCodeAt(0))\n\n // Extract salt, IV, and encrypted seed\n const salt = combined.slice(0, 16) // First 16 bytes\n const iv = combined.slice(16, 28) // Next 12 bytes\n const encryptedSeed = combined.slice(28) // Remaining bytes\n\n const key = await deriveKey(password, salt)\n\n // Decrypt the seed\n const decryptedSeed = await crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, key, encryptedSeed)\n\n return new Uint8Array(decryptedSeed)\n } catch (cause) {\n throw new Error(\"Failed to decrypt data\", { cause })\n }\n}\n\nexport const changeEncryptedDataPassword = async (\n encryptedData: string,\n oldPassword: string,\n newPassword: string\n) => {\n try {\n const decrypted = await decryptData(encryptedData, oldPassword)\n return await encryptData(decrypted, newPassword)\n } catch (cause) {\n throw new Error(\"Failed to change password on encrypted data\", { cause })\n }\n}\n","// we dont want to reference @talismn/util in the keyring, so we copy this here\ntype HexString = `0x${string}`\n\nconst REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/\n\nexport const isHexString = (value: unknown): value is HexString => {\n return typeof value === \"string\" && REGEX_HEX_STRING.test(value)\n}\n","import {\n addressEncodingFromCurve,\n addressFromPublicKey,\n base58,\n blake3,\n deriveKeypair,\n entropyToMnemonic,\n entropyToSeed,\n getPublicKeyFromSecret,\n isAddressEqual,\n isValidMnemonic,\n type KeypairCurve,\n mnemonicToEntropy,\n normalizeAddress,\n utf8,\n} from \"@talismn/crypto\"\n\nimport type { Account, Mnemonic } from \"../types\"\nimport { isAccountExternal } from \"../types\"\nimport type {\n AddAccountDeriveOptions,\n AddAccountExternalOptions,\n AddAccountKeypairOptions,\n AddMnemonicOptions,\n UpdateAccountOptions,\n UpdateMnemonicOptions,\n} from \"../types/keyring\"\nimport { changeEncryptedDataPassword, decryptData, encryptData } from \"./encryption\"\nimport type { AccountStorage, MnemonicStorage } from \"./types\"\nimport { isHexString } from \"./utils\"\n\nexport type KeyringStorage = {\n passwordCheck: string | null // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: MnemonicStorage[]\n accounts: AccountStorage[]\n}\n\nexport class Keyring {\n #data: KeyringStorage\n\n protected constructor(data: KeyringStorage) {\n this.#data = structuredClone(data)\n }\n\n public static create(): Keyring {\n return new Keyring({\n passwordCheck: null, // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: [],\n accounts: [],\n })\n }\n\n public static load(data: KeyringStorage): Keyring {\n if (!data.accounts || !data.mnemonics) throw new Error(\"Invalid data\")\n\n // automatic upgrade : set default values for newly introduced properties\n for (const account of data.accounts) {\n // @ts-expect-error\n if (account.type === \"ledger-polkadot\" && !account.curve) account.curve = \"ed25519\"\n }\n\n return new Keyring(data)\n }\n\n private async checkPassword(password: string, reset = false) {\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const passwordHash = oneWayHash(password)\n const PASSWORD_CHECK_PHRASE = \"PASSWORD_CHECK_PHRASE\"\n\n // run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets\n if (!this.#data.passwordCheck || reset) {\n const bytes = utf8.decode(PASSWORD_CHECK_PHRASE)\n this.#data.passwordCheck = await encryptData(bytes, passwordHash)\n } else {\n try {\n const bytes = await decryptData(this.#data.passwordCheck, passwordHash)\n const text = utf8.encode(bytes)\n if (text !== PASSWORD_CHECK_PHRASE) throw new Error(\"Invalid password\")\n } catch {\n throw new Error(\"Invalid password\")\n }\n }\n }\n\n /** Returns true if a password has been set on this keyring. */\n public hasPassword(): boolean {\n return this.#data.passwordCheck !== null\n }\n\n /**\n * Verify a password against the keyring's passwordCheck blob.\n * Returns true on success, false on wrong password.\n * Throws if no password has been set (caller should check hasPassword() first).\n */\n public async verifyPassword(password: string): Promise<boolean> {\n if (!this.#data.passwordCheck) {\n throw new Error(\"No password set — call hasPassword() before verifyPassword()\")\n }\n try {\n await this.checkPassword(password)\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Initialize the password on a fresh keyring that has no password set.\n * Throws if a password is already set (use changePassword flow instead).\n */\n public async initializePassword(password: string): Promise<void> {\n if (this.#data.passwordCheck !== null) {\n throw new Error(\"Password already set — cannot re-initialize\")\n }\n await this.checkPassword(password, true)\n }\n\n public toJson() {\n return structuredClone(this.#data)\n }\n\n public async export(password: string, jsonPassword: string): Promise<KeyringStorage> {\n const keyring = new Keyring(structuredClone(this.#data))\n\n for (const mnemonic of keyring.#data.mnemonics)\n mnemonic.entropy = await changeEncryptedDataPassword(mnemonic.entropy, password, jsonPassword)\n\n for (const account of keyring.#data.accounts)\n if (account.type === \"keypair\")\n account.secretKey = await changeEncryptedDataPassword(\n account.secretKey,\n password,\n jsonPassword\n )\n\n // reset password check\n await keyring.checkPassword(jsonPassword, true)\n\n return keyring.toJson()\n }\n\n public getMnemonics(): Mnemonic[] {\n return this.#data.mnemonics.map(mnemonicFromStorage)\n }\n\n public async addMnemonic(\n { name, mnemonic, confirmed }: AddMnemonicOptions,\n password: string\n ): Promise<Mnemonic> {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n if (typeof mnemonic !== \"string\") throw new Error(\"mnemonic is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n if (!isValidMnemonic(mnemonic)) throw new Error(\"Invalid mnemonic\")\n\n await this.checkPassword(password)\n\n const entropy = mnemonicToEntropy(mnemonic)\n\n // id is a hash of the entropy, helps us prevent having duplicates and allows automatic remapping of accounts/mnemonics if mnemonics are deleted then re-added\n const id = oneWayHash(entropy)\n\n if (this.#data.mnemonics.find((s) => s.id === id)) throw new Error(\"Mnemonic already exists\")\n\n const storage: MnemonicStorage = {\n id,\n name,\n entropy: await encryptData(entropy, password),\n confirmed,\n createdAt: Date.now(),\n }\n\n this.#data.mnemonics.push(storage)\n\n return mnemonicFromStorage(storage)\n }\n\n public getMnemonic(id: string): Mnemonic | null {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n return mnemonic ? mnemonicFromStorage(mnemonic) : null\n }\n\n public updateMnemonic(id: string, { name, confirmed }: UpdateMnemonicOptions) {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n if (name !== undefined) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name must be a string\")\n mnemonic.name = name\n }\n if (confirmed !== undefined) {\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed must be a boolean\")\n mnemonic.confirmed = confirmed\n }\n return mnemonicFromStorage(mnemonic)\n }\n\n public removeMnemonic(id: string) {\n const index = this.#data.mnemonics.findIndex((mnemonic) => mnemonic.id === id)\n if (index === -1) throw new Error(\"Mnemonic not found\")\n this.#data.mnemonics.splice(index, 1)\n }\n\n async getMnemonicText(id: string, password: string): Promise<string> {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n\n return entropyToMnemonic(entropy)\n }\n\n public getExistingMnemonicId(mnemonic: string): string | null {\n const entropy = mnemonicToEntropy(mnemonic)\n const mnemonicId = oneWayHash(entropy)\n return this.#data.mnemonics.some((s) => s.id === mnemonicId) ? mnemonicId : null\n }\n\n public getAccounts(): Account[] {\n return this.#data.accounts.map(accountFromStorage)\n }\n\n public getAccount(address: string): Account | null {\n const account = this.#data.accounts.find((s) => isAddressEqual(s.address, address))\n return account ? accountFromStorage(account) : null\n }\n\n public updateAccount(address: string, { name, isPortfolio, genesisHash }: UpdateAccountOptions) {\n const account = this.#data.accounts.find((s) => s.address === address)\n if (!account) throw new Error(\"Account not found\")\n\n if (name) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n account.name = name\n }\n if (account.type === \"watch-only\" && isPortfolio !== undefined) {\n if (typeof isPortfolio !== \"boolean\") throw new Error(\"isPortfolio must be a boolean\")\n account.isPortfolio = isPortfolio\n }\n // allow updating genesisHash only for contacts\n if (account.type === \"contact\") {\n if (genesisHash) {\n if (!isHexString(genesisHash)) throw new Error(\"genesisHash must be a hex string\")\n account.genesisHash = genesisHash\n } else delete account.genesisHash\n }\n\n return accountFromStorage(account)\n }\n\n public removeAccount(address: string) {\n const index = this.#data.accounts.findIndex((s) => isAddressEqual(s.address, address))\n if (index === -1) throw new Error(\"Account not found\")\n this.#data.accounts.splice(index, 1)\n }\n\n public addAccountExternal(options: AddAccountExternalOptions): Account {\n const address = normalizeAddress(options.address) // breaks if invalid address\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n ...options,\n address,\n createdAt: Date.now(),\n }\n\n if (!isAccountExternal(account)) throw new Error(\"Invalid account type\")\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n /**\n * Needs to be called before deriving an account from a mnemonic.\n *\n * This will ensure that it is present (or add it if possible) in the keyring before actually creating the account.\n *\n * @param options\n * @param password\n * @returns the id of the mnemonic\n */\n private async ensureMnemonic(options: AddAccountDeriveOptions, password: string) {\n await this.checkPassword(password)\n\n switch (options.type) {\n case \"new-mnemonic\": {\n const { mnemonic, mnemonicName: name, confirmed } = options\n\n if (typeof name !== \"string\" || !name) throw new Error(\"mnemonicName is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n\n const mnemonicId = this.getExistingMnemonicId(mnemonic)\n if (mnemonicId) return mnemonicId\n\n const { id } = await this.addMnemonic(\n {\n name,\n mnemonic,\n confirmed,\n },\n password\n )\n\n return id\n }\n case \"existing-mnemonic\": {\n if (typeof options.mnemonicId !== \"string\" || !options.mnemonicId)\n throw new Error(\"mnemonicId must be a string\")\n\n return options.mnemonicId\n }\n }\n }\n\n public async addAccountDerive(\n options: AddAccountDeriveOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const { curve, derivationPath, name } = options\n\n const mnemonicId = await this.ensureMnemonic(options, password)\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n if (this.getAccount(pair.address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(pair.address),\n secretKey: await encryptData(pair.secretKey, password),\n mnemonicId,\n derivationPath,\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public async addAccountKeypair(\n { curve, name, secretKey }: AddAccountKeypairOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const publicKey = getPublicKeyFromSecret(secretKey, curve)\n const encoding = addressEncodingFromCurve(curve)\n const address = addressFromPublicKey(publicKey, encoding)\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(address),\n secretKey: await encryptData(secretKey, password),\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public getAccountSecretKey(address: string, password: string): Promise<Uint8Array> {\n if (typeof address !== \"string\" || !address) throw new Error(\"address is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const account = this.#data.accounts.find((a) => a.address === normalizeAddress(address))\n if (!account) throw new Error(\"Account not found\")\n if (account.type !== \"keypair\") throw new Error(\"Secret key unavailable\")\n\n return decryptData(account.secretKey, password)\n }\n\n public async getDerivedAddress(\n mnemonicId: string,\n derivationPath: string,\n curve: KeypairCurve,\n password: string\n ): Promise<string> {\n if (typeof mnemonicId !== \"string\" || !mnemonicId) throw new Error(\"mnemonicId is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n return pair.address\n }\n}\n\nconst oneWayHash = (bytes: Uint8Array | string) => {\n if (typeof bytes === \"string\") bytes = utf8.decode(bytes)\n\n // cryptographically secure one way hash\n // outputs 44 characters without special characters\n return base58.encode(blake3(bytes))\n}\n\nconst mnemonicFromStorage = (data: MnemonicStorage): Mnemonic => {\n const copy = structuredClone(data) as Mnemonic\n if (\"entropy\" in copy) delete copy.entropy\n return Object.freeze(copy)\n}\n\nconst accountFromStorage = (data: AccountStorage): Account => {\n const copy = structuredClone(data) as Account\n if (\"secretKey\" in copy) delete copy.secretKey\n return Object.freeze(copy)\n}\n"],"mappings":";;;AAaA,MAAa,mBACX,SACA,SACmC;CACnC,OAAO,SAAS,SAAS;AAC3B;AAEA,MAAa,oBACX,SACA,UAC4C;CAC5C,OAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAuCA,MAAa,qBACX,YACsE;CACtE,OAAO,iBAAiB,SAAS,sBAAkD;AACrF;AAEA,MAAa,kBACX,YACmE;CACnE,OAAO,iBAAiB,SAAS,mBAA+C;AAClF;AAEA,MAAa,sBAAsB,YAA4D;CAC7F,OAAO,eA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U,UAAU,QAAQP,gBAAAA,KAAK,OAAO,KAAK;CAIxD,OAAOW,gBAAAA,OAAO,QAAA,GAAOC,gBAAAA,OAAAA,CAAO,KAAK,CAAC;AACpC;AAEA,MAAM,uBAAuB,SAAoC;CAC/D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,aAAa,MAAM,OAAO,KAAK;CACnC,OAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,MAAM,sBAAsB,SAAkC;CAC5D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,eAAe,MAAM,OAAO,KAAK;CACrC,OAAO,OAAO,OAAO,IAAI;AAC3B"}
package/dist/index.mjs CHANGED
@@ -240,7 +240,8 @@ var Keyring = class Keyring {
240
240
  async getMnemonicText(id, password) {
241
241
  const mnemonic = this.#data.mnemonics.find((s) => s.id === id);
242
242
  if (!mnemonic) throw new Error("Mnemonic not found");
243
- return entropyToMnemonic(await decryptData(mnemonic.entropy, password));
243
+ const entropy = await decryptData(mnemonic.entropy, password);
244
+ return entropyToMnemonic(entropy);
244
245
  }
245
246
  getExistingMnemonicId(mnemonic) {
246
247
  const entropy = mnemonicToEntropy(mnemonic);
@@ -265,10 +266,12 @@ var Keyring = class Keyring {
265
266
  if (typeof isPortfolio !== "boolean") throw new Error("isPortfolio must be a boolean");
266
267
  account.isPortfolio = isPortfolio;
267
268
  }
268
- if (account.type === "contact") if (genesisHash) {
269
- if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
270
- account.genesisHash = genesisHash;
271
- } else delete account.genesisHash;
269
+ if (account.type === "contact") {
270
+ if (genesisHash) {
271
+ if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
272
+ account.genesisHash = genesisHash;
273
+ } else delete account.genesisHash;
274
+ }
272
275
  return accountFromStorage(account);
273
276
  }
274
277
  removeAccount(address) {
@@ -324,7 +327,9 @@ var Keyring = class Keyring {
324
327
  const mnemonicId = await this.ensureMnemonic(options, password);
325
328
  const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId);
326
329
  if (!mnemonic) throw new Error("Mnemonic not found");
327
- const pair = deriveKeypair(await entropyToSeed(await decryptData(mnemonic.entropy, password), curve), derivationPath, curve);
330
+ const entropy = await decryptData(mnemonic.entropy, password);
331
+ const seed = await entropyToSeed(entropy, curve);
332
+ const pair = deriveKeypair(seed, derivationPath, curve);
328
333
  if (this.getAccount(pair.address)) throw new Error("Account already exists");
329
334
  const account = {
330
335
  type: "keypair",
@@ -341,7 +346,9 @@ var Keyring = class Keyring {
341
346
  }
342
347
  async addAccountKeypair({ curve, name, secretKey }, password) {
343
348
  await this.checkPassword(password);
344
- const address = addressFromPublicKey(getPublicKeyFromSecret(secretKey, curve), addressEncodingFromCurve(curve));
349
+ const publicKey = getPublicKeyFromSecret(secretKey, curve);
350
+ const encoding = addressEncodingFromCurve(curve);
351
+ const address = addressFromPublicKey(publicKey, encoding);
345
352
  if (this.getAccount(address)) throw new Error("Account already exists");
346
353
  const account = {
347
354
  type: "keypair",
@@ -367,7 +374,9 @@ var Keyring = class Keyring {
367
374
  if (typeof password !== "string" || !password) throw new Error("password is required");
368
375
  const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId);
369
376
  if (!mnemonic) throw new Error("Mnemonic not found");
370
- return deriveKeypair(await entropyToSeed(await decryptData(mnemonic.entropy, password), curve), derivationPath, curve).address;
377
+ const entropy = await decryptData(mnemonic.entropy, password);
378
+ const seed = await entropyToSeed(entropy, curve);
379
+ return deriveKeypair(seed, derivationPath, curve).address;
371
380
  }
372
381
  };
373
382
  const oneWayHash = (bytes) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#data"],"sources":["../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts","../src/keyring/Keyring.ts"],"sourcesContent":["import {\n detectAddressEncoding,\n getAccountPlatformFromAddress,\n getAccountPlatformFromCurve,\n isBitcoinAddress,\n isEthereumAddress,\n isSolanaAddress,\n} from \"@talismn/crypto\"\n\nimport type { Account, AccountLedgerPolkadot, AccountType } from \"./account\"\n\nexport type AccountOfType<Type extends AccountType> = Extract<Account, { type: Type }>\n\nexport const isAccountOfType = <Type extends AccountType>(\n account: Account | null | undefined,\n type: Type\n): account is AccountOfType<Type> => {\n return account?.type === type\n}\n\nexport const isAccountInTypes = <Types extends AccountType[]>(\n account: Account | null | undefined,\n types: Types\n): account is AccountOfType<Types[number]> => {\n return !!account && types.includes(account.type)\n}\n\nconst ACCOUNT_TYPES_OWNED = [\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n] as const\n\nconst ACCOUNT_TYPES_EXTERNAL = [\n \"contact\",\n \"watch-only\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_POLKADOT = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_SS58 = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_SOLANA = [\"contact\", \"watch-only\", \"keypair\", \"ledger-solana\"] as const\n\nconst ACCOUNT_TYPES_BITCOIN = [\"contact\", \"watch-only\"] as const\n\nexport const isAccountExternal = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL as unknown as AccountType[])\n}\n\nexport const isAccountOwned = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_OWNED as unknown as AccountType[])\n}\n\nexport const isAccountPortfolio = (account: Account | null | undefined): account is Account => {\n return isAccountOwned(account) || (isAccountOfType(account, \"watch-only\") && account.isPortfolio)\n}\n\nexport const isAccountNotContact = (acc: Account) => acc.type !== \"contact\"\n\ntype AccountAddressEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountAddressEthereum = (\n account: Account | null | undefined\n): account is AccountAddressEthereum => {\n return !!account && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountPlatformEthereum = (\n account: Account | null | undefined\n): account is AccountPlatformEthereum => {\n return !!account && account.type !== \"ledger-polkadot\" && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformSolana = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number] }\n>\n\nexport const isAccountPlatformSolana = (\n account: Account | null | undefined\n): account is AccountPlatformSolana => {\n return !!account && isSolanaAddress(account.address)\n}\n\ntype AccountPlatformPolkadot = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number] }\n>\nexport const isAccountPlatformPolkadot = (\n account: Account | null | undefined\n): account is AccountPlatformPolkadot => {\n return (\n !!account &&\n account.type !== \"ledger-ethereum\" &&\n (isAccountAddressEthereum(account) || isAccountAddressSs58(account))\n )\n}\n\ntype AccountAddressSs58 = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number] }\n> & {\n genesisHash?: `0x${string}`\n}\nexport const isAccountAddressSs58 = (\n account: Account | null | undefined\n): account is AccountAddressSs58 => {\n return !!account && detectAddressEncoding(account.address) === \"ss58\"\n}\n\nexport const isAccountLedgerPolkadot = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot => {\n return isAccountOfType(account, \"ledger-polkadot\")\n}\n\nexport const isAccountLedgerPolkadotGeneric = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: undefined } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !account.genesisHash\n}\n\nexport const isAccountLedgerPolkadotLegacy = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: `0x${string}` } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !!account.genesisHash\n}\n\ntype AccountBitcoin = Extract<Account, { type: (typeof ACCOUNT_TYPES_BITCOIN)[number] }>\nexport const isAccountBitcoin = (\n account: Account | null | undefined\n): account is AccountBitcoin => {\n return !!account && isBitcoinAddress(account.address)\n}\n\nexport const getAccountGenesisHash = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"genesisHash\" in account ? account.genesisHash || undefined : undefined\n}\n\nexport const getAccountSignetUrl = (account: Account | null | undefined) => {\n return isAccountOfType(account, \"signet\") ? account.url : undefined\n}\n\nexport const getAccountPlatform = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"curve\" in account\n ? getAccountPlatformFromCurve(account.curve)\n : getAccountPlatformFromAddress(account.address)\n}\n","import { pbkdf2 } from \"@talismn/crypto\"\n\n// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption\nconst deriveKey = async (password: string, salt: Uint8Array): Promise<CryptoKey> =>\n // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256\n await crypto.subtle.importKey(\n \"raw\",\n await pbkdf2(\n \"SHA-256\",\n new TextEncoder().encode(password),\n salt,\n 100_000, // 100,000 iterations\n 32 // 32 bytes (32 * 8 == 256 bits)\n ),\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"encrypt\", \"decrypt\"]\n )\n\nexport const encryptData = async (data: Uint8Array, password: string): Promise<string> => {\n try {\n const salt = crypto.getRandomValues(new Uint8Array(16)) // 16 bytes of salt\n const iv = crypto.getRandomValues(new Uint8Array(12)) // 12-byte IV for AES-GCM\n const key = await deriveKey(password, salt)\n\n // encrypt\n const encryptedSeed = await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv },\n key,\n data as Uint8Array<ArrayBuffer>\n )\n\n // Combine salt, IV, and encrypted seed\n const combined = new Uint8Array(salt.length + iv.length + encryptedSeed.byteLength)\n combined.set(salt, 0)\n combined.set(iv, salt.length)\n combined.set(new Uint8Array(encryptedSeed), salt.length + iv.length)\n\n // Base64 encode the combined data\n return btoa(String.fromCharCode(...combined))\n } catch (cause) {\n throw new Error(\"Failed to encrypt data\", { cause })\n }\n}\n\nexport const decryptData = async (encryptedData: string, password: string): Promise<Uint8Array> => {\n try {\n // Decode Base64 and parse the combined data\n const combined = Uint8Array.from(atob(encryptedData), (c) => c.charCodeAt(0))\n\n // Extract salt, IV, and encrypted seed\n const salt = combined.slice(0, 16) // First 16 bytes\n const iv = combined.slice(16, 28) // Next 12 bytes\n const encryptedSeed = combined.slice(28) // Remaining bytes\n\n const key = await deriveKey(password, salt)\n\n // Decrypt the seed\n const decryptedSeed = await crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, key, encryptedSeed)\n\n return new Uint8Array(decryptedSeed)\n } catch (cause) {\n throw new Error(\"Failed to decrypt data\", { cause })\n }\n}\n\nexport const changeEncryptedDataPassword = async (\n encryptedData: string,\n oldPassword: string,\n newPassword: string\n) => {\n try {\n const decrypted = await decryptData(encryptedData, oldPassword)\n return await encryptData(decrypted, newPassword)\n } catch (cause) {\n throw new Error(\"Failed to change password on encrypted data\", { cause })\n }\n}\n","// we dont want to reference @talismn/util in the keyring, so we copy this here\ntype HexString = `0x${string}`\n\nconst REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/\n\nexport const isHexString = (value: unknown): value is HexString => {\n return typeof value === \"string\" && REGEX_HEX_STRING.test(value)\n}\n","import {\n addressEncodingFromCurve,\n addressFromPublicKey,\n base58,\n blake3,\n deriveKeypair,\n entropyToMnemonic,\n entropyToSeed,\n getPublicKeyFromSecret,\n isAddressEqual,\n isValidMnemonic,\n type KeypairCurve,\n mnemonicToEntropy,\n normalizeAddress,\n utf8,\n} from \"@talismn/crypto\"\n\nimport type { Account, Mnemonic } from \"../types\"\nimport { isAccountExternal } from \"../types\"\nimport type {\n AddAccountDeriveOptions,\n AddAccountExternalOptions,\n AddAccountKeypairOptions,\n AddMnemonicOptions,\n UpdateAccountOptions,\n UpdateMnemonicOptions,\n} from \"../types/keyring\"\nimport { changeEncryptedDataPassword, decryptData, encryptData } from \"./encryption\"\nimport type { AccountStorage, MnemonicStorage } from \"./types\"\nimport { isHexString } from \"./utils\"\n\nexport type KeyringStorage = {\n passwordCheck: string | null // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: MnemonicStorage[]\n accounts: AccountStorage[]\n}\n\nexport class Keyring {\n #data: KeyringStorage\n\n protected constructor(data: KeyringStorage) {\n this.#data = structuredClone(data)\n }\n\n public static create(): Keyring {\n return new Keyring({\n passwordCheck: null, // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: [],\n accounts: [],\n })\n }\n\n public static load(data: KeyringStorage): Keyring {\n if (!data.accounts || !data.mnemonics) throw new Error(\"Invalid data\")\n\n // automatic upgrade : set default values for newly introduced properties\n for (const account of data.accounts) {\n // @ts-expect-error\n if (account.type === \"ledger-polkadot\" && !account.curve) account.curve = \"ed25519\"\n }\n\n return new Keyring(data)\n }\n\n private async checkPassword(password: string, reset = false) {\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const passwordHash = oneWayHash(password)\n const PASSWORD_CHECK_PHRASE = \"PASSWORD_CHECK_PHRASE\"\n\n // run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets\n if (!this.#data.passwordCheck || reset) {\n const bytes = utf8.decode(PASSWORD_CHECK_PHRASE)\n this.#data.passwordCheck = await encryptData(bytes, passwordHash)\n } else {\n try {\n const bytes = await decryptData(this.#data.passwordCheck, passwordHash)\n const text = utf8.encode(bytes)\n if (text !== PASSWORD_CHECK_PHRASE) throw new Error(\"Invalid password\")\n } catch {\n throw new Error(\"Invalid password\")\n }\n }\n }\n\n /** Returns true if a password has been set on this keyring. */\n public hasPassword(): boolean {\n return this.#data.passwordCheck !== null\n }\n\n /**\n * Verify a password against the keyring's passwordCheck blob.\n * Returns true on success, false on wrong password.\n * Throws if no password has been set (caller should check hasPassword() first).\n */\n public async verifyPassword(password: string): Promise<boolean> {\n if (!this.#data.passwordCheck) {\n throw new Error(\"No password set — call hasPassword() before verifyPassword()\")\n }\n try {\n await this.checkPassword(password)\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Initialize the password on a fresh keyring that has no password set.\n * Throws if a password is already set (use changePassword flow instead).\n */\n public async initializePassword(password: string): Promise<void> {\n if (this.#data.passwordCheck !== null) {\n throw new Error(\"Password already set — cannot re-initialize\")\n }\n await this.checkPassword(password, true)\n }\n\n public toJson() {\n return structuredClone(this.#data)\n }\n\n public async export(password: string, jsonPassword: string): Promise<KeyringStorage> {\n const keyring = new Keyring(structuredClone(this.#data))\n\n for (const mnemonic of keyring.#data.mnemonics)\n mnemonic.entropy = await changeEncryptedDataPassword(mnemonic.entropy, password, jsonPassword)\n\n for (const account of keyring.#data.accounts)\n if (account.type === \"keypair\")\n account.secretKey = await changeEncryptedDataPassword(\n account.secretKey,\n password,\n jsonPassword\n )\n\n // reset password check\n await keyring.checkPassword(jsonPassword, true)\n\n return keyring.toJson()\n }\n\n public getMnemonics(): Mnemonic[] {\n return this.#data.mnemonics.map(mnemonicFromStorage)\n }\n\n public async addMnemonic(\n { name, mnemonic, confirmed }: AddMnemonicOptions,\n password: string\n ): Promise<Mnemonic> {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n if (typeof mnemonic !== \"string\") throw new Error(\"mnemonic is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n if (!isValidMnemonic(mnemonic)) throw new Error(\"Invalid mnemonic\")\n\n await this.checkPassword(password)\n\n const entropy = mnemonicToEntropy(mnemonic)\n\n // id is a hash of the entropy, helps us prevent having duplicates and allows automatic remapping of accounts/mnemonics if mnemonics are deleted then re-added\n const id = oneWayHash(entropy)\n\n if (this.#data.mnemonics.find((s) => s.id === id)) throw new Error(\"Mnemonic already exists\")\n\n const storage: MnemonicStorage = {\n id,\n name,\n entropy: await encryptData(entropy, password),\n confirmed,\n createdAt: Date.now(),\n }\n\n this.#data.mnemonics.push(storage)\n\n return mnemonicFromStorage(storage)\n }\n\n public getMnemonic(id: string): Mnemonic | null {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n return mnemonic ? mnemonicFromStorage(mnemonic) : null\n }\n\n public updateMnemonic(id: string, { name, confirmed }: UpdateMnemonicOptions) {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n if (name !== undefined) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name must be a string\")\n mnemonic.name = name\n }\n if (confirmed !== undefined) {\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed must be a boolean\")\n mnemonic.confirmed = confirmed\n }\n return mnemonicFromStorage(mnemonic)\n }\n\n public removeMnemonic(id: string) {\n const index = this.#data.mnemonics.findIndex((mnemonic) => mnemonic.id === id)\n if (index === -1) throw new Error(\"Mnemonic not found\")\n this.#data.mnemonics.splice(index, 1)\n }\n\n async getMnemonicText(id: string, password: string): Promise<string> {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n\n return entropyToMnemonic(entropy)\n }\n\n public getExistingMnemonicId(mnemonic: string): string | null {\n const entropy = mnemonicToEntropy(mnemonic)\n const mnemonicId = oneWayHash(entropy)\n return this.#data.mnemonics.some((s) => s.id === mnemonicId) ? mnemonicId : null\n }\n\n public getAccounts(): Account[] {\n return this.#data.accounts.map(accountFromStorage)\n }\n\n public getAccount(address: string): Account | null {\n const account = this.#data.accounts.find((s) => isAddressEqual(s.address, address))\n return account ? accountFromStorage(account) : null\n }\n\n public updateAccount(address: string, { name, isPortfolio, genesisHash }: UpdateAccountOptions) {\n const account = this.#data.accounts.find((s) => s.address === address)\n if (!account) throw new Error(\"Account not found\")\n\n if (name) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n account.name = name\n }\n if (account.type === \"watch-only\" && isPortfolio !== undefined) {\n if (typeof isPortfolio !== \"boolean\") throw new Error(\"isPortfolio must be a boolean\")\n account.isPortfolio = isPortfolio\n }\n // allow updating genesisHash only for contacts\n if (account.type === \"contact\") {\n if (genesisHash) {\n if (!isHexString(genesisHash)) throw new Error(\"genesisHash must be a hex string\")\n account.genesisHash = genesisHash\n } else delete account.genesisHash\n }\n\n return accountFromStorage(account)\n }\n\n public removeAccount(address: string) {\n const index = this.#data.accounts.findIndex((s) => isAddressEqual(s.address, address))\n if (index === -1) throw new Error(\"Account not found\")\n this.#data.accounts.splice(index, 1)\n }\n\n public addAccountExternal(options: AddAccountExternalOptions): Account {\n const address = normalizeAddress(options.address) // breaks if invalid address\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n ...options,\n address,\n createdAt: Date.now(),\n }\n\n if (!isAccountExternal(account)) throw new Error(\"Invalid account type\")\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n /**\n * Needs to be called before deriving an account from a mnemonic.\n *\n * This will ensure that it is present (or add it if possible) in the keyring before actually creating the account.\n *\n * @param options\n * @param password\n * @returns the id of the mnemonic\n */\n private async ensureMnemonic(options: AddAccountDeriveOptions, password: string) {\n await this.checkPassword(password)\n\n switch (options.type) {\n case \"new-mnemonic\": {\n const { mnemonic, mnemonicName: name, confirmed } = options\n\n if (typeof name !== \"string\" || !name) throw new Error(\"mnemonicName is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n\n const mnemonicId = this.getExistingMnemonicId(mnemonic)\n if (mnemonicId) return mnemonicId\n\n const { id } = await this.addMnemonic(\n {\n name,\n mnemonic,\n confirmed,\n },\n password\n )\n\n return id\n }\n case \"existing-mnemonic\": {\n if (typeof options.mnemonicId !== \"string\" || !options.mnemonicId)\n throw new Error(\"mnemonicId must be a string\")\n\n return options.mnemonicId\n }\n }\n }\n\n public async addAccountDerive(\n options: AddAccountDeriveOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const { curve, derivationPath, name } = options\n\n const mnemonicId = await this.ensureMnemonic(options, password)\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n if (this.getAccount(pair.address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(pair.address),\n secretKey: await encryptData(pair.secretKey, password),\n mnemonicId,\n derivationPath,\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public async addAccountKeypair(\n { curve, name, secretKey }: AddAccountKeypairOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const publicKey = getPublicKeyFromSecret(secretKey, curve)\n const encoding = addressEncodingFromCurve(curve)\n const address = addressFromPublicKey(publicKey, encoding)\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(address),\n secretKey: await encryptData(secretKey, password),\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public getAccountSecretKey(address: string, password: string): Promise<Uint8Array> {\n if (typeof address !== \"string\" || !address) throw new Error(\"address is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const account = this.#data.accounts.find((a) => a.address === normalizeAddress(address))\n if (!account) throw new Error(\"Account not found\")\n if (account.type !== \"keypair\") throw new Error(\"Secret key unavailable\")\n\n return decryptData(account.secretKey, password)\n }\n\n public async getDerivedAddress(\n mnemonicId: string,\n derivationPath: string,\n curve: KeypairCurve,\n password: string\n ): Promise<string> {\n if (typeof mnemonicId !== \"string\" || !mnemonicId) throw new Error(\"mnemonicId is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n return pair.address\n }\n}\n\nconst oneWayHash = (bytes: Uint8Array | string) => {\n if (typeof bytes === \"string\") bytes = utf8.decode(bytes)\n\n // cryptographically secure one way hash\n // outputs 44 characters without special characters\n return base58.encode(blake3(bytes))\n}\n\nconst mnemonicFromStorage = (data: MnemonicStorage): Mnemonic => {\n const copy = structuredClone(data) as Mnemonic\n if (\"entropy\" in copy) delete copy.entropy\n return Object.freeze(copy)\n}\n\nconst accountFromStorage = (data: AccountStorage): Account => {\n const copy = structuredClone(data) as Account\n if (\"secretKey\" in copy) delete copy.secretKey\n return Object.freeze(copy)\n}\n"],"mappings":";;AAaA,MAAa,mBACX,SACA,SACmC;CACnC,OAAO,SAAS,SAAS;AAC3B;AAEA,MAAa,oBACX,SACA,UAC4C;CAC5C,OAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAuCA,MAAa,qBACX,YACsE;CACtE,OAAO,iBAA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AS,MAAM,MAAM,EAAE,YAAY,iBAAiB,OAAO,CAAC;EACvF,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,mBAAmB;EACjD,IAAI,QAAQ,SAAS,WAAW,MAAM,IAAI,MAAM,wBAAwB;EAExE,OAAO,YAAY,QAAQ,WAAW,QAAQ;CAChD;CAEA,MAAa,kBACX,YACA,gBACA,OACA,UACiB;EACjB,IAAI,OAAO,eAAe,YAAY,CAAC,YAAY,MAAM,IAAI,MAAM,wBAAwB;EAC3F,IAAI,OAAO,aAAa,YAAY,CAAC,UAAU,MAAM,IAAI,MAAM,sBAAsB;EAErF,MAAM,WAAW,KAAKA,MAAM,UAAU,MAAM,MAAM,EAAE,OAAO,UAAU;EACrE,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,oBAAoB;EAMnD,OAFa,cAAc,MADR,cAAc,MADX,YAAY,SAAS,SAAS,QAAQ,GAClB,KAAK,GACd,gBAAgB,KAEvC,CAAC,CAAC;CACd;AACF;AAEA,MAAM,cAAc,UAA+B;CACjD,IAAI,OAAO,UAAU,UAAU,QAAQ,KAAK,OAAO,KAAK;CAIxD,OAAO,OAAO,OAAO,OAAO,KAAK,CAAC;AACpC;AAEA,MAAM,uBAAuB,SAAoC;CAC/D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,aAAa,MAAM,OAAO,KAAK;CACnC,OAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,MAAM,sBAAsB,SAAkC;CAC5D,MAAM,OAAO,gBAAgB,IAAI;CACjC,IAAI,eAAe,MAAM,OAAO,KAAK;CACrC,OAAO,OAAO,OAAO,IAAI;AAC3B"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts","../src/keyring/Keyring.ts"],"sourcesContent":["import {\n detectAddressEncoding,\n getAccountPlatformFromAddress,\n getAccountPlatformFromCurve,\n isBitcoinAddress,\n isEthereumAddress,\n isSolanaAddress,\n} from \"@talismn/crypto\"\n\nimport type { Account, AccountLedgerPolkadot, AccountType } from \"./account\"\n\nexport type AccountOfType<Type extends AccountType> = Extract<Account, { type: Type }>\n\nexport const isAccountOfType = <Type extends AccountType>(\n account: Account | null | undefined,\n type: Type\n): account is AccountOfType<Type> => {\n return account?.type === type\n}\n\nexport const isAccountInTypes = <Types extends AccountType[]>(\n account: Account | null | undefined,\n types: Types\n): account is AccountOfType<Types[number]> => {\n return !!account && types.includes(account.type)\n}\n\nconst ACCOUNT_TYPES_OWNED = [\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n] as const\n\nconst ACCOUNT_TYPES_EXTERNAL = [\n \"contact\",\n \"watch-only\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n \"ledger-solana\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n \"ledger-polkadot\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_ETHEREUM = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-ethereum\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_POLKADOT = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_ADDRESS_SS58 = [\n \"contact\",\n \"watch-only\",\n \"keypair\",\n \"ledger-polkadot\",\n \"polkadot-vault\",\n \"signet\",\n] as const\n\nconst ACCOUNT_TYPES_PLATFORM_SOLANA = [\"contact\", \"watch-only\", \"keypair\", \"ledger-solana\"] as const\n\nconst ACCOUNT_TYPES_BITCOIN = [\"contact\", \"watch-only\"] as const\n\nexport const isAccountExternal = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL as unknown as AccountType[])\n}\n\nexport const isAccountOwned = (\n account: Account | null | undefined\n): account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]> => {\n return isAccountInTypes(account, ACCOUNT_TYPES_OWNED as unknown as AccountType[])\n}\n\nexport const isAccountPortfolio = (account: Account | null | undefined): account is Account => {\n return isAccountOwned(account) || (isAccountOfType(account, \"watch-only\") && account.isPortfolio)\n}\n\nexport const isAccountNotContact = (acc: Account) => acc.type !== \"contact\"\n\ntype AccountAddressEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountAddressEthereum = (\n account: Account | null | undefined\n): account is AccountAddressEthereum => {\n return !!account && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformEthereum = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_ETHEREUM)[number] }\n> & {\n address: `0x${string}`\n}\nexport const isAccountPlatformEthereum = (\n account: Account | null | undefined\n): account is AccountPlatformEthereum => {\n return !!account && account.type !== \"ledger-polkadot\" && isEthereumAddress(account.address)\n}\n\ntype AccountPlatformSolana = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number] }\n>\n\nexport const isAccountPlatformSolana = (\n account: Account | null | undefined\n): account is AccountPlatformSolana => {\n return !!account && isSolanaAddress(account.address)\n}\n\ntype AccountPlatformPolkadot = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number] }\n>\nexport const isAccountPlatformPolkadot = (\n account: Account | null | undefined\n): account is AccountPlatformPolkadot => {\n return (\n !!account &&\n account.type !== \"ledger-ethereum\" &&\n (isAccountAddressEthereum(account) || isAccountAddressSs58(account))\n )\n}\n\ntype AccountAddressSs58 = Extract<\n Account,\n { type: (typeof ACCOUNT_TYPES_ADDRESS_SS58)[number] }\n> & {\n genesisHash?: `0x${string}`\n}\nexport const isAccountAddressSs58 = (\n account: Account | null | undefined\n): account is AccountAddressSs58 => {\n return !!account && detectAddressEncoding(account.address) === \"ss58\"\n}\n\nexport const isAccountLedgerPolkadot = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot => {\n return isAccountOfType(account, \"ledger-polkadot\")\n}\n\nexport const isAccountLedgerPolkadotGeneric = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: undefined } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !account.genesisHash\n}\n\nexport const isAccountLedgerPolkadotLegacy = (\n account: Account | null | undefined\n): account is AccountLedgerPolkadot & { genesisHash: `0x${string}` } => {\n return isAccountOfType(account, \"ledger-polkadot\") && !!account.genesisHash\n}\n\ntype AccountBitcoin = Extract<Account, { type: (typeof ACCOUNT_TYPES_BITCOIN)[number] }>\nexport const isAccountBitcoin = (\n account: Account | null | undefined\n): account is AccountBitcoin => {\n return !!account && isBitcoinAddress(account.address)\n}\n\nexport const getAccountGenesisHash = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"genesisHash\" in account ? account.genesisHash || undefined : undefined\n}\n\nexport const getAccountSignetUrl = (account: Account | null | undefined) => {\n return isAccountOfType(account, \"signet\") ? account.url : undefined\n}\n\nexport const getAccountPlatform = (account: Account | null | undefined) => {\n if (!account) return undefined\n return \"curve\" in account\n ? getAccountPlatformFromCurve(account.curve)\n : getAccountPlatformFromAddress(account.address)\n}\n","import { pbkdf2 } from \"@talismn/crypto\"\n\n// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption\nconst deriveKey = async (password: string, salt: Uint8Array): Promise<CryptoKey> =>\n // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256\n await crypto.subtle.importKey(\n \"raw\",\n await pbkdf2(\n \"SHA-256\",\n new TextEncoder().encode(password),\n salt,\n 100_000, // 100,000 iterations\n 32 // 32 bytes (32 * 8 == 256 bits)\n ),\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"encrypt\", \"decrypt\"]\n )\n\nexport const encryptData = async (data: Uint8Array, password: string): Promise<string> => {\n try {\n const salt = crypto.getRandomValues(new Uint8Array(16)) // 16 bytes of salt\n const iv = crypto.getRandomValues(new Uint8Array(12)) // 12-byte IV for AES-GCM\n const key = await deriveKey(password, salt)\n\n // encrypt\n const encryptedSeed = await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv },\n key,\n data as Uint8Array<ArrayBuffer>\n )\n\n // Combine salt, IV, and encrypted seed\n const combined = new Uint8Array(salt.length + iv.length + encryptedSeed.byteLength)\n combined.set(salt, 0)\n combined.set(iv, salt.length)\n combined.set(new Uint8Array(encryptedSeed), salt.length + iv.length)\n\n // Base64 encode the combined data\n return btoa(String.fromCharCode(...combined))\n } catch (cause) {\n throw new Error(\"Failed to encrypt data\", { cause })\n }\n}\n\nexport const decryptData = async (encryptedData: string, password: string): Promise<Uint8Array> => {\n try {\n // Decode Base64 and parse the combined data\n const combined = Uint8Array.from(atob(encryptedData), (c) => c.charCodeAt(0))\n\n // Extract salt, IV, and encrypted seed\n const salt = combined.slice(0, 16) // First 16 bytes\n const iv = combined.slice(16, 28) // Next 12 bytes\n const encryptedSeed = combined.slice(28) // Remaining bytes\n\n const key = await deriveKey(password, salt)\n\n // Decrypt the seed\n const decryptedSeed = await crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, key, encryptedSeed)\n\n return new Uint8Array(decryptedSeed)\n } catch (cause) {\n throw new Error(\"Failed to decrypt data\", { cause })\n }\n}\n\nexport const changeEncryptedDataPassword = async (\n encryptedData: string,\n oldPassword: string,\n newPassword: string\n) => {\n try {\n const decrypted = await decryptData(encryptedData, oldPassword)\n return await encryptData(decrypted, newPassword)\n } catch (cause) {\n throw new Error(\"Failed to change password on encrypted data\", { cause })\n }\n}\n","// we dont want to reference @talismn/util in the keyring, so we copy this here\ntype HexString = `0x${string}`\n\nconst REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/\n\nexport const isHexString = (value: unknown): value is HexString => {\n return typeof value === \"string\" && REGEX_HEX_STRING.test(value)\n}\n","import {\n addressEncodingFromCurve,\n addressFromPublicKey,\n base58,\n blake3,\n deriveKeypair,\n entropyToMnemonic,\n entropyToSeed,\n getPublicKeyFromSecret,\n isAddressEqual,\n isValidMnemonic,\n type KeypairCurve,\n mnemonicToEntropy,\n normalizeAddress,\n utf8,\n} from \"@talismn/crypto\"\n\nimport type { Account, Mnemonic } from \"../types\"\nimport { isAccountExternal } from \"../types\"\nimport type {\n AddAccountDeriveOptions,\n AddAccountExternalOptions,\n AddAccountKeypairOptions,\n AddMnemonicOptions,\n UpdateAccountOptions,\n UpdateMnemonicOptions,\n} from \"../types/keyring\"\nimport { changeEncryptedDataPassword, decryptData, encryptData } from \"./encryption\"\nimport type { AccountStorage, MnemonicStorage } from \"./types\"\nimport { isHexString } from \"./utils\"\n\nexport type KeyringStorage = {\n passwordCheck: string | null // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: MnemonicStorage[]\n accounts: AccountStorage[]\n}\n\nexport class Keyring {\n #data: KeyringStorage\n\n protected constructor(data: KeyringStorage) {\n this.#data = structuredClone(data)\n }\n\n public static create(): Keyring {\n return new Keyring({\n passwordCheck: null, // well-known data encrypted using the password, used to ensure all secrets of the keyring are encrypted with the same password\n mnemonics: [],\n accounts: [],\n })\n }\n\n public static load(data: KeyringStorage): Keyring {\n if (!data.accounts || !data.mnemonics) throw new Error(\"Invalid data\")\n\n // automatic upgrade : set default values for newly introduced properties\n for (const account of data.accounts) {\n // @ts-expect-error\n if (account.type === \"ledger-polkadot\" && !account.curve) account.curve = \"ed25519\"\n }\n\n return new Keyring(data)\n }\n\n private async checkPassword(password: string, reset = false) {\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const passwordHash = oneWayHash(password)\n const PASSWORD_CHECK_PHRASE = \"PASSWORD_CHECK_PHRASE\"\n\n // run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets\n if (!this.#data.passwordCheck || reset) {\n const bytes = utf8.decode(PASSWORD_CHECK_PHRASE)\n this.#data.passwordCheck = await encryptData(bytes, passwordHash)\n } else {\n try {\n const bytes = await decryptData(this.#data.passwordCheck, passwordHash)\n const text = utf8.encode(bytes)\n if (text !== PASSWORD_CHECK_PHRASE) throw new Error(\"Invalid password\")\n } catch {\n throw new Error(\"Invalid password\")\n }\n }\n }\n\n /** Returns true if a password has been set on this keyring. */\n public hasPassword(): boolean {\n return this.#data.passwordCheck !== null\n }\n\n /**\n * Verify a password against the keyring's passwordCheck blob.\n * Returns true on success, false on wrong password.\n * Throws if no password has been set (caller should check hasPassword() first).\n */\n public async verifyPassword(password: string): Promise<boolean> {\n if (!this.#data.passwordCheck) {\n throw new Error(\"No password set — call hasPassword() before verifyPassword()\")\n }\n try {\n await this.checkPassword(password)\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Initialize the password on a fresh keyring that has no password set.\n * Throws if a password is already set (use changePassword flow instead).\n */\n public async initializePassword(password: string): Promise<void> {\n if (this.#data.passwordCheck !== null) {\n throw new Error(\"Password already set — cannot re-initialize\")\n }\n await this.checkPassword(password, true)\n }\n\n public toJson() {\n return structuredClone(this.#data)\n }\n\n public async export(password: string, jsonPassword: string): Promise<KeyringStorage> {\n const keyring = new Keyring(structuredClone(this.#data))\n\n for (const mnemonic of keyring.#data.mnemonics)\n mnemonic.entropy = await changeEncryptedDataPassword(mnemonic.entropy, password, jsonPassword)\n\n for (const account of keyring.#data.accounts)\n if (account.type === \"keypair\")\n account.secretKey = await changeEncryptedDataPassword(\n account.secretKey,\n password,\n jsonPassword\n )\n\n // reset password check\n await keyring.checkPassword(jsonPassword, true)\n\n return keyring.toJson()\n }\n\n public getMnemonics(): Mnemonic[] {\n return this.#data.mnemonics.map(mnemonicFromStorage)\n }\n\n public async addMnemonic(\n { name, mnemonic, confirmed }: AddMnemonicOptions,\n password: string\n ): Promise<Mnemonic> {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n if (typeof mnemonic !== \"string\") throw new Error(\"mnemonic is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n if (!isValidMnemonic(mnemonic)) throw new Error(\"Invalid mnemonic\")\n\n await this.checkPassword(password)\n\n const entropy = mnemonicToEntropy(mnemonic)\n\n // id is a hash of the entropy, helps us prevent having duplicates and allows automatic remapping of accounts/mnemonics if mnemonics are deleted then re-added\n const id = oneWayHash(entropy)\n\n if (this.#data.mnemonics.find((s) => s.id === id)) throw new Error(\"Mnemonic already exists\")\n\n const storage: MnemonicStorage = {\n id,\n name,\n entropy: await encryptData(entropy, password),\n confirmed,\n createdAt: Date.now(),\n }\n\n this.#data.mnemonics.push(storage)\n\n return mnemonicFromStorage(storage)\n }\n\n public getMnemonic(id: string): Mnemonic | null {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n return mnemonic ? mnemonicFromStorage(mnemonic) : null\n }\n\n public updateMnemonic(id: string, { name, confirmed }: UpdateMnemonicOptions) {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n if (name !== undefined) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name must be a string\")\n mnemonic.name = name\n }\n if (confirmed !== undefined) {\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed must be a boolean\")\n mnemonic.confirmed = confirmed\n }\n return mnemonicFromStorage(mnemonic)\n }\n\n public removeMnemonic(id: string) {\n const index = this.#data.mnemonics.findIndex((mnemonic) => mnemonic.id === id)\n if (index === -1) throw new Error(\"Mnemonic not found\")\n this.#data.mnemonics.splice(index, 1)\n }\n\n async getMnemonicText(id: string, password: string): Promise<string> {\n const mnemonic = this.#data.mnemonics.find((s) => s.id === id)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n\n return entropyToMnemonic(entropy)\n }\n\n public getExistingMnemonicId(mnemonic: string): string | null {\n const entropy = mnemonicToEntropy(mnemonic)\n const mnemonicId = oneWayHash(entropy)\n return this.#data.mnemonics.some((s) => s.id === mnemonicId) ? mnemonicId : null\n }\n\n public getAccounts(): Account[] {\n return this.#data.accounts.map(accountFromStorage)\n }\n\n public getAccount(address: string): Account | null {\n const account = this.#data.accounts.find((s) => isAddressEqual(s.address, address))\n return account ? accountFromStorage(account) : null\n }\n\n public updateAccount(address: string, { name, isPortfolio, genesisHash }: UpdateAccountOptions) {\n const account = this.#data.accounts.find((s) => s.address === address)\n if (!account) throw new Error(\"Account not found\")\n\n if (name) {\n if (typeof name !== \"string\" || !name) throw new Error(\"name is required\")\n account.name = name\n }\n if (account.type === \"watch-only\" && isPortfolio !== undefined) {\n if (typeof isPortfolio !== \"boolean\") throw new Error(\"isPortfolio must be a boolean\")\n account.isPortfolio = isPortfolio\n }\n // allow updating genesisHash only for contacts\n if (account.type === \"contact\") {\n if (genesisHash) {\n if (!isHexString(genesisHash)) throw new Error(\"genesisHash must be a hex string\")\n account.genesisHash = genesisHash\n } else delete account.genesisHash\n }\n\n return accountFromStorage(account)\n }\n\n public removeAccount(address: string) {\n const index = this.#data.accounts.findIndex((s) => isAddressEqual(s.address, address))\n if (index === -1) throw new Error(\"Account not found\")\n this.#data.accounts.splice(index, 1)\n }\n\n public addAccountExternal(options: AddAccountExternalOptions): Account {\n const address = normalizeAddress(options.address) // breaks if invalid address\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n ...options,\n address,\n createdAt: Date.now(),\n }\n\n if (!isAccountExternal(account)) throw new Error(\"Invalid account type\")\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n /**\n * Needs to be called before deriving an account from a mnemonic.\n *\n * This will ensure that it is present (or add it if possible) in the keyring before actually creating the account.\n *\n * @param options\n * @param password\n * @returns the id of the mnemonic\n */\n private async ensureMnemonic(options: AddAccountDeriveOptions, password: string) {\n await this.checkPassword(password)\n\n switch (options.type) {\n case \"new-mnemonic\": {\n const { mnemonic, mnemonicName: name, confirmed } = options\n\n if (typeof name !== \"string\" || !name) throw new Error(\"mnemonicName is required\")\n if (typeof confirmed !== \"boolean\") throw new Error(\"confirmed is required\")\n\n const mnemonicId = this.getExistingMnemonicId(mnemonic)\n if (mnemonicId) return mnemonicId\n\n const { id } = await this.addMnemonic(\n {\n name,\n mnemonic,\n confirmed,\n },\n password\n )\n\n return id\n }\n case \"existing-mnemonic\": {\n if (typeof options.mnemonicId !== \"string\" || !options.mnemonicId)\n throw new Error(\"mnemonicId must be a string\")\n\n return options.mnemonicId\n }\n }\n }\n\n public async addAccountDerive(\n options: AddAccountDeriveOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const { curve, derivationPath, name } = options\n\n const mnemonicId = await this.ensureMnemonic(options, password)\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n if (this.getAccount(pair.address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(pair.address),\n secretKey: await encryptData(pair.secretKey, password),\n mnemonicId,\n derivationPath,\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public async addAccountKeypair(\n { curve, name, secretKey }: AddAccountKeypairOptions,\n password: string\n ): Promise<Account> {\n await this.checkPassword(password)\n\n const publicKey = getPublicKeyFromSecret(secretKey, curve)\n const encoding = addressEncodingFromCurve(curve)\n const address = addressFromPublicKey(publicKey, encoding)\n\n if (this.getAccount(address)) throw new Error(\"Account already exists\")\n\n const account: AccountStorage = {\n type: \"keypair\",\n curve,\n name,\n address: normalizeAddress(address),\n secretKey: await encryptData(secretKey, password),\n createdAt: Date.now(),\n }\n\n this.#data.accounts.push(account)\n\n return accountFromStorage(account)\n }\n\n public getAccountSecretKey(address: string, password: string): Promise<Uint8Array> {\n if (typeof address !== \"string\" || !address) throw new Error(\"address is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const account = this.#data.accounts.find((a) => a.address === normalizeAddress(address))\n if (!account) throw new Error(\"Account not found\")\n if (account.type !== \"keypair\") throw new Error(\"Secret key unavailable\")\n\n return decryptData(account.secretKey, password)\n }\n\n public async getDerivedAddress(\n mnemonicId: string,\n derivationPath: string,\n curve: KeypairCurve,\n password: string\n ): Promise<string> {\n if (typeof mnemonicId !== \"string\" || !mnemonicId) throw new Error(\"mnemonicId is required\")\n if (typeof password !== \"string\" || !password) throw new Error(\"password is required\")\n\n const mnemonic = this.#data.mnemonics.find((s) => s.id === mnemonicId)\n if (!mnemonic) throw new Error(\"Mnemonic not found\")\n\n const entropy = await decryptData(mnemonic.entropy, password)\n const seed = await entropyToSeed(entropy, curve)\n const pair = deriveKeypair(seed, derivationPath, curve)\n\n return pair.address\n }\n}\n\nconst oneWayHash = (bytes: Uint8Array | string) => {\n if (typeof bytes === \"string\") bytes = utf8.decode(bytes)\n\n // cryptographically secure one way hash\n // outputs 44 characters without special characters\n return base58.encode(blake3(bytes))\n}\n\nconst mnemonicFromStorage = (data: MnemonicStorage): Mnemonic => {\n const copy = structuredClone(data) as Mnemonic\n if (\"entropy\" in copy) delete copy.entropy\n return Object.freeze(copy)\n}\n\nconst accountFromStorage = (data: AccountStorage): Account => {\n const copy = structuredClone(data) as Account\n if (\"secretKey\" in copy) delete copy.secretKey\n return Object.freeze(copy)\n}\n"],"mappings":";;AAaA,MAAa,mBACX,SACA,SACmC;CACnC,OAAO,SAAS,SAAS;AAC3B;AAEA,MAAa,oBACX,SACA,UAC4C;CAC5C,OAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAuCA,MAAa,qBACX,YACsE;C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
+ "version": "2.0.2",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -21,11 +21,11 @@
21
21
  "node": ">=20"
22
22
  },
23
23
  "dependencies": {
24
- "@talismn/crypto": "1.0.0"
24
+ "@talismn/crypto": "1.1.0"
25
25
  },
26
26
  "devDependencies": {
27
- "typescript": "^7.0.2",
28
- "@talismn/tsconfig": "0.0.4"
27
+ "@talismn/tsconfig": "0.0.4",
28
+ "typescript": "^7.0.2"
29
29
  },
30
30
  "types": "./dist/index.d.ts",
31
31
  "exports": {