@swapkit/wallet-keystore 5.1.3 → 5.2.1
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 +16 -0
- package/dist/index.js +1 -1
- package/dist/types/helpers.d.ts +27 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @swapkit/wallet-keystore
|
|
2
2
|
|
|
3
|
+
## 5.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#408](https://github.com/swapkit/sdk/pull/408) [`93dc581`](https://github.com/swapkit/sdk/commit/93dc581bf236eb2823337939ed6c41ce1fec8fad) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Replace the default `rpcUrls` entry for `Chain.Arc` with the Arc mainnet QuickNode RPC (via @swapkit/helpers@5.4.2)
|
|
8
|
+
- [#406](https://github.com/swapkit/sdk/pull/406) [`ed678ed`](https://github.com/swapkit/sdk/commit/ed678edfe26d66134db63fbe8d9891168f70e7d8) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@5.4.2)
|
|
9
|
+
|
|
10
|
+
## 5.2.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#401](https://github.com/swapkit/sdk/pull/401) [`7f87112`](https://github.com/swapkit/sdk/commit/7f871121b2949d12de4e5809be7fb544f119dec8) Thanks [@ice-chillios](https://github.com/ice-chillios)! - `generatePhrase` now defaults to a 24-word (256-bit entropy) seed phrase, accepts every BIP39 length (12, 15, 18, 21 or 24 words) and throws `wallet_keystore_invalid_word_count` (21903, added to `@swapkit/helpers`) for anything else instead of silently using 256 bits. New `generateKeystore({ password, wordCount })` creates a phrase and its encrypted keystore in one call; `PhraseWordCount` is exported for wallet-creation UIs offering the choice.
|
|
15
|
+
- [#404](https://github.com/swapkit/sdk/pull/404) [`ce7f02d`](https://github.com/swapkit/sdk/commit/ce7f02def2c25307c403b20f213a383834ab8bcc) Thanks [@towanTG](https://github.com/towanTG)! - Changes base url for token icons (via @swapkit/helpers@5.4.1)
|
|
16
|
+
- [#405](https://github.com/swapkit/sdk/pull/405) [`cbbfdcf`](https://github.com/swapkit/sdk/commit/cbbfdcfbf676855f5bff53547854a725b29f1a7b) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Add public Arc mainnet RPC (`https://rpc.mainnet.arc.io`) as the default `rpcUrls` entry for `Chain.Arc` (via @swapkit/helpers@5.4.1)
|
|
17
|
+
- [#399](https://github.com/swapkit/sdk/pull/399) [`70749e7`](https://github.com/swapkit/sdk/commit/70749e7899630daabc371a36c498f62b9da1c62f) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@5.4.1)
|
|
18
|
+
|
|
3
19
|
## 5.1.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var g=((e)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(
|
|
1
|
+
var g=((e)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(a,n)=>(typeof require<"u"?require:a)[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 _,Chain as r,CosmosChains as D,EVMChains as W,filterSupportedChains as X,NetworkDerivationPath as j,UTXOChains as b,updateDerivationPath as F,WalletOption as A}from"@swapkit/helpers";import{createWallet as N,getWalletSupportedChains as V}from"@swapkit/wallet-core";import{createCipheriv as k,createDecipheriv as H,pbkdf2Sync as w,randomBytes as v}from"node:crypto";import{generateMnemonic as O,validateMnemonic as U}from"@scure/bip39";import{wordlist as T}from"@scure/bip39/wordlists/english.js";import{SwapKitError as x}from"@swapkit/helpers";async function P(e){let{blake2b:a}=await import("@noble/hashes/blake2.js"),n=e instanceof Buffer?e:Buffer.from(e,"hex"),o=a(n,{dkLen:32});return Array.from(o).map((s)=>s<16?`0${s.toString(16)}`:s.toString(16)).join("")}async function S(e,a){let o=v(16),s=v(32),i={c:262144,dklen:32,prf:"hmac-sha256",salt:s.toString("hex")},c=w(a,s,i.c,i.dklen,"sha256"),l=k("aes-128-ctr",c.subarray(0,16),o),t=Buffer.concat([l.update(Buffer.from(e,"utf8")),l.final()]),d=Buffer.concat([c.subarray(16,32),Buffer.from(t)]),u=await P(d);return{crypto:{cipher:"aes-128-ctr",cipherparams:{iv:o.toString("hex")},ciphertext:t.toString("hex"),kdf:"pbkdf2",kdfparams:i,mac:u},meta:"xchain-keystore",version:1}}function C(e=24){if(![12,15,18,21,24].includes(e))throw new x("wallet_keystore_invalid_word_count",{wordCount:e});return O(T,e/3*32)}async function B({password:e,wordCount:a=24}){let n=C(a);return{keystore:await S(n,e),phrase:n}}function I(e){return U(e,T)}async function R(e,a){switch(e.version){case 1:{let n=e.crypto.kdfparams,o=Buffer.from(n.salt,"hex"),s=w(a,o,n.c,n.dklen,"sha256"),i=Buffer.from(e.crypto.ciphertext,"hex"),c=Buffer.concat([s.subarray(16,32),i]);if(await P(c)!==e.crypto.mac)throw new x("wallet_keystore_invalid_password");let t=H(e.crypto.cipher,s.subarray(0,16),Buffer.from(e.crypto.cipherparams.iv,"hex"));return Buffer.concat([t.update(i),t.final()]).toString("utf8")}default:throw new x("wallet_keystore_unsupported_version")}}function M(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 Y(e,a){let{createHDWalletHelpers:n,getUtxoApi:o}=await import("@swapkit/toolboxes/utxo");function s(t){let{accountIndex:d,count:u,startIndex:m=0,change:y=!1}=t;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=a.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:(t)=>a.deriveAddressAtIndex(t),getBalance:a.getBalance,getUtxos:(t)=>o(e).getUtxos({address:t,fetchTxHex:!0})});return{deriveAddresses:s,getAggregatedBalance:c,getAggregatedUtxos:l,scanForAddresses:i}}var L=N({connect:({addChain:e})=>async function(n,o,s){let i=await z({chains:n,derivationPathMapOrIndex:s,phrase:o});for(let c of Object.values(i))e({...c,chain:c.chain,walletType:A.KEYSTORE});return!0},directSigningSupport:{...Object.fromEntries(W.map((e)=>[e,!0])),...Object.fromEntries(b.map((e)=>[e,!0])),...Object.fromEntries(D.filter((e)=>e!==r.Harbor).map((e)=>[e,!0])),[r.Aleo]:!0,[r.Aptos]:!0,[r.Cardano]:!0,[r.Hype]:!0,[r.Near]:!0,[r.Ripple]:!0,[r.Solana]:!0,[r.Stellar]:!0,[r.Sui]:!0,[r.Ton]:!0,[r.Tron]:!0},name:"connectKeystore",supportedChains:[...W,...b,...D.filter((e)=>e!==r.Harbor),r.Aleo,r.Aptos,r.Cardano,r.Ripple,r.Solana,r.Stellar,r.Sui,r.Ton,r.Tron,r.Near,r.Hype],walletType:A.KEYSTORE}),q=V(L);async function z({chains:e,phrase:a,derivationPathMapOrIndex:n}){let o=X({chains:e,supportedChains:q,walletType:A.KEYSTORE}),s=typeof n==="number"?n:0,i=await Promise.allSettled(o.map(async(t)=>{let{getToolbox:d}=await import("@swapkit/toolboxes"),u=n&&typeof n==="object"?n[t]:void 0,y=j[t].slice(0,t===r.Solana||t===r.Aleo?4:5),h=_.includes(t)?{account:s}:{index:s},f=u||F(y,h),p=await d(t,{derivationPath:f,phrase:a}),K=await p.getAddress()||"",E=b.includes(t)&&M(p)?await Y(t,p):{};return{...p,...E,address:K,chain:t}})),c=i.flatMap((t)=>t.status==="fulfilled"?[t.value]:[]),l=i[0];if(c.length===0&&l?.status==="rejected")throw l.reason;return c.reduce((t,d)=>(t[d.chain]=d,t),{})}export{q as KEYSTORE_SUPPORTED_CHAINS,z as createKeystoreWallet,R as decryptFromKeystore,S as encryptToKeyStore,B as generateKeystore,C as generatePhrase,L as keystoreWallet,I as validatePhrase};
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type PhraseWordCount = 12 | 15 | 18 | 21 | 24;
|
|
1
2
|
export type Keystore = {
|
|
2
3
|
version: number;
|
|
3
4
|
meta: string;
|
|
@@ -36,6 +37,31 @@ export declare function encryptToKeyStore(phrase: string, password: string): Pro
|
|
|
36
37
|
meta: string;
|
|
37
38
|
version: number;
|
|
38
39
|
}>;
|
|
39
|
-
export declare function generatePhrase(
|
|
40
|
+
export declare function generatePhrase(wordCount?: PhraseWordCount): string;
|
|
41
|
+
export declare function generateKeystore({ password, wordCount, }: {
|
|
42
|
+
password: string;
|
|
43
|
+
wordCount?: PhraseWordCount;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
keystore: {
|
|
46
|
+
crypto: {
|
|
47
|
+
cipher: string;
|
|
48
|
+
cipherparams: {
|
|
49
|
+
iv: string;
|
|
50
|
+
};
|
|
51
|
+
ciphertext: string;
|
|
52
|
+
kdf: string;
|
|
53
|
+
kdfparams: {
|
|
54
|
+
c: number;
|
|
55
|
+
dklen: number;
|
|
56
|
+
prf: string;
|
|
57
|
+
salt: string;
|
|
58
|
+
};
|
|
59
|
+
mac: string;
|
|
60
|
+
};
|
|
61
|
+
meta: string;
|
|
62
|
+
version: number;
|
|
63
|
+
};
|
|
64
|
+
phrase: string;
|
|
65
|
+
}>;
|
|
40
66
|
export declare function validatePhrase(phrase: string): boolean;
|
|
41
67
|
export declare function decryptFromKeystore(keystore: Keystore, password: string): Promise<string>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Chain, type DerivationPathArray } from "@swapkit/helpers";
|
|
2
2
|
import type { FullWallet } from "@swapkit/toolboxes";
|
|
3
|
-
export { decryptFromKeystore, encryptToKeyStore, generatePhrase, type Keystore, validatePhrase, } from "./helpers";
|
|
3
|
+
export { decryptFromKeystore, encryptToKeyStore, generateKeystore, generatePhrase, type Keystore, type PhraseWordCount, validatePhrase, } from "./helpers";
|
|
4
4
|
export declare const keystoreWallet: {
|
|
5
5
|
connectKeystore: {
|
|
6
6
|
connectWallet: ({ addChain }: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-dev",
|
|
3
|
-
"dependencies": { "@swapkit/helpers": "5.4.
|
|
3
|
+
"dependencies": { "@swapkit/helpers": "5.4.2", "@swapkit/toolboxes": "5.4.2", "@swapkit/wallet-core": "5.0.9" },
|
|
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
|
|
25
|
+
"version": "5.2.1"
|
|
26
26
|
}
|