@swapkit/wallet-keystore 1.5.13 → 1.6.0
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 +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +8 -8
- package/src/keystore.ts +23 -6
package/dist/index.js
CHANGED
|
@@ -8,6 +8,6 @@ use chrome, FireFox or Internet Explorer 11`)}var E=d0(),M=g5(),j=E.Buffer,S=E.k
|
|
|
8
8
|
*
|
|
9
9
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
10
10
|
* @license MIT
|
|
11
|
-
*//*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *//*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */import{generateMnemonic as g8,validateMnemonic as m8}from"@scure/bip39";import{wordlist as n6}from"@scure/bip39/wordlists/english";import{blake2bFinal as p8,blake2bInit as b8,blake2bUpdate as c8}from"blakejs";var r6=(l)=>{let g=l;if(!(g instanceof Buffer))g=Buffer.from(g,"hex");let E=b8(32);return c8(E,g),Array.from(p8(E)).map((M)=>M<16?`0${M.toString(16)}`:M.toString(16)).join("")},i6=(l,g,E,M,j)=>new Promise((S,H)=>{_5.pbkdf2(l,g,E,M,j,(U,k)=>{if(U)H(U);else S(k)})}),$4=async(l,g)=>{let E=_5.randomBytes(32),M=_5.randomBytes(16),j={c:262144,prf:"hmac-sha256",dklen:32,salt:E.toString("hex")},S="aes-128-ctr",H=await i6(Buffer.from(g),E,j.c,j.dklen,"sha256"),U=_5.createCipheriv("aes-128-ctr",H.subarray(0,16),M),k=Buffer.concat([U.update(Buffer.from(l,"utf8")),U.final()]);return{meta:"xchain-keystore",version:1,crypto:{cipher:"aes-128-ctr",cipherparams:{iv:M.toString("hex")},ciphertext:k.toString("hex"),kdf:"pbkdf2",kdfparams:j,mac:r6(Buffer.concat([H.subarray(16,32),Buffer.from(k)]))}}},j4=(l=12)=>{return g8(n6,l===12?128:256)},U4=(l)=>{return m8(l,n6)},W4=async(l,g)=>{switch(l.version){case 1:{let E=l.crypto.kdfparams,M=await i6(Buffer.from(g),Buffer.from(E.salt,"hex"),E.c,E.dklen,"sha256"),j=Buffer.from(l.crypto.ciphertext,"hex");if(r6(Buffer.concat([M.subarray(16,32),j]))!==l.crypto.mac)throw new Error("Invalid password");let H=_5.createDecipheriv(l.crypto.cipher,M.subarray(0,16),Buffer.from(l.crypto.cipherparams.iv,"hex"));return Buffer.concat([H.update(j),H.final()]).toString("utf8")}default:throw new Error("Unsupported keystore version")}};import{Chain as H5,CosmosChains as d8,EVMChains as l8,NetworkDerivationPath as h8,UTXOChains as u8,WalletOption as t6,derivationPathToString as o8,
|
|
11
|
+
*//*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *//*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */import{generateMnemonic as g8,validateMnemonic as m8}from"@scure/bip39";import{wordlist as n6}from"@scure/bip39/wordlists/english";import{blake2bFinal as p8,blake2bInit as b8,blake2bUpdate as c8}from"blakejs";var r6=(l)=>{let g=l;if(!(g instanceof Buffer))g=Buffer.from(g,"hex");let E=b8(32);return c8(E,g),Array.from(p8(E)).map((M)=>M<16?`0${M.toString(16)}`:M.toString(16)).join("")},i6=(l,g,E,M,j)=>new Promise((S,H)=>{_5.pbkdf2(l,g,E,M,j,(U,k)=>{if(U)H(U);else S(k)})}),$4=async(l,g)=>{let E=_5.randomBytes(32),M=_5.randomBytes(16),j={c:262144,prf:"hmac-sha256",dklen:32,salt:E.toString("hex")},S="aes-128-ctr",H=await i6(Buffer.from(g),E,j.c,j.dklen,"sha256"),U=_5.createCipheriv("aes-128-ctr",H.subarray(0,16),M),k=Buffer.concat([U.update(Buffer.from(l,"utf8")),U.final()]);return{meta:"xchain-keystore",version:1,crypto:{cipher:"aes-128-ctr",cipherparams:{iv:M.toString("hex")},ciphertext:k.toString("hex"),kdf:"pbkdf2",kdfparams:j,mac:r6(Buffer.concat([H.subarray(16,32),Buffer.from(k)]))}}},j4=(l=12)=>{return g8(n6,l===12?128:256)},U4=(l)=>{return m8(l,n6)},W4=async(l,g)=>{switch(l.version){case 1:{let E=l.crypto.kdfparams,M=await i6(Buffer.from(g),Buffer.from(E.salt,"hex"),E.c,E.dklen,"sha256"),j=Buffer.from(l.crypto.ciphertext,"hex");if(r6(Buffer.concat([M.subarray(16,32),j]))!==l.crypto.mac)throw new Error("Invalid password");let H=_5.createDecipheriv(l.crypto.cipher,M.subarray(0,16),Buffer.from(l.crypto.cipherparams.iv,"hex"));return Buffer.concat([H.update(j),H.final()]).toString("utf8")}default:throw new Error("Unsupported keystore version")}};import{Chain as H5,CosmosChains as d8,EVMChains as l8,NetworkDerivationPath as h8,UTXOChains as u8,WalletOption as t6,derivationPathToString as o8,filterSupportedChains as s8,getRPCUrl as e6,pickEvmApiKey as a8,setRequestClientConfig as f8,updatedLastIndex as n8}from"@swapkit/helpers";var r8=[...l8,...u8,...d8,H5.Polkadot,H5.Chainflip,H5.Solana],i8=async({apis:l,rpcUrl:g,chain:E,phrase:M,ethplorerApiKey:j,covalentApiKey:S,blockchairApiKey:H,derivationPath:U,stagenet:k})=>{switch(E){case H5.Arbitrum:case H5.Avalanche:case H5.Base:case H5.BinanceSmartChain:case H5.Ethereum:case H5.Optimism:case H5.Polygon:{let{getProvider:z,getToolboxByChain:V}=await import("@swapkit/toolbox-evm"),{HDNodeWallet:$}=await import("./chunk-7r0bsnk5.js"),T=l?.[E],N=a8({chain:E,nonEthApiKey:S,ethApiKey:j}),W=z(E,g),D=$.fromPhrase(M).connect(W),I={api:T,apiKey:N,provider:W,signer:D};return{address:D.address,walletMethods:V(E)(I)}}case H5.BitcoinCash:{let W=function({builder:I,utxos:v}){return v.forEach((x,A)=>{I.sign(A,T,void 0,65,x.witnessUtxo.value)}),I.build()},{BCHToolbox:z}=await import("@swapkit/toolbox-utxo"),V=l?.[E],$=z({rpcUrl:g,apiKey:H,apiClient:V}),T=await $.createKeysForPath({phrase:M,derivationPath:U}),N=$.getAddressFromKeys(T),D={...$,transfer:(I)=>$.transfer({...I,from:N,signTransaction:W})};return{address:N,walletMethods:D}}case H5.Bitcoin:case H5.Dash:case H5.Dogecoin:case H5.Litecoin:{let{getToolboxByChain:z}=await import("@swapkit/toolbox-utxo"),V=l?.[E],$=z(E)({rpcUrl:g,apiKey:H,apiClient:V}),T=$.createKeysForPath({phrase:M,derivationPath:U}),N=$.getAddressFromKeys(T);return{address:N,walletMethods:{...$,transfer:(W)=>$.transfer({...W,from:N,signTransaction:(D)=>D.signAllInputs(T)})}}}case H5.Cosmos:case H5.Kujira:{let{getToolboxByChain:z}=await import("@swapkit/toolbox-cosmos"),V=l?.[E],$=z(E)({server:V,stagenet:k}),T=await $.getAddressFromMnemonic(M),N=await $.getSigner(M);return{address:T,walletMethods:{...$,transfer:(D)=>$.transfer({...D,signer:N})}}}case H5.Maya:case H5.THORChain:{let{getToolboxByChain:z}=await import("@swapkit/toolbox-cosmos"),V=l?.[E],$=z(E)({server:V,stagenet:k}),T=await $.getSigner(M),N=await $.getAddressFromMnemonic(M);return{address:N,walletMethods:{...$,deposit:({assetValue:W,memo:D})=>$.deposit({assetValue:W,memo:D,from:N,signer:T}),transfer:(W)=>$.transfer({...W,from:N,signer:T}),signMessage:async(W)=>{let D=await $.createPrivateKeyFromPhrase(M);return $.signWithPrivateKey({privateKey:D,message:W})}}}}case H5.Polkadot:case H5.Chainflip:{let{Network:z,getToolboxByChain:V,createKeyring:$}=await import("@swapkit/toolbox-substrate"),T=await $(M,z[E].prefix),N=await V(E,{signer:T,providerUrl:E===H5.Polkadot?e6(H5.Polkadot):e6(H5.Chainflip)});return{address:T.address,walletMethods:N}}case H5.Solana:{let{SOLToolbox:z}=await import("@swapkit/toolbox-solana"),V=z({rpcUrl:g}),$=V.createKeysForPath({phrase:M,derivationPath:U});return{address:V.getAddressFromKeys($),walletMethods:{...V,transfer:(T)=>V.transfer({...T,fromKeypair:$})}}}default:throw new Error(`Unsupported chain ${E}`)}};function t8({addChain:l,apis:g,rpcUrls:E,config:{thorswapApiKey:M,covalentApiKey:j,ethplorerApiKey:S,blockchairApiKey:H,stagenet:U}}){return async function k(z,V,$){f8({apiKey:M});let N=s8(z,r8,t6.KEYSTORE).map(async(W)=>{let D=typeof $==="number"?$:0,I=$&&typeof $==="object"?$[W]:void 0,[v,x,A,y,p]=h8[W],c=I||n8(W===H5.Solana?[v,x,A,y]:[v,x,A,y,p],D),n=o8(c),{address:i,walletMethods:Y0}=await i8({derivationPath:n,chain:W,apis:g,rpcUrl:E[W],covalentApiKey:j,ethplorerApiKey:S,phrase:V,blockchairApiKey:H,stagenet:U});l({...Y0,chain:W,address:i,balance:[],walletType:t6.KEYSTORE})});return await Promise.all(N),!0}}var e8={connectKeystore:t8};export{U4 as validatePhrase,e8 as keystoreWallet,j4 as generatePhrase,$4 as encryptToKeyStore,W4 as decryptFromKeystore};
|
|
12
12
|
|
|
13
|
-
//# debugId=
|
|
13
|
+
//# debugId=C1C273F9C56A594964756E2164756E21
|