@talismn/keyring 1.0.1 → 1.0.3
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/declarations/src/keyring/types.d.ts +2 -2
- package/dist/declarations/src/types/account.d.ts +5 -2
- package/dist/declarations/src/types/keyring.d.ts +2 -2
- package/dist/declarations/src/types/utils.d.ts +10 -5
- package/dist/talismn-keyring.cjs.dev.js +16 -10
- package/dist/talismn-keyring.cjs.prod.js +16 -10
- package/dist/talismn-keyring.esm.js +17 -12
- package/package.json +6 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountContact, AccountKeypair, AccountLedgerEthereum, AccountLedgerPolkadot, AccountPolkadotVault, AccountSignet, AccountWatchOnly } from "../types/account";
|
|
1
|
+
import type { AccountContact, AccountKeypair, AccountLedgerEthereum, AccountLedgerPolkadot, AccountLedgerSolana, AccountPolkadotVault, AccountSignet, AccountWatchOnly } from "../types/account";
|
|
2
2
|
import type { Mnemonic } from "../types/mnemonic";
|
|
3
3
|
export type MnemonicStorage = Mnemonic & {
|
|
4
4
|
entropy: string;
|
|
@@ -6,4 +6,4 @@ export type MnemonicStorage = Mnemonic & {
|
|
|
6
6
|
export type AccountKeypairStorage = AccountKeypair & {
|
|
7
7
|
secretKey: string;
|
|
8
8
|
};
|
|
9
|
-
export type AccountStorage = AccountKeypairStorage | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountPolkadotVault | AccountSignet;
|
|
9
|
+
export type AccountStorage = AccountKeypairStorage | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { KeypairCurve } from "@talismn/crypto";
|
|
2
2
|
export type LedgerPolkadotCurve = "ed25519" | "ethereum";
|
|
3
|
-
export type AccountPlatform = "ethereum" | "polkadot" | "solana" | "bitcoin";
|
|
4
3
|
export type AccountBase = {
|
|
5
4
|
address: string;
|
|
6
5
|
name: string;
|
|
@@ -32,6 +31,10 @@ export type AccountLedgerEthereum = AccountBase & {
|
|
|
32
31
|
type: "ledger-ethereum";
|
|
33
32
|
derivationPath: string;
|
|
34
33
|
};
|
|
34
|
+
export type AccountLedgerSolana = AccountBase & {
|
|
35
|
+
type: "ledger-solana";
|
|
36
|
+
derivationPath: string;
|
|
37
|
+
};
|
|
35
38
|
export type AccountPolkadotVault = AccountBase & {
|
|
36
39
|
type: "polkadot-vault";
|
|
37
40
|
genesisHash: `0x${string}` | null;
|
|
@@ -41,5 +44,5 @@ export type AccountSignet = AccountBase & {
|
|
|
41
44
|
genesisHash: `0x${string}`;
|
|
42
45
|
url: string;
|
|
43
46
|
};
|
|
44
|
-
export type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountPolkadotVault | AccountSignet;
|
|
47
|
+
export type Account = AccountKeypair | AccountContact | AccountWatchOnly | AccountLedgerEthereum | AccountLedgerPolkadot | AccountLedgerSolana | AccountPolkadotVault | AccountSignet;
|
|
45
48
|
export type AccountType = Account["type"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { KeypairCurve } from "@talismn/crypto";
|
|
2
|
-
import type { AccountBase, AccountContact, AccountLedgerEthereum, AccountLedgerPolkadot, AccountPolkadotVault, AccountSignet, AccountWatchOnly } from "./account";
|
|
2
|
+
import type { AccountBase, AccountContact, AccountLedgerEthereum, AccountLedgerPolkadot, AccountLedgerSolana, AccountPolkadotVault, AccountSignet, AccountWatchOnly } from "./account";
|
|
3
3
|
export type AddMnemonicOptions = {
|
|
4
4
|
mnemonic: string;
|
|
5
5
|
name: string;
|
|
@@ -29,7 +29,7 @@ export type AddAccountKeypairOptions = Omit<AccountBase, "createdAt" | "address"
|
|
|
29
29
|
curve: KeypairCurve;
|
|
30
30
|
secretKey: Uint8Array;
|
|
31
31
|
};
|
|
32
|
-
export type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
|
|
32
|
+
export type AddAccountExternalOptions = Omit<AccountContact, "createdAt"> | Omit<AccountWatchOnly, "createdAt"> | Omit<AccountLedgerEthereum, "createdAt"> | Omit<AccountLedgerPolkadot, "createdAt"> | Omit<AccountLedgerSolana, "createdAt"> | Omit<AccountPolkadotVault, "createdAt"> | Omit<AccountSignet, "createdAt">;
|
|
33
33
|
export type UpdateAccountOptions = {
|
|
34
34
|
name?: string;
|
|
35
35
|
isPortfolio?: boolean;
|
|
@@ -4,17 +4,18 @@ export type AccountOfType<Type extends AccountType> = Extract<Account, {
|
|
|
4
4
|
}>;
|
|
5
5
|
export declare const isAccountOfType: <Type extends AccountType>(account: Account | null | undefined, type: Type) => account is AccountOfType<Type>;
|
|
6
6
|
export declare const isAccountInTypes: <Types extends AccountType[]>(account: Account | null | undefined, types: Types) => account is AccountOfType<Types[number]>;
|
|
7
|
-
declare const ACCOUNT_TYPES_OWNED: readonly ["keypair", "ledger-ethereum", "ledger-polkadot", "polkadot-vault"];
|
|
8
|
-
declare const ACCOUNT_TYPES_EXTERNAL: readonly ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
7
|
+
declare const ACCOUNT_TYPES_OWNED: readonly ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
|
|
8
|
+
declare const ACCOUNT_TYPES_EXTERNAL: readonly ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
|
|
9
9
|
declare const ACCOUNT_TYPES_ADDRESS_ETHEREUM: readonly ["contact", "watch-only", "keypair", "ledger-ethereum", "ledger-polkadot"];
|
|
10
10
|
declare const ACCOUNT_TYPES_PLATFORM_ETHEREUM: readonly ["contact", "watch-only", "keypair", "ledger-ethereum"];
|
|
11
|
-
declare const ACCOUNT_TYPES_ADDRESS_SS58: readonly ["contact", "watch-only", "keypair", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
12
11
|
declare const ACCOUNT_TYPES_PLATFORM_POLKADOT: readonly ["contact", "watch-only", "keypair", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
12
|
+
declare const ACCOUNT_TYPES_ADDRESS_SS58: readonly ["contact", "watch-only", "keypair", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
13
|
+
declare const ACCOUNT_TYPES_PLATFORM_SOLANA: readonly ["contact", "watch-only", "keypair", "ledger-solana"];
|
|
13
14
|
declare const ACCOUNT_TYPES_BITCOIN: readonly ["contact", "watch-only"];
|
|
14
15
|
export declare const isAccountExternal: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_EXTERNAL)[number]>;
|
|
15
16
|
export declare const isAccountOwned: (account: Account | null | undefined) => account is AccountOfType<(typeof ACCOUNT_TYPES_OWNED)[number]>;
|
|
16
17
|
export declare const isAccountPortfolio: (account: Account | null | undefined) => account is Account;
|
|
17
|
-
export declare const isAccountNotContact: (acc: Account) => acc is import("./account").AccountKeypair | import("./account").AccountWatchOnly | AccountLedgerPolkadot | import("./account").AccountLedgerEthereum | import("./account").AccountPolkadotVault | import("./account").AccountSignet;
|
|
18
|
+
export declare const isAccountNotContact: (acc: Account) => acc is import("./account").AccountKeypair | import("./account").AccountWatchOnly | AccountLedgerPolkadot | import("./account").AccountLedgerEthereum | import("./account").AccountLedgerSolana | import("./account").AccountPolkadotVault | import("./account").AccountSignet;
|
|
18
19
|
type AccountAddressEthereum = Extract<Account, {
|
|
19
20
|
type: (typeof ACCOUNT_TYPES_ADDRESS_ETHEREUM)[number];
|
|
20
21
|
}> & {
|
|
@@ -27,6 +28,10 @@ type AccountPlatformEthereum = Extract<Account, {
|
|
|
27
28
|
address: `0x${string}`;
|
|
28
29
|
};
|
|
29
30
|
export declare const isAccountPlatformEthereum: (account: Account | null | undefined) => account is AccountPlatformEthereum;
|
|
31
|
+
type AccountPlatformSolana = Extract<Account, {
|
|
32
|
+
type: (typeof ACCOUNT_TYPES_PLATFORM_SOLANA)[number];
|
|
33
|
+
}>;
|
|
34
|
+
export declare const isAccountPlatformSolana: (account: Account | null | undefined) => account is AccountPlatformSolana;
|
|
30
35
|
type AccountPlatformPolkadot = Extract<Account, {
|
|
31
36
|
type: (typeof ACCOUNT_TYPES_PLATFORM_POLKADOT)[number];
|
|
32
37
|
}>;
|
|
@@ -50,5 +55,5 @@ type AccountBitcoin = Extract<Account, {
|
|
|
50
55
|
export declare const isAccountBitcoin: (account: Account | null | undefined) => account is AccountBitcoin;
|
|
51
56
|
export declare const getAccountGenesisHash: (account: Account | null | undefined) => `0x${string}` | undefined;
|
|
52
57
|
export declare const getAccountSignetUrl: (account: Account | null | undefined) => string | undefined;
|
|
53
|
-
export declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").
|
|
58
|
+
export declare const getAccountPlatform: (account: Account | null | undefined) => import("@talismn/crypto").AccountPlatform | undefined;
|
|
54
59
|
export {};
|
|
@@ -8,8 +8,8 @@ const isAccountOfType = (account, type) => {
|
|
|
8
8
|
const isAccountInTypes = (account, types) => {
|
|
9
9
|
return !!account && types.includes(account.type);
|
|
10
10
|
};
|
|
11
|
-
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "polkadot-vault"];
|
|
12
|
-
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
11
|
+
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
|
|
12
|
+
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
|
|
13
13
|
const isAccountExternal = account => {
|
|
14
14
|
return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL);
|
|
15
15
|
};
|
|
@@ -26,6 +26,9 @@ const isAccountAddressEthereum = account => {
|
|
|
26
26
|
const isAccountPlatformEthereum = account => {
|
|
27
27
|
return !!account && account.type !== "ledger-polkadot" && crypto$1.isEthereumAddress(account.address);
|
|
28
28
|
};
|
|
29
|
+
const isAccountPlatformSolana = account => {
|
|
30
|
+
return !!account && crypto$1.isSolanaAddress(account.address);
|
|
31
|
+
};
|
|
29
32
|
const isAccountPlatformPolkadot = account => {
|
|
30
33
|
return !!account && account.type !== "ledger-ethereum" && (isAccountAddressEthereum(account) || isAccountAddressSs58(account));
|
|
31
34
|
};
|
|
@@ -53,7 +56,7 @@ const getAccountSignetUrl = account => {
|
|
|
53
56
|
};
|
|
54
57
|
const getAccountPlatform = account => {
|
|
55
58
|
if (!account) return undefined;
|
|
56
|
-
return "curve" in account ? crypto$1.
|
|
59
|
+
return "curve" in account ? crypto$1.getAccountPlatformFromCurve(account.curve) : crypto$1.getAccountPlatformFromAddress(account.address);
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
|
|
@@ -165,12 +168,12 @@ class Keyring {
|
|
|
165
168
|
|
|
166
169
|
// run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets
|
|
167
170
|
if (!this.#data.passwordCheck || reset) {
|
|
168
|
-
const bytes = crypto$1.
|
|
171
|
+
const bytes = crypto$1.utf8.decode(PASSWORD_CHECK_PHRASE);
|
|
169
172
|
this.#data.passwordCheck = await encryptData(bytes, passwordHash);
|
|
170
173
|
} else {
|
|
171
174
|
try {
|
|
172
175
|
const bytes = await decryptData(this.#data.passwordCheck, passwordHash);
|
|
173
|
-
const text = crypto$1.
|
|
176
|
+
const text = crypto$1.utf8.encode(bytes);
|
|
174
177
|
if (text !== PASSWORD_CHECK_PHRASE) throw new Error("Invalid password");
|
|
175
178
|
} catch {
|
|
176
179
|
throw new Error("Invalid password");
|
|
@@ -276,9 +279,11 @@ class Keyring {
|
|
|
276
279
|
account.isPortfolio = isPortfolio;
|
|
277
280
|
}
|
|
278
281
|
// allow updating genesisHash only for contacts
|
|
279
|
-
if (account.type === "contact"
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
+
if (account.type === "contact") {
|
|
283
|
+
if (genesisHash) {
|
|
284
|
+
if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
|
|
285
|
+
account.genesisHash = genesisHash;
|
|
286
|
+
} else delete account.genesisHash;
|
|
282
287
|
}
|
|
283
288
|
return accountFromStorage(account);
|
|
284
289
|
}
|
|
@@ -408,11 +413,11 @@ class Keyring {
|
|
|
408
413
|
}
|
|
409
414
|
}
|
|
410
415
|
const oneWayHash = bytes => {
|
|
411
|
-
if (typeof bytes === "string") bytes = crypto$1.
|
|
416
|
+
if (typeof bytes === "string") bytes = crypto$1.utf8.decode(bytes);
|
|
412
417
|
|
|
413
418
|
// cryptographically secure one way hash
|
|
414
419
|
// outputs 44 characters without special characters
|
|
415
|
-
return crypto$1.
|
|
420
|
+
return crypto$1.base58.encode(crypto$1.blake3(bytes));
|
|
416
421
|
};
|
|
417
422
|
const mnemonicFromStorage = data => {
|
|
418
423
|
const copy = structuredClone(data);
|
|
@@ -442,4 +447,5 @@ exports.isAccountOfType = isAccountOfType;
|
|
|
442
447
|
exports.isAccountOwned = isAccountOwned;
|
|
443
448
|
exports.isAccountPlatformEthereum = isAccountPlatformEthereum;
|
|
444
449
|
exports.isAccountPlatformPolkadot = isAccountPlatformPolkadot;
|
|
450
|
+
exports.isAccountPlatformSolana = isAccountPlatformSolana;
|
|
445
451
|
exports.isAccountPortfolio = isAccountPortfolio;
|
|
@@ -8,8 +8,8 @@ const isAccountOfType = (account, type) => {
|
|
|
8
8
|
const isAccountInTypes = (account, types) => {
|
|
9
9
|
return !!account && types.includes(account.type);
|
|
10
10
|
};
|
|
11
|
-
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "polkadot-vault"];
|
|
12
|
-
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
11
|
+
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
|
|
12
|
+
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
|
|
13
13
|
const isAccountExternal = account => {
|
|
14
14
|
return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL);
|
|
15
15
|
};
|
|
@@ -26,6 +26,9 @@ const isAccountAddressEthereum = account => {
|
|
|
26
26
|
const isAccountPlatformEthereum = account => {
|
|
27
27
|
return !!account && account.type !== "ledger-polkadot" && crypto$1.isEthereumAddress(account.address);
|
|
28
28
|
};
|
|
29
|
+
const isAccountPlatformSolana = account => {
|
|
30
|
+
return !!account && crypto$1.isSolanaAddress(account.address);
|
|
31
|
+
};
|
|
29
32
|
const isAccountPlatformPolkadot = account => {
|
|
30
33
|
return !!account && account.type !== "ledger-ethereum" && (isAccountAddressEthereum(account) || isAccountAddressSs58(account));
|
|
31
34
|
};
|
|
@@ -53,7 +56,7 @@ const getAccountSignetUrl = account => {
|
|
|
53
56
|
};
|
|
54
57
|
const getAccountPlatform = account => {
|
|
55
58
|
if (!account) return undefined;
|
|
56
|
-
return "curve" in account ? crypto$1.
|
|
59
|
+
return "curve" in account ? crypto$1.getAccountPlatformFromCurve(account.curve) : crypto$1.getAccountPlatformFromAddress(account.address);
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
|
|
@@ -165,12 +168,12 @@ class Keyring {
|
|
|
165
168
|
|
|
166
169
|
// run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets
|
|
167
170
|
if (!this.#data.passwordCheck || reset) {
|
|
168
|
-
const bytes = crypto$1.
|
|
171
|
+
const bytes = crypto$1.utf8.decode(PASSWORD_CHECK_PHRASE);
|
|
169
172
|
this.#data.passwordCheck = await encryptData(bytes, passwordHash);
|
|
170
173
|
} else {
|
|
171
174
|
try {
|
|
172
175
|
const bytes = await decryptData(this.#data.passwordCheck, passwordHash);
|
|
173
|
-
const text = crypto$1.
|
|
176
|
+
const text = crypto$1.utf8.encode(bytes);
|
|
174
177
|
if (text !== PASSWORD_CHECK_PHRASE) throw new Error("Invalid password");
|
|
175
178
|
} catch {
|
|
176
179
|
throw new Error("Invalid password");
|
|
@@ -276,9 +279,11 @@ class Keyring {
|
|
|
276
279
|
account.isPortfolio = isPortfolio;
|
|
277
280
|
}
|
|
278
281
|
// allow updating genesisHash only for contacts
|
|
279
|
-
if (account.type === "contact"
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
+
if (account.type === "contact") {
|
|
283
|
+
if (genesisHash) {
|
|
284
|
+
if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
|
|
285
|
+
account.genesisHash = genesisHash;
|
|
286
|
+
} else delete account.genesisHash;
|
|
282
287
|
}
|
|
283
288
|
return accountFromStorage(account);
|
|
284
289
|
}
|
|
@@ -408,11 +413,11 @@ class Keyring {
|
|
|
408
413
|
}
|
|
409
414
|
}
|
|
410
415
|
const oneWayHash = bytes => {
|
|
411
|
-
if (typeof bytes === "string") bytes = crypto$1.
|
|
416
|
+
if (typeof bytes === "string") bytes = crypto$1.utf8.decode(bytes);
|
|
412
417
|
|
|
413
418
|
// cryptographically secure one way hash
|
|
414
419
|
// outputs 44 characters without special characters
|
|
415
|
-
return crypto$1.
|
|
420
|
+
return crypto$1.base58.encode(crypto$1.blake3(bytes));
|
|
416
421
|
};
|
|
417
422
|
const mnemonicFromStorage = data => {
|
|
418
423
|
const copy = structuredClone(data);
|
|
@@ -442,4 +447,5 @@ exports.isAccountOfType = isAccountOfType;
|
|
|
442
447
|
exports.isAccountOwned = isAccountOwned;
|
|
443
448
|
exports.isAccountPlatformEthereum = isAccountPlatformEthereum;
|
|
444
449
|
exports.isAccountPlatformPolkadot = isAccountPlatformPolkadot;
|
|
450
|
+
exports.isAccountPlatformSolana = isAccountPlatformSolana;
|
|
445
451
|
exports.isAccountPortfolio = isAccountPortfolio;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEthereumAddress, detectAddressEncoding, isBitcoinAddress,
|
|
1
|
+
import { isEthereumAddress, isSolanaAddress, detectAddressEncoding, isBitcoinAddress, getAccountPlatformFromCurve, getAccountPlatformFromAddress, pbkdf2, utf8, isValidMnemonic, mnemonicToEntropy, entropyToMnemonic, isAddressEqual, normalizeAddress, entropyToSeed, deriveKeypair, getPublicKeyFromSecret, addressEncodingFromCurve, addressFromPublicKey, base58, blake3 } from '@talismn/crypto';
|
|
2
2
|
|
|
3
3
|
const isAccountOfType = (account, type) => {
|
|
4
4
|
return account?.type === type;
|
|
@@ -6,8 +6,8 @@ const isAccountOfType = (account, type) => {
|
|
|
6
6
|
const isAccountInTypes = (account, types) => {
|
|
7
7
|
return !!account && types.includes(account.type);
|
|
8
8
|
};
|
|
9
|
-
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "polkadot-vault"];
|
|
10
|
-
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "polkadot-vault", "signet"];
|
|
9
|
+
const ACCOUNT_TYPES_OWNED = ["keypair", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault"];
|
|
10
|
+
const ACCOUNT_TYPES_EXTERNAL = ["contact", "watch-only", "ledger-ethereum", "ledger-polkadot", "ledger-solana", "polkadot-vault", "signet"];
|
|
11
11
|
const isAccountExternal = account => {
|
|
12
12
|
return isAccountInTypes(account, ACCOUNT_TYPES_EXTERNAL);
|
|
13
13
|
};
|
|
@@ -24,6 +24,9 @@ const isAccountAddressEthereum = account => {
|
|
|
24
24
|
const isAccountPlatformEthereum = account => {
|
|
25
25
|
return !!account && account.type !== "ledger-polkadot" && isEthereumAddress(account.address);
|
|
26
26
|
};
|
|
27
|
+
const isAccountPlatformSolana = account => {
|
|
28
|
+
return !!account && isSolanaAddress(account.address);
|
|
29
|
+
};
|
|
27
30
|
const isAccountPlatformPolkadot = account => {
|
|
28
31
|
return !!account && account.type !== "ledger-ethereum" && (isAccountAddressEthereum(account) || isAccountAddressSs58(account));
|
|
29
32
|
};
|
|
@@ -51,7 +54,7 @@ const getAccountSignetUrl = account => {
|
|
|
51
54
|
};
|
|
52
55
|
const getAccountPlatform = account => {
|
|
53
56
|
if (!account) return undefined;
|
|
54
|
-
return "curve" in account ?
|
|
57
|
+
return "curve" in account ? getAccountPlatformFromCurve(account.curve) : getAccountPlatformFromAddress(account.address);
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
// Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
|
|
@@ -163,12 +166,12 @@ class Keyring {
|
|
|
163
166
|
|
|
164
167
|
// run through same complexity as for other secrets, to make it so it s not easier to brute force passwordCheck than other secrets
|
|
165
168
|
if (!this.#data.passwordCheck || reset) {
|
|
166
|
-
const bytes =
|
|
169
|
+
const bytes = utf8.decode(PASSWORD_CHECK_PHRASE);
|
|
167
170
|
this.#data.passwordCheck = await encryptData(bytes, passwordHash);
|
|
168
171
|
} else {
|
|
169
172
|
try {
|
|
170
173
|
const bytes = await decryptData(this.#data.passwordCheck, passwordHash);
|
|
171
|
-
const text =
|
|
174
|
+
const text = utf8.encode(bytes);
|
|
172
175
|
if (text !== PASSWORD_CHECK_PHRASE) throw new Error("Invalid password");
|
|
173
176
|
} catch {
|
|
174
177
|
throw new Error("Invalid password");
|
|
@@ -274,9 +277,11 @@ class Keyring {
|
|
|
274
277
|
account.isPortfolio = isPortfolio;
|
|
275
278
|
}
|
|
276
279
|
// allow updating genesisHash only for contacts
|
|
277
|
-
if (account.type === "contact"
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
+
if (account.type === "contact") {
|
|
281
|
+
if (genesisHash) {
|
|
282
|
+
if (!isHexString(genesisHash)) throw new Error("genesisHash must be a hex string");
|
|
283
|
+
account.genesisHash = genesisHash;
|
|
284
|
+
} else delete account.genesisHash;
|
|
280
285
|
}
|
|
281
286
|
return accountFromStorage(account);
|
|
282
287
|
}
|
|
@@ -406,11 +411,11 @@ class Keyring {
|
|
|
406
411
|
}
|
|
407
412
|
}
|
|
408
413
|
const oneWayHash = bytes => {
|
|
409
|
-
if (typeof bytes === "string") bytes =
|
|
414
|
+
if (typeof bytes === "string") bytes = utf8.decode(bytes);
|
|
410
415
|
|
|
411
416
|
// cryptographically secure one way hash
|
|
412
417
|
// outputs 44 characters without special characters
|
|
413
|
-
return
|
|
418
|
+
return base58.encode(blake3(bytes));
|
|
414
419
|
};
|
|
415
420
|
const mnemonicFromStorage = data => {
|
|
416
421
|
const copy = structuredClone(data);
|
|
@@ -423,4 +428,4 @@ const accountFromStorage = data => {
|
|
|
423
428
|
return Object.freeze(copy);
|
|
424
429
|
};
|
|
425
430
|
|
|
426
|
-
export { Keyring, getAccountGenesisHash, getAccountPlatform, getAccountSignetUrl, isAccountAddressEthereum, isAccountAddressSs58, isAccountBitcoin, isAccountExternal, isAccountInTypes, isAccountLedgerPolkadot, isAccountLedgerPolkadotGeneric, isAccountLedgerPolkadotLegacy, isAccountNotContact, isAccountOfType, isAccountOwned, isAccountPlatformEthereum, isAccountPlatformPolkadot, isAccountPortfolio };
|
|
431
|
+
export { Keyring, getAccountGenesisHash, getAccountPlatform, getAccountSignetUrl, isAccountAddressEthereum, isAccountAddressSs58, isAccountBitcoin, isAccountExternal, isAccountInTypes, isAccountLedgerPolkadot, isAccountLedgerPolkadotGeneric, isAccountLedgerPolkadotLegacy, isAccountNotContact, isAccountOfType, isAccountOwned, isAccountPlatformEthereum, isAccountPlatformPolkadot, isAccountPlatformSolana, isAccountPortfolio };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/keyring",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
"main": "dist/talismn-keyring.cjs.js",
|
|
16
16
|
"module": "dist/talismn-keyring.esm.js",
|
|
17
17
|
"files": [
|
|
18
|
-
"/dist"
|
|
19
|
-
"/plugins"
|
|
18
|
+
"/dist"
|
|
20
19
|
],
|
|
21
20
|
"engines": {
|
|
22
21
|
"node": ">=18"
|
|
23
22
|
},
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@talismn/crypto": "0.1
|
|
24
|
+
"@talismn/crypto": "0.2.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/jest": "^29.5.14",
|
|
@@ -31,8 +30,8 @@
|
|
|
31
30
|
"jest-fixed-jsdom": "^0.0.9",
|
|
32
31
|
"ts-jest": "^29.2.5",
|
|
33
32
|
"typescript": "^5.6.3",
|
|
34
|
-
"@talismn/
|
|
35
|
-
"@talismn/
|
|
33
|
+
"@talismn/eslint-config": "0.0.3",
|
|
34
|
+
"@talismn/tsconfig": "0.0.2"
|
|
36
35
|
},
|
|
37
36
|
"preconstruct": {
|
|
38
37
|
"entrypoints": [
|
|
@@ -48,6 +47,6 @@
|
|
|
48
47
|
"scripts": {
|
|
49
48
|
"test": "jest",
|
|
50
49
|
"lint": "eslint src --max-warnings 0",
|
|
51
|
-
"clean": "rm -rf dist
|
|
50
|
+
"clean": "rm -rf dist .turbo node_modules"
|
|
52
51
|
}
|
|
53
52
|
}
|