@talismn/keyring 1.0.8 → 1.0.9

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.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/keyring/Keyring.ts","../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts"],"sourcesContent":["export * from \"./keyring\"\nexport * from \"./types\"\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 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","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({ name: \"AES-GCM\", iv }, key, data)\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\nexport const 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAeO;;;ACfP,oBAOO;AAMA,IAAM,kBAAkB,CAC7B,SACA,SACmC;AACnC,SAAO,SAAS,SAAS;AAC3B;AAEO,IAAM,mBAAmB,CAC9B,SACA,UAC4C;AAC5C,SAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,IAAM,sBAAsB;AAAA,E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AAe,YAAY,CAAC,WAAY,OAAM,IAAI,MAAM,wBAAwB;AAC3F,QAAI,OAAO,aAAa,YAAY,CAAC,SAAU,OAAM,IAAI,MAAM,sBAAsB;AAErF,UAAM,WAAW,KAAK,MAAM,UAAU,KAAK,CAAC,MAAM,EAAE,OAAO,UAAU;AACrE,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM,oBAAoB;AAEnD,UAAM,UAAU,MAAM,YAAY,SAAS,SAAS,QAAQ;AAC5D,UAAM,OAAO,UAAM,8BAAc,SAAS,KAAK;AAC/C,UAAM,WAAO,8BAAc,MAAM,gBAAgB,KAAK;AAEtD,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAM,aAAa,CAAC,UAA+B;AACjD,MAAI,OAAO,UAAU,SAAU,SAAQ,oBAAK,OAAO,KAAK;AAIxD,SAAO,sBAAO,WAAO,uBAAO,KAAK,CAAC;AACpC;AAEA,IAAM,sBAAsB,CAAC,SAAoC;AAC/D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,aAAa,KAAM,QAAO,KAAK;AACnC,SAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,IAAM,qBAAqB,CAAC,SAAkC;AAC5D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,eAAe,KAAM,QAAO,KAAK;AACrC,SAAO,OAAO,OAAO,IAAI;AAC3B;","names":["import_crypto","import_crypto"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/keyring/Keyring.ts","../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts"],"sourcesContent":["export * from \"./keyring\"\nexport * from \"./types\"\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 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","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({ name: \"AES-GCM\", iv }, key, data)\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAeO;;;ACfP,oBAOO;AAMA,IAAM,kBAAkB,CAC7B,SACA,SACmC;AACnC,SAAO,SAAS,SAAS;AAC3B;AAEO,IAAM,mBAAmB,CAC9B,SACA,UAC4C;AAC5C,SAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,yBAAyB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAuCO,IAAM,oBAAoB,CAC/B,YACsE;AACtE,SAAO,iBAAiB,SAAS,sBAAkD;AACrF;AAEO,IAAM,iBAAiB,CAC5B,YACmE;AACnE,SAAO,iBAAiB,SAAS,mBAA+C;AAClF;AAEO,IAAM,qBAAqB,CAAC,YAA4D;AAC7F,SAAO,eAAe,OAAO,KAAM,gBAAgB,SAAS,YAAY,KAAK,QAAQ;AACvF;AAEO,IAAM,sBAAsB,CAAC,QAAiB,IAAI,SAAS;AAQ3D,IAAM,2BAA2B,CACtC,YACsC;AACtC,SAAO,CAAC,CA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AAO,sBAAO,WAAO,uBAAO,KAAK,CAAC;AACpC;AAEA,IAAM,sBAAsB,CAAC,SAAoC;AAC/D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,aAAa,KAAM,QAAO,KAAK;AACnC,SAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,IAAM,qBAAqB,CAAC,SAAkC;AAC5D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,eAAe,KAAM,QAAO,KAAK;AACrC,SAAO,OAAO,OAAO,IAAI;AAC3B;","names":["import_crypto","import_crypto"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/keyring/Keyring.ts","../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts"],"sourcesContent":["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 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","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({ name: \"AES-GCM\", iv }, key, data)\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\nexport const 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"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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,QAAS,OAAM,IAAI,MAAM,mBAAmB;AACjD,QAAI,QAAQ,SAAS,UAAW,OAAM,IAAI,MAAM,wBAAwB;AAExE,WAAO,YAAY,QAAQ,WAAW,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAa,kBACX,YACA,gBACA,OACA,UACiB;AACjB,QAAI,OAAO,eAAe,YAAY,CAAC,WAAY,OAAM,IAAI,MAAM,wBAAwB;AAC3F,QAAI,OAAO,aAAa,YAAY,CAAC,SAAU,OAAM,IAAI,MAAM,sBAAsB;AAErF,UAAM,WAAW,KAAK,MAAM,UAAU,KAAK,CAAC,MAAM,EAAE,OAAO,UAAU;AACrE,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM,oBAAoB;AAEnD,UAAM,UAAU,MAAM,YAAY,SAAS,SAAS,QAAQ;AAC5D,UAAM,OAAO,MAAM,cAAc,SAAS,KAAK;AAC/C,UAAM,OAAO,cAAc,MAAM,gBAAgB,KAAK;AAEtD,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAM,aAAa,CAAC,UAA+B;AACjD,MAAI,OAAO,UAAU,SAAU,SAAQ,KAAK,OAAO,KAAK;AAIxD,SAAO,OAAO,OAAO,OAAO,KAAK,CAAC;AACpC;AAEA,IAAM,sBAAsB,CAAC,SAAoC;AAC/D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,aAAa,KAAM,QAAO,KAAK;AACnC,SAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,IAAM,qBAAqB,CAAC,SAAkC;AAC5D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,eAAe,KAAM,QAAO,KAAK;AACrC,SAAO,OAAO,OAAO,IAAI;AAC3B;","names":[]}
1
+ {"version":3,"sources":["../src/keyring/Keyring.ts","../src/types/utils.ts","../src/keyring/encryption.ts","../src/keyring/utils.ts"],"sourcesContent":["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 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","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({ name: \"AES-GCM\", iv }, key, data)\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"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,IAAM,kBAAkB,CAC7B,SACA,SACmC;AACnC,SAAO,SAAS,SAAS;AAC3B;AAEO,IAAM,mBAAmB,CAC9B,SACA,UAC4C;AAC5C,SAAO,CAAC,CAAC,WAAW,MAAM,SAAS,QAAQ,IAAI;AACjD;AAEA,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,yBAAyB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAuCO,IAAM,oBAAoB,CAC/B,YACsE;AACtE,SAAO,iBAAiB,SAAS,sBAAkD;AACrF;AAEO,IAAM,iBAAiB,CAC5B,YACmE;AACnE,SAAO,iBAAiB,SAAS,mBAA+C;AAClF;AAEO,IAAM,qBAA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/C,UAAM,OAAO,cAAc,MAAM,gBAAgB,KAAK;AAEtD,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAM,aAAa,CAAC,UAA+B;AACjD,MAAI,OAAO,UAAU,SAAU,SAAQ,KAAK,OAAO,KAAK;AAIxD,SAAO,OAAO,OAAO,OAAO,KAAK,CAAC;AACpC;AAEA,IAAM,sBAAsB,CAAC,SAAoC;AAC/D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,aAAa,KAAM,QAAO,KAAK;AACnC,SAAO,OAAO,OAAO,IAAI;AAC3B;AAEA,IAAM,qBAAqB,CAAC,SAAkC;AAC5D,QAAM,OAAO,gBAAgB,IAAI;AACjC,MAAI,eAAe,KAAM,QAAO,KAAK;AACrC,SAAO,OAAO,OAAO,IAAI;AAC3B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/keyring",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -21,7 +21,7 @@
21
21
  "node": ">=20"
22
22
  },
23
23
  "dependencies": {
24
- "@talismn/crypto": "0.3.2"
24
+ "@talismn/crypto": "0.3.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typescript": "^5.6.3",