Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stacks/connect

Package Overview
Dependencies
Maintainers
4
Versions
703
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stacks/connect - npm Package Compare versions

Comparing version 7.3.2-alpha.432e87f.0 to 7.3.2-alpha.455575e.0

44

dist/index.js

@@ -9,12 +9,12 @@ 'use strict';

var N=Object.defineProperty,M=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var k=(t,e,n)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,i=(t,e)=>{for(var n in e||(e={}))D.call(e,n)&&k(t,n,e[n]);if(P)for(var n of P(e))R.call(e,n)&&k(t,n,e[n]);return t},p=(t,e)=>M(t,L(e));var f=(t,e)=>{var n={};for(var r in t)D.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&P)for(var r of P(t))e.indexOf(r)<0&&R.call(t,r)&&(n[r]=t[r]);return n};function d(){return window.StacksProvider||window.BlockstackProvider}function Ht(){return !!d()}var jt="https://app.blockstack.org",U="7.3.2-alpha.432e87f.0";typeof window!="undefined"&&(window.__CONNECT_VERSION__=U);var H=()=>{let t=navigator.userAgent;return /android/i.test(t)||/iPad|iPhone|iPod/.test(t)?!0:/windows phone/i.test(t)},Qt=()=>!H(),B=t=>{if(!t){let e=new auth.AppConfig(["store_write"],document.location.href);t=new auth.UserSession({appConfig:e});}return t},A=async t=>{let e=d();if(!e)throw new Error("Unable to authenticate without Hiro Wallet extension");let{redirectTo:n="/",manifestPath:r,onFinish:s,onCancel:o,sendToSignIn:a=!1,userSession:c,appDetails:u}=t,l=B(c);l.isUserSignedIn()&&l.signUserOut();let m=l.generateAndStoreTransitKey(),$=l.makeAuthRequest(m,`${document.location.origin}${n}`,`${document.location.origin}${r}`,l.appConfig.scopes,void 0,void 0,{sendToSignIn:a,appDetails:u,connectVersion:U});try{let T=await e.authenticationRequest($);await l.handlePendingSignIn(T);let h=jsontokens.decodeToken(T),X=h==null?void 0:h.payload;s==null||s({authResponse:T,authResponsePayload:X,userSession:l});}catch(T){console.error("[Connect] Error during auth request",T),o==null||o();}},Zt=async t=>(t=B(t),t.isUserSignedIn()?t.loadUserData():t.isSignInPending()?t.handlePendingSignIn():null);var J=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function S(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let n of t)e+=J[n];return e}function I(t){if(typeof t!="string")throw new TypeError(`hexToBytes: expected string, got ${typeof t}`);let e=t.length%2?`0${t}`:t,n=new Uint8Array(e.length/2);for(let r=0;r<n.length;r++){let s=r*2,o=e.slice(s,s+2),a=Number.parseInt(o,16);if(Number.isNaN(a)||a<0)throw new Error("Invalid byte sequence");n[r]=a;}return n}var z=(r=>(r.ContractCall="contract_call",r.ContractDeploy="smart_contract",r.STXTransfer="token_transfer",r))(z||{}),Y=(o=>(o.BUFFER="buffer",o.UINT="uint",o.INT="int",o.PRINCIPAL="principal",o.BOOL="bool",o))(Y||{});var x=t=>{let e=t;if(!e){let n=new auth.AppConfig(["store_write"],document.location.href);e=new auth.UserSession({appConfig:n});}return e};function g(t){try{return x(t).loadUserData().appPrivateKey}catch(e){return !1}}var y=t=>{let n=x(t).loadUserData().appPrivateKey,r=jsontokens.SECP256K1Client.derivePublicKey(n);return {privateKey:n,publicKey:r}};function st(t){var c;let{stxAddress:e,userSession:n,network:r}=t;if(e)return e;if(!n||!r)return;let s=(c=n==null?void 0:n.loadUserData().profile)==null?void 0:c.stxAddress,o={[transactions.ChainID.Mainnet]:"mainnet",[transactions.ChainID.Testnet]:"testnet"};return s==null?void 0:s[o[r.chainId]]}function it(t){let e=t.network||new network.StacksTestnet,n=x(t.userSession),r=p(i({},t),{network:e,userSession:n});return i({stxAddress:st(r)},r)}function E(t){return t.map(e=>S(transactions.serializePostCondition(e)))}async function C(t,e){let{postConditions:n}=t;return n&&typeof n[0]!="string"&&(n=E(n)),new jsontokens.TokenSigner("ES256k",e).signAsync(p(i({},t),{postConditions:n}))}function w(t){let{postConditions:e}=t;return e&&typeof e[0]!="string"&&(e=E(e)),jsontokens.createUnsecuredToken(p(i({},t),{postConditions:e}))}var at=async({token:t,options:e})=>{var r,s,o;let n=d();if(!n)throw new Error("Hiro Wallet not installed");try{let a=await n.transactionRequest(t),{txRaw:c}=a,u=I(c.replace(/^0x/,"")),l=transactions.deserializeTransaction(u);if("sponsored"in e&&e.sponsored){(r=e.onFinish)==null||r.call(e,p(i({},a),{stacksTransaction:l}));return}(s=e.onFinish)==null||s.call(e,p(i({},a),{stacksTransaction:l}));}catch(a){console.error("[Connect] Error during transaction request",a),(o=e.onCancel)==null||o.call(e);}},pt=async t=>{let c=t,{functionArgs:e,appDetails:n,userSession:r}=c,s=f(c,["functionArgs","appDetails","userSession"]),o=e.map(u=>typeof u=="string"?u:S(transactions.serializeCV(u)));if(g(r)){let{privateKey:u,publicKey:l}=y(r),m=p(i({},s),{functionArgs:o,txType:"contract_call",publicKey:l});return n&&(m.appDetails=n),C(m,u)}let a=p(i({},s),{functionArgs:o,txType:"contract_call"});return n&&(a.appDetails=n),w(a)},ct=async t=>{let o=t,{appDetails:e,userSession:n}=o,r=f(o,["appDetails","userSession"]);if(g(n)){let{privateKey:a,publicKey:c}=y(n),u=p(i({},r),{publicKey:c,txType:"smart_contract"});return e&&(u.appDetails=e),C(u,a)}let s=p(i({},r),{txType:"smart_contract"});return e&&(s.appDetails=e),w(s)},ut=async t=>{let a=t,{amount:e,appDetails:n,userSession:r}=a,s=f(a,["amount","appDetails","userSession"]);if(g(r)){let{privateKey:c,publicKey:u}=y(r),l=p(i({},s),{amount:e.toString(10),publicKey:u,txType:"token_transfer"});return n&&(l.appDetails=n),C(l,c)}let o=p(i({},s),{amount:e.toString(10),txType:"token_transfer"});return n&&(o.appDetails=n),w(o)};async function O(t,e){let n=await e(i(i({},it(t)),t));return at({token:n,options:t})}function le(t){return O(t,pt)}function de(t){return O(t,ct)}function fe(t){return O(t,ut)}async function gt(t,e){return new jsontokens.TokenSigner("ES256k",e).signAsync(i({},t))}function yt(t){let e=t.network||new network.StacksTestnet,n=x(t.userSession),r=p(i({},t),{network:e,userSession:n});return i({},r)}async function xt({token:t,options:e}){var r,s;let n=d();if(!n)throw new Error("Hiro Wallet not installed");try{let o=await n.psbtRequest(t);(r=e.onFinish)==null||r.call(e,o);}catch(o){console.error("[Connect] Error during psbt request",o),(s=e.onCancel)==null||s.call(e);}}var mt=async t=>{let c=t,{allowedSighash:e,hex:n,signAtIndex:r,userSession:s}=c,o=f(c,["allowedSighash","hex","signAtIndex","userSession"]);if(g(s)){let{privateKey:u,publicKey:l}=y(s),m=p(i({},o),{allowedSighash:e,hex:n,signAtIndex:r,publicKey:l});return gt(m,u)}let a=i({},o);return jsontokens.createUnsecuredToken(a)};async function St(t,e){let n=await e(i(i({},yt(t)),t));return xt({token:n,options:t})}function he(t){return St(t,mt)}function Ct(t){var a;let{userSession:e,network:n}=t;if(!e||!n)return;let r=(a=e==null?void 0:e.loadUserData().profile)==null?void 0:a.stxAddress,s={[transactions.ChainID.Mainnet]:"mainnet",[transactions.ChainID.Testnet]:"testnet"};return r==null?void 0:r[s[n.chainId]]}async function wt(t,e){return new jsontokens.TokenSigner("ES256k",e).signAsync(i({},t))}function b(t){let e=t.network||new network.StacksTestnet,n=x(t.userSession),r=p(i({},t),{network:e,userSession:n});return i({stxAddress:Ct(r)},r)}async function Ot({token:t,options:e}){var r,s;let n=d();if(!n)throw new Error("Hiro Wallet not installed.");try{let o=await n.signatureRequest(t);(r=e.onFinish)==null||r.call(e,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=e.onCancel)==null||s.call(e);}}var bt=async t=>{let s=t,{userSession:e}=s,n=f(s,["userSession"]);if(g(e)){let{privateKey:o,publicKey:a}=y(e),c=p(i({},n),{publicKey:a});return wt(c,o)}let r=i({},n);return jsontokens.createUnsecuredToken(r)};async function kt(t,e){let n=await e(i(i({},b(t)),t));return Ot({token:n,options:t})}function Ue(t){return kt(t,bt)}async function Ut(t,e){let n=await e(i(i({},b(t)),t));return It({token:n,options:t})}function F(t){return p(i({},t),{message:S(transactions.serializeCV(t.message)),domain:S(transactions.serializeCV(t.domain))})}async function Bt(t,e){return new jsontokens.TokenSigner("ES256k",e).signAsync(F(t))}async function At(t){let r=t,{userSession:e}=r,n=f(r,["userSession"]);if(g(e)){let{privateKey:s,publicKey:o}=y(e),a=p(i({},n),{publicKey:o});return Bt(a,s)}return jsontokens.createUnsecuredToken(F(t))}async function It({token:t,options:e}){var r,s;let n=d();if(!n)throw new Error("Hiro Wallet not installed.");try{let o=await n.structuredDataSignatureRequest(t);(r=e.onFinish)==null||r.call(e,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=e.onCancel)==null||s.call(e);}}function $e(t){return Ut(t,At)}async function Kt(t,e){return new jsontokens.TokenSigner("ES256k",e).signAsync(i({},t))}function Ft(t){let e=t.network||new network.StacksTestnet,n=x(t.userSession),r=p(i({},t),{network:e,userSession:n});return i({},r)}async function $t({token:t,options:e}){var r,s;let n=d();if(!n)throw new Error("Hiro Wallet not installed.");try{let o=await n.profileUpdateRequest(t);(r=e.onFinish)==null||r.call(e,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=e.onCancel)==null||s.call(e);}}var Xt=async t=>{let o=t,{userSession:e,profile:n}=o,r=f(o,["userSession","profile"]);if(g(e)){let{privateKey:a,publicKey:c}=y(e),u=p(i({},r),{profile:n,publicKey:c});return Kt(u,a)}let s=i({},r);return jsontokens.createUnsecuredToken(s)};async function Nt(t,e){let n=await e(i(i({},Ft(t)),t));return $t({token:n,options:t})}function He(t){return Nt(t,Xt)}var Mt=(o=>(o[o.DEFAULT=0]="DEFAULT",o[o.ALL=1]="ALL",o[o.NONE=2]="NONE",o[o.SINGLE=3]="SINGLE",o[o.ANYONECANPAY=128]="ANYONECANPAY",o))(Mt||{});var _t=t=>{if(d()){A(t);return}if(typeof window!==void 0){loader.defineCustomElements(window);let e=document.createElement("connect-modal");e.authOptions=t,document.body.appendChild(e);let n=r=>{r.key==="Escape"&&(document.removeEventListener("keydown",n),e.remove());};document.addEventListener("keydown",n);}},Ze=t=>_t(t);
var X=Object.defineProperty,_=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var b=(e,t,n)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,i=(e,t)=>{for(var n in t||(t={}))D.call(t,n)&&b(e,n,t[n]);if(T)for(var n of T(t))A.call(t,n)&&b(e,n,t[n]);return e},c=(e,t)=>_(e,L(t));var f=(e,t)=>{var n={};for(var r in e)D.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&T)for(var r of T(e))t.indexOf(r)<0&&A.call(e,r)&&(n[r]=e[r]);return n};function d(){return window.StacksProvider||window.BlockstackProvider}function Jt(){return !!d()}var Qt="https://app.blockstack.org",R="7.3.2-alpha.455575e.0";typeof window!="undefined"&&(window.__CONNECT_VERSION__=R);var J=()=>{let e=navigator.userAgent;return /android/i.test(e)||/iPad|iPhone|iPod/.test(e)?!0:/windows phone/i.test(e)},Zt=()=>!J(),B=e=>{if(!e){let t=new auth.AppConfig(["store_write"],document.location.href);e=new auth.UserSession({appConfig:t});}return e},U=async(e,t=d())=>{if(!t)throw new Error("[Connect] No installed Stacks wallet found");let{redirectTo:n="/",manifestPath:r,onFinish:s,onCancel:o,sendToSignIn:a=!1,userSession:p,appDetails:u}=e,l=B(p);l.isUserSignedIn()&&l.signUserOut();let S=l.generateAndStoreTransitKey(),$=l.makeAuthRequest(S,`${document.location.origin}${n}`,`${document.location.origin}${r}`,l.appConfig.scopes,void 0,void 0,{sendToSignIn:a,appDetails:u,connectVersion:R});try{let P=await t.authenticationRequest($);await l.handlePendingSignIn(P);let h=jsontokens.decodeToken(P),F=h==null?void 0:h.payload;s==null||s({authResponse:P,authResponsePayload:F,userSession:l});}catch(P){console.error("[Connect] Error during auth request",P),o==null||o();}},Ht=async e=>(e=B(e),e.isUserSignedIn()?e.loadUserData():e.isSignInPending()?e.handlePendingSignIn():null);var z=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function m(e){if(!(e instanceof Uint8Array))throw new Error("Uint8Array expected");let t="";for(let n of e)t+=z[n];return t}function I(e){if(typeof e!="string")throw new TypeError(`hexToBytes: expected string, got ${typeof e}`);let t=e.length%2?`0${e}`:e,n=new Uint8Array(t.length/2);for(let r=0;r<n.length;r++){let s=r*2,o=t.slice(s,s+2),a=Number.parseInt(o,16);if(Number.isNaN(a)||a<0)throw new Error("Invalid byte sequence");n[r]=a;}return n}var G=(r=>(r.ContractCall="contract_call",r.ContractDeploy="smart_contract",r.STXTransfer="token_transfer",r))(G||{}),W=(o=>(o.BUFFER="buffer",o.UINT="uint",o.INT="int",o.PRINCIPAL="principal",o.BOOL="bool",o))(W||{});var x=e=>{let t=e;if(!t){let n=new auth.AppConfig(["store_write"],document.location.href);t=new auth.UserSession({appConfig:n});}return t};function g(e){try{return x(e).loadUserData().appPrivateKey}catch(t){return !1}}var y=e=>{let n=x(e).loadUserData().appPrivateKey,r=jsontokens.SECP256K1Client.derivePublicKey(n);return {privateKey:n,publicKey:r}};function st(e){var p;let{stxAddress:t,userSession:n,network:r}=e;if(t)return t;if(!n||!r)return;let s=(p=n==null?void 0:n.loadUserData().profile)==null?void 0:p.stxAddress,o={[transactions.ChainID.Mainnet]:"mainnet",[transactions.ChainID.Testnet]:"testnet"};return s==null?void 0:s[o[r.chainId]]}function at(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(i({},e),{network:t,userSession:n});return i({stxAddress:st(r)},r)}function E(e){return e.map(t=>m(transactions.serializePostCondition(t)))}async function C(e,t){let{postConditions:n}=e;return n&&typeof n[0]!="string"&&(n=E(n)),new jsontokens.TokenSigner("ES256k",t).signAsync(c(i({},e),{postConditions:n}))}function w(e){let{postConditions:t}=e;return t&&typeof t[0]!="string"&&(t=E(t)),jsontokens.createUnsecuredToken(c(i({},e),{postConditions:t}))}var it=async({token:e,options:t},n)=>{var r,s,o;try{let a=await n.transactionRequest(e),{txRaw:p}=a,u=I(p.replace(/^0x/,"")),l=transactions.deserializeTransaction(u);if("sponsored"in t&&t.sponsored){(r=t.onFinish)==null||r.call(t,c(i({},a),{stacksTransaction:l}));return}(s=t.onFinish)==null||s.call(t,c(i({},a),{stacksTransaction:l}));}catch(a){console.error("[Connect] Error during transaction request",a),(o=t.onCancel)==null||o.call(t);}},ct=async e=>{let p=e,{functionArgs:t,appDetails:n,userSession:r}=p,s=f(p,["functionArgs","appDetails","userSession"]),o=t.map(u=>typeof u=="string"?u:m(transactions.serializeCV(u)));if(g(r)){let{privateKey:u,publicKey:l}=y(r),S=c(i({},s),{functionArgs:o,txType:"contract_call",publicKey:l});return n&&(S.appDetails=n),C(S,u)}let a=c(i({},s),{functionArgs:o,txType:"contract_call"});return n&&(a.appDetails=n),w(a)},pt=async e=>{let o=e,{appDetails:t,userSession:n}=o,r=f(o,["appDetails","userSession"]);if(g(n)){let{privateKey:a,publicKey:p}=y(n),u=c(i({},r),{publicKey:p,txType:"smart_contract"});return t&&(u.appDetails=t),C(u,a)}let s=c(i({},r),{txType:"smart_contract"});return t&&(s.appDetails=t),w(s)},ut=async e=>{let a=e,{amount:t,appDetails:n,userSession:r}=a,s=f(a,["amount","appDetails","userSession"]);if(g(r)){let{privateKey:p,publicKey:u}=y(r),l=c(i({},s),{amount:t.toString(10),publicKey:u,txType:"token_transfer"});return n&&(l.appDetails=n),C(l,p)}let o=c(i({},s),{amount:t.toString(10),txType:"token_transfer"});return n&&(o.appDetails=n),w(o)};async function k(e,t,n){let r=await t(i(i({},at(e)),e));return it({token:r,options:e},n)}function le(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return k(e,ct,t)}function de(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return k(e,pt,t)}function fe(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return k(e,ut,t)}async function gt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(i({},e))}function yt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(i({},e),{network:t,userSession:n});return i({},r)}async function xt({token:e,options:t},n){var r,s;if(!n)throw new Error("[Connect] No installed Stacks wallet found");try{let o=await n.psbtRequest(e);(r=t.onFinish)==null||r.call(t,o);}catch(o){console.error("[Connect] Error during psbt request",o),(s=t.onCancel)==null||s.call(t);}}var St=async e=>{let p=e,{allowedSighash:t,hex:n,signAtIndex:r,userSession:s}=p,o=f(p,["allowedSighash","hex","signAtIndex","userSession"]);if(g(s)){let{privateKey:u,publicKey:l}=y(s),S=c(i({},o),{allowedSighash:t,hex:n,signAtIndex:r,publicKey:l});return gt(S,u)}let a=i({},o);return jsontokens.createUnsecuredToken(a)};async function mt(e,t,n){let r=await t(i(i({},yt(e)),e));return xt({token:r,options:e},n)}function he(e,t=d()){return mt(e,St,t)}function Ct(e){var a;let{userSession:t,network:n}=e;if(!t||!n)return;let r=(a=t==null?void 0:t.loadUserData().profile)==null?void 0:a.stxAddress,s={[transactions.ChainID.Mainnet]:"mainnet",[transactions.ChainID.Testnet]:"testnet"};return r==null?void 0:r[s[n.chainId]]}async function wt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(i({},e))}function O(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(i({},e),{network:t,userSession:n});return i({stxAddress:Ct(r)},r)}async function kt({token:e,options:t},n){var r,s;try{let o=await n.signatureRequest(e);(r=t.onFinish)==null||r.call(t,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=t.onCancel)==null||s.call(t);}}var Ot=async e=>{let s=e,{userSession:t}=s,n=f(s,["userSession"]);if(g(t)){let{privateKey:o,publicKey:a}=y(t),p=c(i({},n),{publicKey:a});return wt(p,o)}let r=i({},n);return jsontokens.createUnsecuredToken(r)};async function bt(e,t,n){let r=await t(i(i({},O(e)),e));return kt({token:r,options:e},n)}function Re(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return bt(e,Ot,t)}async function Rt(e,t,n){let r=await t(i(i({},O(e)),e));return It({token:r,options:e},n)}function K(e){return c(i({},e),{message:m(transactions.serializeCV(e.message)),domain:m(transactions.serializeCV(e.domain))})}async function Bt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(K(e))}async function Ut(e){let r=e,{userSession:t}=r,n=f(r,["userSession"]);if(g(t)){let{privateKey:s,publicKey:o}=y(t),a=c(i({},n),{publicKey:o});return Bt(a,s)}return jsontokens.createUnsecuredToken(K(e))}async function It({token:e,options:t},n){var r,s;try{let o=await n.structuredDataSignatureRequest(e);(r=t.onFinish)==null||r.call(t,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=t.onCancel)==null||s.call(t);}}function $e(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Rt(e,Ut,t)}async function Nt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(i({},e))}function Kt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(i({},e),{network:t,userSession:n});return i({},r)}async function $t({token:e,options:t},n){var r,s;try{let o=await n.profileUpdateRequest(e);(r=t.onFinish)==null||r.call(t,o);}catch(o){console.error("[Connect] Error during signature request",o),(s=t.onCancel)==null||s.call(t);}}var Ft=async e=>{let o=e,{userSession:t,profile:n}=o,r=f(o,["userSession","profile"]);if(g(t)){let{privateKey:a,publicKey:p}=y(t),u=c(i({},r),{profile:n,publicKey:p});return Nt(u,a)}let s=i({},r);return jsontokens.createUnsecuredToken(s)};async function Xt(e,t,n){let r=await t(i(i({},Kt(e)),e));return $t({token:r,options:e},n)}function Je(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Xt(e,Ft,t)}var _t=(a=>(a[a.ALL=1]="ALL",a[a.NONE=2]="NONE",a[a.SINGLE=3]="SINGLE",a[a.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",a[a.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",a[a.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY",a))(_t||{});var Mt=(e,t=d())=>{if(t){U(e,t);return}if(typeof window!==void 0){loader.defineCustomElements(window);let n=document.createElement("connect-modal");n.authOptions=e,document.body.appendChild(n);let r=s=>{s.key==="Escape"&&(document.removeEventListener("keydown",r),n.remove());};document.addEventListener("keydown",r);}},He=e=>Mt(e);
exports.ContractCallArgumentType = Y;
exports.SignatureHash = Mt;
exports.TransactionTypes = z;
exports.authenticate = A;
exports.defaultAuthURL = jt;
exports.getDefaultProfileUpdateRequestOptions = Ft;
exports.ContractCallArgumentType = W;
exports.SignatureHash = _t;
exports.TransactionTypes = G;
exports.authenticate = U;
exports.defaultAuthURL = Qt;
exports.getDefaultProfileUpdateRequestOptions = Kt;
exports.getDefaultPsbtRequestOptions = yt;
exports.getDefaultSignatureRequestOptions = b;
exports.getDefaultSignatureRequestOptions = O;
exports.getKeys = y;

@@ -24,24 +24,24 @@ exports.getOrCreateUserSession = B;

exports.getStxAddress = st;
exports.getUserData = Zt;
exports.getUserData = Ht;
exports.getUserSession = x;
exports.hasAppPrivateKey = g;
exports.isMobile = H;
exports.isStacksWalletInstalled = Ht;
exports.makeContractCallToken = pt;
exports.makeContractDeployToken = ct;
exports.makeProfileUpdateToken = Xt;
exports.makePsbtToken = mt;
exports.isMobile = J;
exports.isStacksWalletInstalled = Jt;
exports.makeContractCallToken = ct;
exports.makeContractDeployToken = pt;
exports.makeProfileUpdateToken = Ft;
exports.makePsbtToken = St;
exports.makeSTXTransferToken = ut;
exports.openContractCall = le;
exports.openContractDeploy = de;
exports.openProfileUpdateRequestPopup = He;
exports.openProfileUpdateRequestPopup = Je;
exports.openPsbtRequestPopup = he;
exports.openSTXTransfer = fe;
exports.openSignatureRequestPopup = Ue;
exports.openSignatureRequestPopup = Re;
exports.openStructuredDataSignatureRequestPopup = $e;
exports.shouldUsePopup = Qt;
exports.showBlockstackConnect = Ze;
exports.showConnect = _t;
exports.signMessage = bt;
exports.signStructuredMessage = At;
exports.shouldUsePopup = Zt;
exports.showBlockstackConnect = He;
exports.showConnect = Mt;
exports.signMessage = Ot;
exports.signStructuredMessage = Ut;
Object.keys(auth).forEach(function (k) {

@@ -48,0 +48,0 @@ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {

import { UserSession } from '@stacks/auth';
import type { AuthOptions } from './types';
import type { AuthOptions, StacksProvider } from './types';
export declare const defaultAuthURL = "https://app.blockstack.org";

@@ -10,3 +10,3 @@ export declare const isMobile: () => boolean;

export declare const getOrCreateUserSession: (userSession?: UserSession) => UserSession;
export declare const authenticate: (authOptions: AuthOptions) => Promise<void>;
export declare const authenticate: (authOptions: AuthOptions, provider?: StacksProvider) => Promise<void>;
export declare const getUserData: (userSession?: UserSession) => Promise<import("@stacks/auth").UserData>;
import { PsbtRequestOptions } from '../types/bitcoin';
import { StacksProvider } from '../types';
export declare function getDefaultPsbtRequestOptions(options: PsbtRequestOptions): {
allowedSighash?: import("../types/bitcoin").SignatureHash[];
allowedSighash?: import("../types").SignatureHash[];
hex: string;

@@ -12,4 +13,4 @@ signAtIndex?: number | number[];

network?: import("@stacks/network").StacksNetwork;
onCancel?: import("../types/bitcoin").PsbtCanceled;
onFinish?: import("../types/bitcoin").PsbtFinished;
onCancel?: import("../types").PsbtCanceled;
onFinish?: import("../types").PsbtFinished;
stxAddress?: string;

@@ -22,2 +23,2 @@ userSession?: import("@stacks/auth").UserSession;

*/
export declare function openPsbtRequestPopup(options: PsbtRequestOptions): Promise<void>;
export declare function openPsbtRequestPopup(options: PsbtRequestOptions, provider?: StacksProvider): Promise<void>;

@@ -1,2 +0,2 @@

import { ProfileUpdateRequestOptions } from '../types';
import { ProfileUpdateRequestOptions, StacksProvider } from '../types';
export declare function getDefaultProfileUpdateRequestOptions(options: ProfileUpdateRequestOptions): {

@@ -16,2 +16,2 @@ profile: import("@stacks/profile").PublicPersonProfile;

export declare const makeProfileUpdateToken: (options: ProfileUpdateRequestOptions) => Promise<string>;
export declare function openProfileUpdateRequestPopup(options: ProfileUpdateRequestOptions): Promise<void>;
export declare function openProfileUpdateRequestPopup(options: ProfileUpdateRequestOptions, provider?: StacksProvider): Promise<void>;
import { CommonSignatureRequestOptions, SignatureRequestOptions } from '../types/signature';
import { StacksProvider } from '../types';
export declare function getDefaultSignatureRequestOptions(options: CommonSignatureRequestOptions): {

@@ -11,4 +12,4 @@ appDetails?: {

userSession?: import("@stacks/auth").UserSession;
onFinish?: import("../types/signature").SignatureFinished;
onCancel?: import("../types/signature").SignatureCanceled;
onFinish?: import("../types").SignatureFinished;
onCancel?: import("../types").SignatureCanceled;
};

@@ -19,2 +20,2 @@ export interface SignatureRequestPayload {

export declare const signMessage: (options: SignatureRequestOptions) => Promise<string>;
export declare function openSignatureRequestPopup(options: SignatureRequestOptions): Promise<void>;
export declare function openSignatureRequestPopup(options: SignatureRequestOptions, provider?: StacksProvider): Promise<void>;
import { StructuredDataSignatureRequestOptions } from '../types/structuredDataSignature';
import { StacksProvider } from '../types';
export declare function signStructuredMessage(options: StructuredDataSignatureRequestOptions): Promise<string>;
export declare function openStructuredDataSignatureRequestPopup(options: StructuredDataSignatureRequestOptions): Promise<void>;
export declare function openStructuredDataSignatureRequestPopup(options: StructuredDataSignatureRequestOptions, provider?: StacksProvider): Promise<void>;
import { UserSession } from '@stacks/auth';
import { ContractCallOptions, ContractCallRegularOptions, ContractCallSponsoredOptions, ContractDeployOptions, ContractDeployRegularOptions, ContractDeploySponsoredOptions, STXTransferOptions, STXTransferRegularOptions, STXTransferSponsoredOptions, TransactionOptions } from '../types/transactions';
import { StacksProvider } from '../types';
export declare const getUserSession: (_userSession?: UserSession) => UserSession;

@@ -13,10 +14,4 @@ export declare function hasAppPrivateKey(userSession?: UserSession): string | false;

export declare const makeSTXTransferToken: (options: STXTransferOptions) => Promise<string>;
export declare function openContractCall(options: ContractCallRegularOptions): Promise<void>;
export declare function openContractCall(options: ContractCallSponsoredOptions): Promise<void>;
export declare function openContractCall(options: ContractCallOptions): Promise<void>;
export declare function openContractDeploy(options: ContractDeployRegularOptions): Promise<void>;
export declare function openContractDeploy(options: ContractDeploySponsoredOptions): Promise<void>;
export declare function openContractDeploy(options: ContractDeployOptions): Promise<void>;
export declare function openSTXTransfer(options: STXTransferRegularOptions): Promise<void>;
export declare function openSTXTransfer(options: STXTransferSponsoredOptions): Promise<void>;
export declare function openSTXTransfer(options: STXTransferOptions): Promise<void>;
export declare function openContractCall(options: ContractCallOptions | ContractCallRegularOptions | ContractCallSponsoredOptions, provider?: StacksProvider): Promise<void>;
export declare function openContractDeploy(options: ContractDeployOptions | ContractDeployRegularOptions | ContractDeploySponsoredOptions, provider?: StacksProvider): Promise<void>;
export declare function openSTXTransfer(options: STXTransferOptions | STXTransferRegularOptions | STXTransferSponsoredOptions, provider?: StacksProvider): Promise<void>;
import { UserSession } from '@stacks/auth';
import { StacksNetwork } from '@stacks/network';
import { AuthOptions } from './auth';
/**
* ALL -- all inputs, all outputs
* NONE -- all inputs, no outputs
* SINGLE -- all inputs, one output of the same index
* ALL + ANYONE -- one input, all outputs
* NONE + ANYONE -- one input, no outputs
* SINGLE -- one inputs, one output of the same index
*/
export declare enum SignatureHash {
DEFAULT = 0,
ALL = 1,
NONE = 2,
SINGLE = 3,
ANYONECANPAY = 128
ALL_ANYONECANPAY = 129,
NONE_ANYONECANPAY = 130,
SINGLE_ANYONECANPAY = 131
}

@@ -11,0 +20,0 @@ export interface PsbtData {

import type { AuthOptions } from './types/auth';
export declare const showConnect: (authOptions: AuthOptions) => void;
import { StacksProvider } from './types';
export declare const showConnect: (authOptions: AuthOptions, provider?: StacksProvider) => void;
/**

@@ -4,0 +5,0 @@ * @deprecated Use the renamed `showConnect` method

{
"name": "@stacks/connect",
"version": "7.3.2-alpha.432e87f.0",
"version": "7.3.2-alpha.455575e.0",
"license": "MIT",

@@ -14,3 +14,3 @@ "prettier": "@stacks/prettier-config",

"@stacks/auth": "^6.1.1",
"@stacks/connect-ui": "^6.1.2-alpha.432e87f.0",
"@stacks/connect-ui": "^6.1.2-alpha.455575e.0",
"@stacks/network": "^6.1.1",

@@ -39,3 +39,3 @@ "@stacks/profile": "^6.1.1",

},
"gitHead": "112902cffb5ffe205a18c1cedaaae4178892d57a"
"gitHead": "c905361dae113f6fd8877240e4eee1e5adf56a95"
}

@@ -33,5 +33,5 @@ # `@stacks/connect` [![npm](https://img.shields.io/npm/v/@stacks/connect)](https://www.npmjs.com/package/@stacks/connect) <!-- omit in toc -->

- [Sending STX (`openSTXTransfer`)](#sending-stx-openstxtransfer)
- [Sending transactions with post-conditions (`openSTXTransfer`)](#sending-transactions-with-post-conditions-openstxtransfer)
- [Calling Smart-Contracts (`openContractCall`)](#calling-smart-contracts-opencontractcall)
- [Sending transactions with post-conditions (`openContractCall`)](#sending-transactions-with-post-conditions-opencontractcall)
- [Post-Condition Modes](#post-condition-modes)
- [Calling Smart-Contracts (`openContractCall`)](#calling-smart-contracts-opencontractcall)

@@ -89,2 +89,37 @@ #### "Connect" aka authentication (`showConnect`)

onFinish: response => {
// WHEN user confirms pop-up
console.log(response.txid); // the response includes the txid of the transaction
},
onCancel: () => {
// WHEN user cancels/closes pop-up
console.log('User canceled');
},
});
```
#### Calling Smart-Contracts (`openContractCall`)
Calling smart-contracts lets users interact with the blockchain through transactions.
The snippet below will open the wallet to _confirm and broadcast_ a smart-contract transaction.
Here, we are passing our pick `Alice` to an imaginary deployed voting smart-contract.
```js
import { openContractCall } from '@stacks/connect';
import { StacksTestnet } from '@stacks/network';
import { AnchorMode, PostConditionMode, stringUtf8CV } from '@stacks/transactions';
import { userSession } from './userSession';
const pick = stringUtf8CV('Alice');
openContractCall({
network: new StacksTestnet(),
anchorMode: AnchorMode.Any, // which type of block the tx should be mined in
contractAddress: 'ST39MJ145BR6S8C315AG2BD61SJ16E208P1FDK3AK',
contractName: 'example-contract',
functionName: 'vote',
functionArgs: [pick],
postConditionMode: PostConditionMode.Deny, // whether the tx should fail when unexpected assets are transferred

@@ -95,7 +130,5 @@ postConditions: [], // for an example using post-conditions, see next example

// WHEN user confirms pop-up
console.log(response.txid); // the response includes the txid of the transaction
},
onCancel: () => {
// WHEN user cancels/closes pop-up
console.log('User canceled');
},

@@ -105,3 +138,3 @@ });

#### Sending transactions with post-conditions (`openSTXTransfer`)
#### Sending transactions with post-conditions (`openContractCall`)

@@ -119,10 +152,10 @@ Consider the example above.

// this post-condition ensures that our recipient receives at least 5000 tokens
// this post-condition ensures that our recipient receives at least 5000 STX tokens
const myPostCondition = makeStandardSTXPostCondition(
'ST39MJ145BR6S8C315AG2BD61SJ16E208P1FDK3AK', // address of recipient
FungibleConditionCode.GreaterEqual, // comparator
5000 // relative amount to previous balance
5000000000 // relative amount to previous balance (denoted in micro-STX)
);
// passing to `openSTXTransfer` options, e.g. modifying our previous example ...
// passing to `openContractCall` options, e.g. modifying our previous example ...
postConditionMode: PostConditionMode.Deny, // whether the tx should fail when unexpected assets are transferred

@@ -133,3 +166,3 @@ postConditions: [ myPostCondition ],

> For more examples on constructing different kinds of post-conditions read the [Post-Conditions Guide of Stacks.js](https://github.com/hirosystems/stacks.js/tree/master/packages/transactions#post-conditions).
> For more examples on constructing different kinds of post-conditions read the [Post-Conditions Guide of Stacks.js](https://github.com/hirosystems/stacks.js/tree/main/packages/transactions#post-conditions).

@@ -147,36 +180,17 @@ ##### Post-Condition Modes

#### Calling Smart-Contracts (`openContractCall`)
### 🛠 Advanced <!-- omit in toc -->
Calling smart-contracts lets users interact with the blockchain through transactions.
#### Opening a specific wallet <!-- omit in toc -->
The snippet below will open the wallet to _confirm and broadcast_ a smart-contract transaction.
Here, we are passing our pick `Alice` to an imaginary deployed voting smart-contract.
By default, `@stacks/connect` will defer to the `window.StacksProvider` object to interact with wallets.
However, if multiple wallets are installed, they might interfere with each other.
To avoid this, you can specify which wallet to use in the wallet interaction methods.
```js
import { openContractCall } from '@stacks/connect';
import { StacksTestnet } from '@stacks/network';
import { AnchorMode, PostConditionMode, stringUtf8CV } from '@stacks/transactions';
import { userSession } from './userSession';
const pick = stringUtf8CV('Alice');
openContractCall({
network: new StacksTestnet(),
anchorMode: AnchorMode.Any, // which type of block the tx should be mined in
contractAddress: 'ST39MJ145BR6S8C315AG2BD61SJ16E208P1FDK3AK',
contractName: 'example-contract',
functionName: 'vote',
functionArgs: [pick],
postConditionMode: PostConditionMode.Deny,
postConditions: [],
onFinish: response => {
// WHEN user confirms pop-up
},
onCancel: () => {
// WHEN user cancels/closes pop-up
},
});
// This will open only the Hiro Wallet
authenticate({ ...opts }, HiroWalletProvider);
openPsbtRequestPopup({ ...opts }, HiroWalletProvider);
openProfileUpdateRequestPopup({ ...opts }, HiroWalletProvider);
openSignatureRequestPopup({ ...opts }, HiroWalletProvider);
openStructuredDataSignatureRequestPopup({ ...opts }, HiroWalletProvider);
```

@@ -187,5 +201,5 @@

- Connect can currently not set manual nonces, since this is not supported by wallets.
- For some projects it might be necessary to also install the `regenerator-runtime` package. `npm install --save-dev regenerator-runtime`. This is a build issue of `@stacks/connect` and we are working on a fix.
- For some projects it might be necessary to also install the `regenerator-runtime` package. `npm install --save-dev regenerator-runtime`. This is a build issue of older versions of `@stacks/connect`.
## 📚 Option Glossary <!-- omit in toc -->
## 📚 Method Parameters <!-- omit in toc -->

@@ -212,9 +226,11 @@ A glossary of the most common options of `openSTXTransfer` and `openContractCall`

| | Default | Description | Type | Example |
| :----------- | :------------------ | :-------------------------------------------------------------------- | :-------------------------------------------------------------------------- | :----------------------- |
| `network` | Mainnet | The network to broadcast the transaction to | [StacksNetwork](https://stacks.js.org/classes/network.StacksNetwork.html) | `new StacksMainnet()` |
| `anchorMode` | Any | The type of block the transaction should be mined in | [AnchorMode Enum](https://stacks.js.org/enums/transactions.AnchorMode.html) | `AnchorMode.OnChainOnly` |
| `memo` | _Empty_ `''` | The memo field (used for additional data) | `string` | `'a memo'` |
| `fee` | _Handled by Wallet_ | The transaction fee (the wallet will estimate fees as well) | Integer (e.g. `number`, `bigint`) | `1000` |
| `onFinish` | _No-op_ | The callback function to run after broadcasting the transaction | Function (receiving `response`) | |
| `onCancel` | _No-op_ | The callback function to run after the user cancels/closes the wallet | Function | |
| | Default | Description | Type | Example |
| :------------------ | :------------------ | :-------------------------------------------------------------------------- | :------------------------------------------------------------------------------ | :------------------------ |
| `network` | Mainnet | The network to broadcast the transaction to | [StacksNetwork](https://stacks.js.org/classes/network.StacksNetwork.html) | `new StacksMainnet()` |
| `anchorMode` | Any | The type of block the transaction should be mined in | [AnchorMode Enum](https://stacks.js.org/enums/transactions.AnchorMode.html) | `AnchorMode.OnChainOnly` |
| `memo` | _Empty_ `''` | The memo field (used for additional data) | `string` | `'a memo'` |
| `fee` | _Handled by Wallet_ | The transaction fee (the wallet will estimate fees as well) | Integer (e.g. `number`, `bigint`) | `1000` |
| `postConditionMode` | Deny | The post condition mode, _i.e. whether to allow unspecified asset transfer_ | [PostConditionMode](https://stacks.js.org/enums/transactions.PostConditionMode) | `PostConditionMode.Allow` |
| `postConditions` | _Empty_ `[]` | The list of post conditions to check, regardless of postConditionMode | [PostCondition](https://stacks.js.org/types/transactions.PostCondition)[] | |
| `onFinish` | _No-op_ | The callback function to run after broadcasting the transaction | Function (receiving `response`) | |
| `onCancel` | _No-op_ | The callback function to run after the user cancels/closes the wallet | Function | |

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc