@swapkit/wallet-keystore 6.0.4 → 6.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @swapkit/wallet-keystore
2
2
 
3
+ ## 6.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#459](https://github.com/swapkit/sdk/pull/459) [`29bda2c`](https://github.com/swapkit/sdk/commit/29bda2c7a7f69112fc9403c042cb4aee7c2010a5) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Wallets now declare all their signing capabilities per chain in one `signingSupport` map on `createWallet`: `direct` (signs the transaction the API builds for a route), `typedData` (EIP-712) and `btcMessage` (BIP-137), with the names exported as `SigningCapability`. Undeclared capabilities count as unsupported, and each connected chain wallet carries its capabilities as `signing`. Use `walletSupportsDirectSigning(wallet)` to check for direct signing; it understands wallets from both old and new connectors.
8
+ - [#462](https://github.com/swapkit/sdk/pull/462) [`adf132c`](https://github.com/swapkit/sdk/commit/adf132ce1b856153be10f132372cb4fd6cabe7d6) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - EVM wallets wrapped by `prepareNetworkSwitch` now switch to the chain's network before `signTypedData`, as they already do before sending a transaction. A refused or impossible switch fails with `helpers_failed_to_switch_network` before anything is signed. Message signing (`signMessage`) is unchanged. (via @swapkit/helpers@6.3.0)
9
+ - [#457](https://github.com/swapkit/sdk/pull/457) [`59568bc`](https://github.com/swapkit/sdk/commit/59568bcafbe907e7efa3a6ee0eb55a8c2500bac4) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - EVM `signTypedData` now accepts standard EIP-712 payloads that include `EIP712Domain` in `types`, as wallets and backends produce them for `eth_signTypedData_v4`. Such payloads previously threw; callers no longer need to strip `EIP712Domain` before signing. If the declared `EIP712Domain` does not exactly match the fields of `domain` (names, types and canonical order), signing rejects with `toolbox_evm_typed_data_domain_mismatch` instead of signing a different domain. Payloads without it sign exactly as before. (via @swapkit/helpers@6.3.0)
10
+ - [#453](https://github.com/swapkit/sdk/pull/453) [`e8988db`](https://github.com/swapkit/sdk/commit/e8988dbd06040f6b134163e7d9cba1910b9ee711) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@6.3.0)
11
+ - [#452](https://github.com/swapkit/sdk/pull/452) [`8f3ecb0`](https://github.com/swapkit/sdk/commit/8f3ecb0522e2433f38012277446fd56ba1a223c5) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - The Sui toolbox now talks to Sui over gRPC instead of JSON-RPC, which Sui's public fullnodes stopped serving. Balances, transfers, sweeps, fee estimates and swaps from Sui work again with the default RPC. A custom Sui RPC set in `rpcUrls` must now serve gRPC. (via @swapkit/toolboxes@6.4.1)
12
+
13
+ ## 6.0.5
14
+
15
+ ### Patch Changes
16
+
17
+ - [#373](https://github.com/swapkit/sdk/pull/373) [`218e46d`](https://github.com/swapkit/sdk/commit/218e46d12d423e0420143ec410f0a4c8d102ab8d) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Add the `toolbox_lightspark_*` block (91301 to 91313) to `SwapKitError.ErrorCode` for the new Lightning toolbox: `toolbox_lightspark_missing_credentials`, `toolbox_lightspark_invalid_invoice`, `toolbox_lightspark_invoice_amount_mismatch`, `toolbox_lightspark_invoice_destination_mismatch`, `toolbox_lightspark_invoice_expired`, `toolbox_lightspark_invoice_already_settled`, `toolbox_lightspark_fee_limit_exceeded`, `toolbox_lightspark_invalid_params`, `toolbox_lightspark_api_error`, `toolbox_lightspark_invalid_amount`, `toolbox_lightspark_invalid_destination`, `toolbox_lightspark_network_mismatch` and `toolbox_lightspark_signing_key_unavailable`. An unloadable node signing key is reported as `toolbox_lightspark_signing_key_unavailable`, distinct from `toolbox_lightspark_missing_credentials`, so an integrator branching on the code can tell an unloaded key from an absent credential. (via @swapkit/helpers@6.2.0)
18
+ - [#447](https://github.com/swapkit/sdk/pull/447) [`b827853`](https://github.com/swapkit/sdk/commit/b827853cd1bfa68a9bd733843b3740f10ecab359) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@6.2.0)
19
+ - [#373](https://github.com/swapkit/sdk/pull/373) [`218e46d`](https://github.com/swapkit/sdk/commit/218e46d12d423e0420143ec410f0a4c8d102ab8d) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Add a standalone Lightning toolbox backed by Lightspark at `@swapkit/toolboxes/lightspark`, re-exported from `@swapkit/server`. It ships with no `Chain` enum member and no core or wallet wiring. (via @swapkit/toolboxes@6.4.0)
20
+ - [#449](https://github.com/swapkit/sdk/pull/449) [`e105e04`](https://github.com/swapkit/sdk/commit/e105e0417e77c486406706ecf1c0ed12c77c4375) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - The Starknet toolbox uses a wallet-provided account only to sign and send. Network reads and fee estimates go through the configured Starknet RPC, so wallets that bundle an older starknet.js (such as OKX Wallet) no longer fail with `getClassHashAt` of undefined or an "Invalid block id" error. (via @swapkit/toolboxes@6.4.0)
21
+
3
22
  ## 6.0.4
4
23
 
5
24
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var x=((e)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(a,r)=>(typeof require<"u"?require:a)[r]}):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 n,CosmosChains as C,EVMChains as S,filterSupportedChains as R,getUTXOScriptTypeForPath as F,NetworkDerivationPath as M,SwapKitError as j,UTXOChains as m,updateDerivationPath as N,WalletOption as T}from"@swapkit/helpers";import{createWallet as V,getWalletSupportedChains as Y}from"@swapkit/wallet-core";import{createCipheriv as E,createDecipheriv as W,pbkdf2Sync as b,randomBytes as P}from"node:crypto";import{generateMnemonic as X,validateMnemonic as k}from"@scure/bip39";import{wordlist as w}from"@scure/bip39/wordlists/english.js";import{SwapKitError as v}from"@swapkit/helpers";async function A(e){let{blake2b:a}=await import("@noble/hashes/blake2.js"),r=e instanceof Buffer?e:Buffer.from(e,"hex"),i=a(r,{dkLen:32});return Array.from(i).map((o)=>o<16?`0${o.toString(16)}`:o.toString(16)).join("")}async function D(e,a){let i=P(16),o=P(32),s={c:262144,dklen:32,prf:"hmac-sha256",salt:o.toString("hex")},d=b(a,o,s.c,s.dklen,"sha256"),u=E("aes-128-ctr",d.subarray(0,16),i),t=Buffer.concat([u.update(Buffer.from(e,"utf8")),u.final()]),c=Buffer.concat([d.subarray(16,32),Buffer.from(t)]),p=await A(c);return{crypto:{cipher:"aes-128-ctr",cipherparams:{iv:i.toString("hex")},ciphertext:t.toString("hex"),kdf:"pbkdf2",kdfparams:s,mac:p},meta:"xchain-keystore",version:1}}function K(e=24){if(![12,15,18,21,24].includes(e))throw new v("wallet_keystore_invalid_word_count",{wordCount:e});return X(w,e/3*32)}async function _({password:e,wordCount:a=24}){let r=K(a);return{keystore:await D(r,e),phrase:r}}function H(e){return k(e,w)}async function B(e,a){switch(e.version){case 1:{let r=e.crypto.kdfparams,i=Buffer.from(r.salt,"hex"),o=b(a,i,r.c,r.dklen,"sha256"),s=Buffer.from(e.crypto.ciphertext,"hex"),d=Buffer.concat([o.subarray(16,32),s]);if(await A(d)!==e.crypto.mac)throw new v("wallet_keystore_invalid_password");let t=W(e.crypto.cipher,o.subarray(0,16),Buffer.from(e.crypto.cipherparams.iv,"hex"));return Buffer.concat([t.update(s),t.final()]).toString("utf8")}default:throw new v("wallet_keystore_unsupported_version")}}function L(e,a){if(!a)return{derivationPath:void 0,scriptType:void 0};let r=m.includes(e),i="derivationPath"in a?a.derivationPath:a,o="scriptType"in a?a.scriptType:void 0;if(r&&!o)throw new j("toolbox_utxo_invalid_params",{chain:e,error:`${e}: a UTXO derivation entry must state its scriptType: { derivationPath, scriptType }. getUTXOScriptTypeForPath(derivationPath) gives the encoding the path implies.`});return{derivationPath:i,scriptType:r?o:void 0}}var q=new Set(["toolbox_utxo_unsupported_script_type","toolbox_utxo_invalid_params"]);function z(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 G(e,a){let{createHDWalletHelpers:r,getUtxoApi:i}=await import("@swapkit/toolboxes/utxo");function o(t){let{accountIndex:c,count:p,startIndex:h=0,change:g=!1}=t;if(p<1||p>1000)throw RangeError(`count must be between 1 and 1000, got ${p}`);if(h<0)throw RangeError(`startIndex must be non-negative, got ${h}`);let y=[];for(let f=0;f<p;f++){let l=a.deriveAddressAtIndex({accountIndex:c,change:g,index:h+f});if(l)y.push(l)}return y}let{scanForAddresses:s,getAggregatedBalance:d,getAggregatedUtxos:u}=r({chain:e,deriveAddress:(t)=>a.deriveAddressAtIndex(t),getBalance:a.getBalance,getUtxos:(t)=>i(e).getUtxos({address:t,fetchTxHex:!0})});return{deriveAddresses:o,getAggregatedBalance:d,getAggregatedUtxos:u,scanForAddresses:s}}var J=V({connect:({addChain:e})=>async function(r,i,o){let s=await Z({chains:r,derivationPathMapOrIndex:o,phrase:i});for(let d of Object.values(s))e({...d,chain:d.chain,walletType:T.KEYSTORE});return!0},directSigningSupport:{...Object.fromEntries(S.map((e)=>[e,!0])),...Object.fromEntries(m.map((e)=>[e,!0])),...Object.fromEntries(C.filter((e)=>e!==n.Harbor).map((e)=>[e,!0])),[n.Aleo]:!0,[n.Aptos]:!0,[n.Cardano]:!0,[n.Hype]:!0,[n.Near]:!0,[n.Ripple]:!0,[n.Solana]:!0,[n.Stellar]:!0,[n.Sui]:!0,[n.Ton]:!0,[n.Tron]:!0},name:"connectKeystore",supportedChains:[...S,...m,...C.filter((e)=>e!==n.Harbor),n.Aleo,n.Aptos,n.Cardano,n.Ripple,n.Solana,n.Stellar,n.Sui,n.Ton,n.Tron,n.Near,n.Hype],walletType:T.KEYSTORE}),Q=Y(J);async function Z({chains:e,phrase:a,derivationPathMapOrIndex:r}){let i=R({chains:e,supportedChains:Q,walletType:T.KEYSTORE}),o=typeof r==="number"?r:0,s=await Promise.allSettled(i.map(async(t)=>{let{getToolbox:c}=await import("@swapkit/toolboxes"),{derivationPath:p,scriptType:h}=L(t,r&&typeof r==="object"?r[t]:void 0),g=I.includes(t)?{account:o}:{index:o},y=p||N(M[t],g),f=m.includes(t)?h??F(y):void 0,l=await c(t,{derivationPath:y,phrase:a,...f?{scriptType:f}:{}}),O=await l.getAddress()||"",U=m.includes(t)&&z(l)?await G(t,l):{};return{...l,...U,address:O,chain:t}})),d=s.flatMap((t)=>t.status==="fulfilled"?[t.value]:[]),u=s[0];if(d.length===0&&u?.status==="rejected")throw u.reason;for(let[t,c]of s.entries()){if(c.status!=="rejected")continue;let p=c.reason?.errorKey;if(p&&q.has(p))throw c.reason;console.error(`connectKeystore: skipping ${i[t]} — failed to connect`,c.reason)}return d.reduce((t,c)=>(t[c.chain]=c,t),{})}export{Q as KEYSTORE_SUPPORTED_CHAINS,Z as createKeystoreWallet,B as decryptFromKeystore,D as encryptToKeyStore,_ as generateKeystore,K as generatePhrase,J as keystoreWallet,H as validatePhrase};
1
+ var x=((e)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,r)=>(typeof require<"u"?require:n)[r]}):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 d,CosmosChains as R,EVMChains as O,filterSupportedChains as M,getUTXOScriptTypeForPath as F,NetworkDerivationPath as V,SwapKitError as j,UTXOChains as m,updateDerivationPath as N,WalletOption as T}from"@swapkit/helpers";import{createWallet as Y,getWalletSupportedChains as L}from"@swapkit/wallet-core";import{createCipheriv as E,createDecipheriv as W,pbkdf2Sync as b,randomBytes as P}from"node:crypto";import{generateMnemonic as k,validateMnemonic as X}from"@scure/bip39";import{wordlist as w}from"@scure/bip39/wordlists/english.js";import{SwapKitError as v}from"@swapkit/helpers";async function A(e){let{blake2b:n}=await import("@noble/hashes/blake2.js"),r=e instanceof Buffer?e:Buffer.from(e,"hex"),o=n(r,{dkLen:32});return Array.from(o).map((a)=>a<16?`0${a.toString(16)}`:a.toString(16)).join("")}async function C(e,n){let o=P(16),a=P(32),i={c:262144,dklen:32,prf:"hmac-sha256",salt:a.toString("hex")},c=b(n,a,i.c,i.dklen,"sha256"),u=E("aes-128-ctr",c.subarray(0,16),o),t=Buffer.concat([u.update(Buffer.from(e,"utf8")),u.final()]),s=Buffer.concat([c.subarray(16,32),Buffer.from(t)]),p=await A(s);return{crypto:{cipher:"aes-128-ctr",cipherparams:{iv:o.toString("hex")},ciphertext:t.toString("hex"),kdf:"pbkdf2",kdfparams:i,mac:p},meta:"xchain-keystore",version:1}}function D(e=24){if(![12,15,18,21,24].includes(e))throw new v("wallet_keystore_invalid_word_count",{wordCount:e});return k(w,e/3*32)}async function _({password:e,wordCount:n=24}){let r=D(n);return{keystore:await C(r,e),phrase:r}}function H(e){return X(e,w)}async function B(e,n){switch(e.version){case 1:{let r=e.crypto.kdfparams,o=Buffer.from(r.salt,"hex"),a=b(n,o,r.c,r.dklen,"sha256"),i=Buffer.from(e.crypto.ciphertext,"hex"),c=Buffer.concat([a.subarray(16,32),i]);if(await A(c)!==e.crypto.mac)throw new v("wallet_keystore_invalid_password");let t=W(e.crypto.cipher,a.subarray(0,16),Buffer.from(e.crypto.cipherparams.iv,"hex"));return Buffer.concat([t.update(i),t.final()]).toString("utf8")}default:throw new v("wallet_keystore_unsupported_version")}}function q(e,n){if(!n)return{derivationPath:void 0,scriptType:void 0};let r=m.includes(e),o="derivationPath"in n?n.derivationPath:n,a="scriptType"in n?n.scriptType:void 0;if(r&&!a)throw new j("toolbox_utxo_invalid_params",{chain:e,error:`${e}: a UTXO derivation entry must state its scriptType: { derivationPath, scriptType }. getUTXOScriptTypeForPath(derivationPath) gives the encoding the path implies.`});return{derivationPath:o,scriptType:r?a:void 0}}var z=new Set(["toolbox_utxo_unsupported_script_type","toolbox_utxo_invalid_params"]);function G(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 J(e,n){let{createHDWalletHelpers:r,getUtxoApi:o}=await import("@swapkit/toolboxes/utxo");function a(t){let{accountIndex:s,count:p,startIndex:f=0,change:g=!1}=t;if(p<1||p>1000)throw RangeError(`count must be between 1 and 1000, got ${p}`);if(f<0)throw RangeError(`startIndex must be non-negative, got ${f}`);let y=[];for(let h=0;h<p;h++){let l=n.deriveAddressAtIndex({accountIndex:s,change:g,index:f+h});if(l)y.push(l)}return y}let{scanForAddresses:i,getAggregatedBalance:c,getAggregatedUtxos:u}=r({chain:e,deriveAddress:(t)=>n.deriveAddressAtIndex(t),getBalance:n.getBalance,getUtxos:(t)=>o(e).getUtxos({address:t,fetchTxHex:!0})});return{deriveAddresses:a,getAggregatedBalance:c,getAggregatedUtxos:u,scanForAddresses:i}}var K=[...O,...m,...R.filter((e)=>e!==d.Harbor),d.Aleo,d.Aptos,d.Cardano,d.Ripple,d.Solana,d.Stellar,d.Sui,d.Ton,d.Tron,d.Near,d.Hype],Q=Y({connect:({addChain:e})=>async function(r,o,a){let i=await ee({chains:r,derivationPathMapOrIndex:a,phrase:o});for(let c of Object.values(i))e({...c,chain:c.chain,walletType:T.KEYSTORE});return!0},name:"connectKeystore",signingSupport:Object.fromEntries(K.map((e)=>[e,O.includes(e)?{direct:!0,typedData:!0}:{direct:!0}])),supportedChains:[...K],walletType:T.KEYSTORE}),Z=L(Q);async function ee({chains:e,phrase:n,derivationPathMapOrIndex:r}){let o=M({chains:e,supportedChains:Z,walletType:T.KEYSTORE}),a=typeof r==="number"?r:0,i=await Promise.allSettled(o.map(async(t)=>{let{getToolbox:s}=await import("@swapkit/toolboxes"),{derivationPath:p,scriptType:f}=q(t,r&&typeof r==="object"?r[t]:void 0),g=I.includes(t)?{account:a}:{index:a},y=p||N(V[t],g),h=m.includes(t)?f??F(y):void 0,l=await s(t,{derivationPath:y,phrase:n,...h?{scriptType:h}:{}}),S=await l.getAddress()||"",U=m.includes(t)&&G(l)?await J(t,l):{};return{...l,...U,address:S,chain:t}})),c=i.flatMap((t)=>t.status==="fulfilled"?[t.value]:[]),u=i[0];if(c.length===0&&u?.status==="rejected")throw u.reason;for(let[t,s]of i.entries()){if(s.status!=="rejected")continue;let p=s.reason?.errorKey;if(p&&z.has(p))throw s.reason;console.error(`connectKeystore: skipping ${o[t]} — failed to connect`,s.reason)}return c.reduce((t,s)=>(t[s.chain]=s,t),{})}export{Z as KEYSTORE_SUPPORTED_CHAINS,ee as createKeystoreWallet,B as decryptFromKeystore,C as encryptToKeyStore,_ as generateKeystore,D as generatePhrase,Q as keystoreWallet,H as validatePhrase};
@@ -21,6 +21,7 @@ export declare const keystoreWallet: {
21
21
  }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: KeystoreDerivationPathMapOrIndex | undefined) => Promise<boolean>;
22
22
  directSigningSupport: import("@swapkit/wallet-core").DirectSigningSupport;
23
23
  getExtendedPublicKey?: import("@swapkit/wallet-core").GetExtendedPublicKey;
24
+ signingSupport?: import("@swapkit/wallet-core").ChainSigningSupport;
24
25
  supportedChains: (Chain.Adi | Chain.Aleo | Chain.Aptos | Chain.Arbitrum | Chain.Arc | Chain.Aurora | Chain.Avalanche | Chain.Base | Chain.Berachain | Chain.BinanceSmartChain | Chain.Bitcoin | Chain.BitcoinCash | Chain.Botanix | Chain.Cardano | Chain.Core | Chain.Corn | Chain.Cosmos | Chain.Cronos | Chain.Dash | Chain.Dogecoin | Chain.Ethereum | Chain.Gnosis | Chain.Hyperevm | Chain.Hype | Chain.Kujira | Chain.Litecoin | Chain.Linea | Chain.Maya | Chain.MegaETH | Chain.Monad | Chain.Near | Chain.Noble | Chain.Optimism | Chain.Plasma | Chain.Polygon | Chain.Ripple | Chain.Robinhood | Chain.Solana | Chain.Sonic | Chain.Stellar | Chain.Sui | Chain.THORChain | Chain.Ton | Chain.Tron | Chain.Unichain | Chain.XLayer | Chain.Zcash)[];
25
26
  };
26
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "author": "swapkit-dev",
3
- "dependencies": { "@swapkit/helpers": "6.1.2", "@swapkit/toolboxes": "6.3.0", "@swapkit/wallet-core": "5.0.14" },
3
+ "dependencies": { "@swapkit/helpers": "6.3.0", "@swapkit/toolboxes": "6.4.1", "@swapkit/wallet-core": "5.1.0" },
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": "6.0.4"
25
+ "version": "6.1.0"
26
26
  }