@swapkit/passkey 0.1.0 → 0.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/dist/index.cjs +1 -1
- package/package.json +4 -12
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var{defineProperty:T,getOwnPropertyNames:X,getOwnPropertyDescriptor:b}=Object,j=Object.prototype.hasOwnProperty;var
|
|
1
|
+
var{defineProperty:T,getOwnPropertyNames:X,getOwnPropertyDescriptor:b}=Object,j=Object.prototype.hasOwnProperty;function q(t){return this[t]}var z=(t)=>{var o=(H??=new WeakMap).get(t),n;if(o)return o;if(o=T({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function"){for(var l of X(t))if(!j.call(o,l))T(o,l,{get:q.bind(t,l),enumerable:!(n=b(t,l))||n.enumerable})}return H.set(t,o),o},H;var F=(t)=>t;function G(t,o){this[t]=F.bind(null,o)}var J=(t,o)=>{for(var n in o)T(t,n,{get:o[n],enumerable:!0,configurable:!0,set:G.bind(o,n)})};var N={};J(N,{passkeyWallet:()=>i,passkeyConnector:()=>E,PASSKEY_SUPPORTED_CHAINS:()=>D});module.exports=z(N);var a=require("@swapkit/helpers"),u=require("@swapkit/wallet-core");var _=require("@swapkit/helpers"),O=new TextEncoder().encode("swapkit-passkey-wallet-v1"),W=(t)=>btoa(String.fromCharCode(...t)),g=(t)=>Uint8Array.from(atob(t),(o)=>o.charCodeAt(0));function Q(t){let o=t===0?"":`_${t}`;return{cid:`swapkit_passkey_cid${o}`,phrase:`swapkit_passkey_phrase${o}`}}function Z(t){return t.getClientExtensionResults()?.prf?.results?.first}async function $(){let{generateMnemonic:t}=await import("@scure/bip39"),{wordlist:o}=await import("@scure/bip39/wordlists/english.js");return t(o,256)}async function m(t){let o=await crypto.subtle.importKey("raw",t,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({hash:"SHA-256",info:new TextEncoder().encode("storage"),name:"HKDF",salt:O},o,{length:256,name:"AES-GCM"},!1,["encrypt","decrypt"])}async function L(t,o){let n=await m(t),l=crypto.getRandomValues(new Uint8Array(12)),S=new Uint8Array(await crypto.subtle.encrypt({iv:l,name:"AES-GCM"},n,new TextEncoder().encode(o))),s=new Uint8Array(l.length+S.length);return s.set(l),s.set(S,l.length),W(s)}async function k(t,o){let n=await m(t),l=g(o),S=l.slice(0,12),s=l.slice(12),C=await crypto.subtle.decrypt({iv:S,name:"AES-GCM"},n,s);return new TextDecoder().decode(C)}async function v(t,o,n,l){let S=await navigator.credentials.create({publicKey:{authenticatorSelection:{authenticatorAttachment:"platform",residentKey:"required",userVerification:"required"},challenge:crypto.getRandomValues(new Uint8Array(32)),extensions:{prf:{}},pubKeyCredParams:[{alg:-7,type:"public-key"},{alg:-257,type:"public-key"}],rp:{id:t,name:o},user:{displayName:l===0?`${o} Passkey Wallet`:`${o} Passkey Wallet #${l}`,id:crypto.getRandomValues(new Uint8Array(16)),name:`swapkit-${l}-${Date.now()}`}}});if(!S||!S.getClientExtensionResults()?.prf?.enabled)return null;return localStorage.setItem(n,W(new Uint8Array(S.rawId))),S.rawId}async function M(t,o,n){let l={challenge:crypto.getRandomValues(new Uint8Array(32)),extensions:{prf:{eval:{first:O}}},rpId:t,userVerification:"required"};if(n)l.allowCredentials=[{id:n,type:"public-key"}];let S=await navigator.credentials.get({publicKey:l});if(!S)return null;return localStorage.setItem(o,W(new Uint8Array(S.rawId))),Z(S)??null}function i(t="SwapKit",o=0){let n=Q(o);return{get available(){return typeof globalThis.PublicKeyCredential<"u"&&typeof globalThis.navigator<"u"&&typeof globalThis.localStorage<"u"&&typeof globalThis.crypto<"u"},async connect(l){let S=await this.prfAuth();if(!S)throw new _.SwapKitError("wallet_passkey_connection_failed");if(l){let{validateMnemonic:P}=await import("@scure/bip39"),{wordlist:w}=await import("@scure/bip39/wordlists/english.js");if(!P(l,w))throw new _.SwapKitError("wallet_passkey_connection_failed");return localStorage.setItem(n.phrase,await L(S,l)),l}let s=localStorage.getItem(n.phrase);if(s)return k(S,s);let C=await $();return localStorage.setItem(n.phrase,await L(S,C)),C},disconnect(){if(typeof globalThis.localStorage>"u")return;localStorage.removeItem(n.cid),localStorage.removeItem(n.phrase)},async prfAuth(){if(!this.available)throw new _.SwapKitError("wallet_passkey_not_supported");let l=globalThis.location?.hostname??"localhost",S=localStorage.getItem(n.cid),s=S?g(S):await v(l,t,n.cid,o);if(!s)throw new _.SwapKitError("wallet_passkey_connection_failed");return M(l,n.cid,s)}}}var R=[...a.EVMChains,...a.UTXOChains,...a.CosmosChains.filter((t)=>t!==a.Chain.Harbor),a.Chain.Aptos,a.Chain.Cardano,a.Chain.Ripple,a.Chain.Solana,a.Chain.Stellar,a.Chain.Sui,a.Chain.Ton,a.Chain.Tron,a.Chain.Near,a.Chain.HyperCore],E=u.createWallet({connect:({addChain:t})=>async function(n,l){let{phrase:S,index:s=0}=l??{},C=a.SKConfig.get("integrations").passkey?.rpName||"SwapKit",P=i(C,s);if(!P.available)throw new a.SwapKitError("wallet_passkey_not_supported");let w=await P.connect(S);if(!w)throw new a.SwapKitError("wallet_passkey_connection_failed");let U=a.filterSupportedChains({chains:n,supportedChains:D,walletType:a.WalletOption.PASSKEY_WALLET});return await Promise.all(U.map(async(A)=>{let{getToolbox:p}=await import("@swapkit/toolboxes"),h=a.updateDerivationPath(a.NetworkDerivationPath[A].slice(0,A===a.Chain.Solana?4:5),{index:s}),Y=await p(A,{derivationPath:h,phrase:w}),V=await Y.getAddress()||"";t({...Y,address:V,chain:A,walletType:a.WalletOption.PASSKEY_WALLET})})),!0},directSigningSupport:Object.fromEntries(R.map((t)=>[t,!0])),name:"connectPasskeyWallet",supportedChains:[...R],walletType:a.WalletOption.PASSKEY_WALLET}),D=u.getWalletSupportedChains(E);
|
package/package.json
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-dev",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@swapkit/helpers": "workspace:*",
|
|
5
|
-
"@swapkit/toolboxes": "workspace:*",
|
|
6
|
-
"@swapkit/wallet-core": "workspace:*"
|
|
7
|
-
},
|
|
3
|
+
"dependencies": { "@swapkit/helpers": "4.13.8", "@swapkit/toolboxes": "4.15.12", "@swapkit/wallet-core": "4.2.8" },
|
|
8
4
|
"description": "SwapKit - Passkey Wallet",
|
|
9
5
|
"exports": {
|
|
10
6
|
".": {
|
|
@@ -18,13 +14,9 @@
|
|
|
18
14
|
"homepage": "https://github.com/swapkit/SwapKit",
|
|
19
15
|
"license": "SEE LICENSE IN LICENSE",
|
|
20
16
|
"name": "@swapkit/passkey",
|
|
21
|
-
"peerDependencies": { "@scure/bip39": "
|
|
17
|
+
"peerDependencies": { "@scure/bip39": "2.2.0" },
|
|
22
18
|
"publishConfig": { "access": "public" },
|
|
23
|
-
"repository": {
|
|
24
|
-
"directory": "packages/passkey",
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/swapkit/SwapKit.git"
|
|
27
|
-
},
|
|
19
|
+
"repository": { "directory": "packages/passkey", "type": "git", "url": "git+https://github.com/swapkit/SwapKit.git" },
|
|
28
20
|
"scripts": {
|
|
29
21
|
"build": "bun run ./build.ts",
|
|
30
22
|
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
@@ -33,5 +25,5 @@
|
|
|
33
25
|
"type-check:go": "tsgo"
|
|
34
26
|
},
|
|
35
27
|
"type": "module",
|
|
36
|
-
"version": "0.1.
|
|
28
|
+
"version": "0.1.2"
|
|
37
29
|
}
|