@swapkit/wallet-keystore 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @swapkit/wallet-keystore
2
2
 
3
+ ## 5.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#371](https://github.com/swapkit/sdk/pull/371) [`6236419`](https://github.com/swapkit/sdk/commit/623641928563f9e0141c47395a2e1febbd182093) Thanks [@ice-chillios](https://github.com/ice-chillios)! - EVM nonce derivation now reads the "pending" transaction count and serialises allocation per chainId:address behind an expiring monotonic floor, so concurrent sends from one address no longer reuse a mined-only count and silently replace each other in the mempool. Allocations are released when a send provably never reached the wire (gas or fee estimation failure, a rejected send, a signer that cannot sign), so a failed attempt no longer strands a nonce gap; transport-ambiguous failures keep the nonce reserved until the floor expires, and a floor never expires while one of its nonces is held by an in-flight send (a signature awaiting hardware or wallet confirmation cannot have its nonce re-issued). sendTransaction and state-changing contract calls both resolve through the signer's own provider when it carries one — approve + send from a single toolbox share one floor, and the transport-failure fallback broadcast and its hash lookup go through that same provider. Caller-supplied nonces are honoured on the ERC-20 transfer and approval builder paths. The native sweep builder no longer pins a nonce into the built transaction — the OP-stack L1 fee serialisation performs its own plain "pending" read for byte-length only (build-only APIs consume no allocation) — so both `transfer` and a two-step `createTransaction`/`sendTransaction` sweep allocate through the floor on the send path. The toolbox `broadcastTransaction` no longer crashes when invoked (previously an unbound method reference). (via @swapkit/toolboxes@5.3.0)
8
+ - [#380](https://github.com/swapkit/sdk/pull/380) [`9e8158f`](https://github.com/swapkit/sdk/commit/9e8158f012909b540652f0047f719482628724e1) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - TRON transaction failures now carry a diagnostic payload instead of a bare error key. (via @swapkit/toolboxes@5.3.0)
9
+ - [#381](https://github.com/swapkit/sdk/pull/381) [`3b750ec`](https://github.com/swapkit/sdk/commit/3b750ec492b40b028f50c1adcf2347c647ad3f2f) Thanks [@ochhii1337](https://github.com/ochhii1337)! - TON's native coin is now `GRAM`, so the gas asset is `TON.GRAM` instead of `TON.TON`. (via @swapkit/toolboxes@5.3.0)
10
+ - Update generated token lists. (via @swapkit/toolboxes@5.3.0)
11
+
3
12
  ## 5.1.1
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var H=((q)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(q,{get:(Z,L)=>(typeof require<"u"?require:Z)[L]}):q)(function(q){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+q+'" is not supported')});import{ACCOUNT_INDEXED_CHAINS as k,Chain as G,CosmosChains as S,EVMChains as W,filterSupportedChains as v,NetworkDerivationPath as C,UTXOChains as K,updateDerivationPath as b,WalletOption as A}from"@swapkit/helpers";import{createWallet as x,getWalletSupportedChains as p}from"@swapkit/wallet-core";import{createCipheriv as m,createDecipheriv as M,pbkdf2Sync as U,randomBytes as E}from"node:crypto";import{generateMnemonic as u,validateMnemonic as O}from"@scure/bip39";import{wordlist as T}from"@scure/bip39/wordlists/english.js";async function f(q){let{blake2b:Z}=await import("@noble/hashes/blake2.js"),L=q instanceof Buffer?q:Buffer.from(q,"hex"),$=Z(L,{dkLen:32});return Array.from($).map((Q)=>Q<16?`0${Q.toString(16)}`:Q.toString(16)).join("")}async function I(q,Z){let $=E(16),Q=E(32),Y={c:262144,dklen:32,prf:"hmac-sha256",salt:Q.toString("hex")},j=U(Z,Q,Y.c,Y.dklen,"sha256"),F=m("aes-128-ctr",j.subarray(0,16),$),J=Buffer.concat([F.update(Buffer.from(q,"utf8")),F.final()]),z=Buffer.concat([j.subarray(16,32),Buffer.from(J)]),B=await f(z);return{crypto:{cipher:"aes-128-ctr",cipherparams:{iv:$.toString("hex")},ciphertext:J.toString("hex"),kdf:"pbkdf2",kdfparams:Y,mac:B},meta:"xchain-keystore",version:1}}function P(q=12){return u(T,q===12?128:256)}function w(q){return O(q,T)}async function y(q,Z){let{SwapKitError:L}=await import("@swapkit/helpers");switch(q.version){case 1:{let $=q.crypto.kdfparams,Q=Buffer.from($.salt,"hex"),Y=U(Z,Q,$.c,$.dklen,"sha256"),j=Buffer.from(q.crypto.ciphertext,"hex"),F=Buffer.concat([Y.subarray(16,32),j]);if(await f(F)!==q.crypto.mac)throw new L("wallet_keystore_invalid_password");let z=M(q.crypto.cipher,Y.subarray(0,16),Buffer.from(q.crypto.cipherparams.iv,"hex"));return Buffer.concat([z.update(j),z.final()]).toString("utf8")}default:throw new L("wallet_keystore_unsupported_version")}}function c(q){return typeof q==="object"&&q!==null&&"deriveAddressAtIndex"in q&&typeof q.deriveAddressAtIndex==="function"&&"getExtendedPublicKey"in q&&typeof q.getExtendedPublicKey==="function"&&"getBalance"in q&&typeof q.getBalance==="function"}async function d(q,Z){let{createHDWalletHelpers:L,getUtxoApi:$}=await import("@swapkit/toolboxes/utxo");function Q(J){let{accountIndex:z,count:B,startIndex:N=0,change:R=!1}=J;if(B<1||B>1000)throw RangeError(`count must be between 1 and 1000, got ${B}`);if(N<0)throw RangeError(`startIndex must be non-negative, got ${N}`);let X=[];for(let _=0;_<B;_++){let V=Z.deriveAddressAtIndex({accountIndex:z,change:R,index:N+_});if(V)X.push(V)}return X}let{scanForAddresses:Y,getAggregatedBalance:j,getAggregatedUtxos:F}=L({chain:q,deriveAddress:(J)=>Z.deriveAddressAtIndex(J),getBalance:Z.getBalance,getUtxos:(J)=>$(q).getUtxos({address:J,fetchTxHex:!0})});return{deriveAddresses:Q,getAggregatedBalance:j,getAggregatedUtxos:F,scanForAddresses:Y}}var l=x({connect:({addChain:q})=>async function(L,$,Q){let Y=await s({chains:L,derivationPathMapOrIndex:Q,phrase:$});for(let j of Object.values(Y))q({...j,chain:j.chain,walletType:A.KEYSTORE});return!0},directSigningSupport:{...Object.fromEntries(W.map((q)=>[q,!0])),...Object.fromEntries(K.map((q)=>[q,!0])),...Object.fromEntries(S.filter((q)=>q!==G.Harbor).map((q)=>[q,!0])),[G.Aleo]:!0,[G.Aptos]:!0,[G.Cardano]:!0,[G.Hype]:!0,[G.Near]:!0,[G.Ripple]:!0,[G.Solana]:!0,[G.Stellar]:!0,[G.Sui]:!0,[G.Ton]:!0,[G.Tron]:!0},name:"connectKeystore",supportedChains:[...W,...K,...S.filter((q)=>q!==G.Harbor),G.Aleo,G.Aptos,G.Cardano,G.Ripple,G.Solana,G.Stellar,G.Sui,G.Ton,G.Tron,G.Near,G.Hype],walletType:A.KEYSTORE}),h=p(l);async function s({chains:q,phrase:Z,derivationPathMapOrIndex:L}){let $=v({chains:q,supportedChains:h,walletType:A.KEYSTORE}),Q=typeof L==="number"?L:0,Y=await Promise.allSettled($.map(async(J)=>{let{getToolbox:z}=await import("@swapkit/toolboxes"),B=L&&typeof L==="object"?L[J]:void 0,R=C[J].slice(0,J===G.Solana||J===G.Aleo?4:5),X=k.includes(J)?{account:Q}:{index:Q},_=B||b(R,X),V=await z(J,{derivationPath:_,phrase:Z}),g=await V.getAddress()||"",D=K.includes(J)&&c(V)?await d(J,V):{};return{...V,...D,address:g,chain:J}})),j=Y.flatMap((J)=>J.status==="fulfilled"?[J.value]:[]),F=Y[0];if(j.length===0&&F?.status==="rejected")throw F.reason;return j.reduce((J,z)=>{return J[z.chain]=z,J},{})}export{w as validatePhrase,l as keystoreWallet,P as generatePhrase,I as encryptToKeyStore,y as decryptFromKeystore,s as createKeystoreWallet,h as KEYSTORE_SUPPORTED_CHAINS};
1
+ var g=((e)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(s,n)=>(typeof require<"u"?require:s)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{ACCOUNT_INDEXED_CHAINS as I,Chain as t,CosmosChains as P,EVMChains as S,filterSupportedChains as R,NetworkDerivationPath as X,UTXOChains as x,updateDerivationPath as _,WalletOption as b}from"@swapkit/helpers";import{createWallet as j,getWalletSupportedChains as F}from"@swapkit/wallet-core";import{createCipheriv as E,createDecipheriv as K,pbkdf2Sync as v,randomBytes as A}from"node:crypto";import{generateMnemonic as H,validateMnemonic as W}from"@scure/bip39";import{wordlist as T}from"@scure/bip39/wordlists/english.js";async function w(e){let{blake2b:s}=await import("@noble/hashes/blake2.js"),n=e instanceof Buffer?e:Buffer.from(e,"hex"),o=s(n,{dkLen:32});return Array.from(o).map((a)=>a<16?`0${a.toString(16)}`:a.toString(16)).join("")}async function k(e,s){let o=A(16),a=A(32),i={c:262144,dklen:32,prf:"hmac-sha256",salt:a.toString("hex")},c=v(s,a,i.c,i.dklen,"sha256"),l=E("aes-128-ctr",c.subarray(0,16),o),r=Buffer.concat([l.update(Buffer.from(e,"utf8")),l.final()]),d=Buffer.concat([c.subarray(16,32),Buffer.from(r)]),u=await w(d);return{crypto:{cipher:"aes-128-ctr",cipherparams:{iv:o.toString("hex")},ciphertext:r.toString("hex"),kdf:"pbkdf2",kdfparams:i,mac:u},meta:"xchain-keystore",version:1}}function O(e=12){return H(T,e===12?128:256)}function U(e){return W(e,T)}async function B(e,s){let{SwapKitError:n}=await import("@swapkit/helpers");switch(e.version){case 1:{let o=e.crypto.kdfparams,a=Buffer.from(o.salt,"hex"),i=v(s,a,o.c,o.dklen,"sha256"),c=Buffer.from(e.crypto.ciphertext,"hex"),l=Buffer.concat([i.subarray(16,32),c]);if(await w(l)!==e.crypto.mac)throw new n("wallet_keystore_invalid_password");let d=K(e.crypto.cipher,i.subarray(0,16),Buffer.from(e.crypto.cipherparams.iv,"hex"));return Buffer.concat([d.update(c),d.final()]).toString("utf8")}default:throw new n("wallet_keystore_unsupported_version")}}function N(e){return typeof e==="object"&&e!==null&&"deriveAddressAtIndex"in e&&typeof e.deriveAddressAtIndex==="function"&&"getExtendedPublicKey"in e&&typeof e.getExtendedPublicKey==="function"&&"getBalance"in e&&typeof e.getBalance==="function"}async function V(e,s){let{createHDWalletHelpers:n,getUtxoApi:o}=await import("@swapkit/toolboxes/utxo");function a(r){let{accountIndex:d,count:u,startIndex:m=0,change:y=!1}=r;if(u<1||u>1000)throw RangeError(`count must be between 1 and 1000, got ${u}`);if(m<0)throw RangeError(`startIndex must be non-negative, got ${m}`);let h=[];for(let f=0;f<u;f++){let p=s.deriveAddressAtIndex({accountIndex:d,change:y,index:m+f});if(p)h.push(p)}return h}let{scanForAddresses:i,getAggregatedBalance:c,getAggregatedUtxos:l}=n({chain:e,deriveAddress:(r)=>s.deriveAddressAtIndex(r),getBalance:s.getBalance,getUtxos:(r)=>o(e).getUtxos({address:r,fetchTxHex:!0})});return{deriveAddresses:a,getAggregatedBalance:c,getAggregatedUtxos:l,scanForAddresses:i}}var M=j({connect:({addChain:e})=>async function(n,o,a){let i=await L({chains:n,derivationPathMapOrIndex:a,phrase:o});for(let c of Object.values(i))e({...c,chain:c.chain,walletType:b.KEYSTORE});return!0},directSigningSupport:{...Object.fromEntries(S.map((e)=>[e,!0])),...Object.fromEntries(x.map((e)=>[e,!0])),...Object.fromEntries(P.filter((e)=>e!==t.Harbor).map((e)=>[e,!0])),[t.Aleo]:!0,[t.Aptos]:!0,[t.Cardano]:!0,[t.Hype]:!0,[t.Near]:!0,[t.Ripple]:!0,[t.Solana]:!0,[t.Stellar]:!0,[t.Sui]:!0,[t.Ton]:!0,[t.Tron]:!0},name:"connectKeystore",supportedChains:[...S,...x,...P.filter((e)=>e!==t.Harbor),t.Aleo,t.Aptos,t.Cardano,t.Ripple,t.Solana,t.Stellar,t.Sui,t.Ton,t.Tron,t.Near,t.Hype],walletType:b.KEYSTORE}),Y=F(M);async function L({chains:e,phrase:s,derivationPathMapOrIndex:n}){let o=R({chains:e,supportedChains:Y,walletType:b.KEYSTORE}),a=typeof n==="number"?n:0,i=await Promise.allSettled(o.map(async(r)=>{let{getToolbox:d}=await import("@swapkit/toolboxes"),u=n&&typeof n==="object"?n[r]:void 0,y=X[r].slice(0,r===t.Solana||r===t.Aleo?4:5),h=I.includes(r)?{account:a}:{index:a},f=u||_(y,h),p=await d(r,{derivationPath:f,phrase:s}),D=await p.getAddress()||"",C=x.includes(r)&&N(p)?await V(r,p):{};return{...p,...C,address:D,chain:r}})),c=i.flatMap((r)=>r.status==="fulfilled"?[r.value]:[]),l=i[0];if(c.length===0&&l?.status==="rejected")throw l.reason;return c.reduce((r,d)=>(r[d.chain]=d,r),{})}export{Y as KEYSTORE_SUPPORTED_CHAINS,L as createKeystoreWallet,B as decryptFromKeystore,k as encryptToKeyStore,O as generatePhrase,M as keystoreWallet,U as validatePhrase};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "author": "swapkit-dev",
3
- "dependencies": { "@swapkit/helpers": "5.2.1", "@swapkit/toolboxes": "5.2.1", "@swapkit/wallet-core": "5.0.5" },
3
+ "dependencies": { "@swapkit/helpers": "5.3.0", "@swapkit/toolboxes": "5.3.0", "@swapkit/wallet-core": "5.0.6" },
4
4
  "description": "SwapKit - Wallet Keystore",
5
5
  "exports": { ".": { "default": "./dist/index.js", "types": "./dist/types/index.d.ts" } },
6
6
  "files": ["dist/", "CHANGELOG.md"],
@@ -22,5 +22,5 @@
22
22
  "type-check:go": "tsgo"
23
23
  },
24
24
  "type": "module",
25
- "version": "5.1.1"
25
+ "version": "5.1.2"
26
26
  }