@stacks/connect
Advanced tools
Comparing version 7.3.2-alpha.f1fab3e.0 to 7.4.0
@@ -9,3 +9,3 @@ 'use strict'; | ||
var X=Object.defineProperty,M=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,R=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,a=(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))R.call(t,n)&&b(e,n,t[n]);return e},c=(e,t)=>M(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&&R.call(e,r)&&(n[r]=e[r]);return n};function u(){return window.StacksProvider||window.BlockstackProvider}function zt(){return !!u()}var Ht="https://app.blockstack.org",B="7.3.2-alpha.f1fab3e.0";typeof window!="undefined"&&(window.__CONNECT_VERSION__=B);var z=()=>{let e=navigator.userAgent;return /android/i.test(e)||/iPad|iPhone|iPod/.test(e)?!0:/windows phone/i.test(e)},Qt=()=>!z(),U=e=>{if(!e){let t=new auth.AppConfig(["store_write"],document.location.href);e=new auth.UserSession({appConfig:t});}return e},A=async(e,t=u())=>{if(!t)throw new Error("[Connect] No installed Stacks wallet found");let{redirectTo:n="/",manifestPath:r,onFinish:s,onCancel:o,sendToSignIn:i=!1,userSession:p,appDetails:l}=e,d=U(p);d.isUserSignedIn()&&d.signUserOut();let S=d.generateAndStoreTransitKey(),F=d.makeAuthRequest(S,`${document.location.origin}${n}`,`${document.location.origin}${r}`,d.appConfig.scopes,void 0,void 0,{sendToSignIn:i,appDetails:l,connectVersion:B});try{let P=await t.authenticationRequest(F);await d.handlePendingSignIn(P);let h=jsontokens.decodeToken(P),$=h==null?void 0:h.payload;s==null||s({authResponse:P,authResponsePayload:$,userSession:d});}catch(P){console.error("[Connect] Error during auth request",P),o==null||o();}},Zt=async e=>(e=U(e),e.isUserSignedIn()?e.loadUserData():e.isSignInPending()?e.handlePendingSignIn():null);var Y=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+=Y[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),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i;}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(a({},e),{network:t,userSession:n});return a({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(a({},e),{postConditions:n}))}function w(e){let{postConditions:t}=e;return t&&typeof t[0]!="string"&&(t=E(t)),jsontokens.createUnsecuredToken(c(a({},e),{postConditions:t}))}var it=async({token:e,options:t},n)=>{var r,s,o;try{let i=await n.transactionRequest(e),{txRaw:p}=i,l=I(p.replace(/^0x/,"")),d=transactions.deserializeTransaction(l);if("sponsored"in t&&t.sponsored){(r=t.onFinish)==null||r.call(t,c(a({},i),{stacksTransaction:d}));return}(s=t.onFinish)==null||s.call(t,c(a({},i),{stacksTransaction:d}));}catch(i){console.error("[Connect] Error during transaction request",i),(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(l=>typeof l=="string"?l:m(transactions.serializeCV(l)));if(g(r)){let{privateKey:l,publicKey:d}=y(r),S=c(a({},s),{functionArgs:o,txType:"contract_call",publicKey:d});return n&&(S.appDetails=n),C(S,l)}let i=c(a({},s),{functionArgs:o,txType:"contract_call"});return n&&(i.appDetails=n),w(i)},pt=async e=>{let o=e,{appDetails:t,userSession:n}=o,r=f(o,["appDetails","userSession"]);if(g(n)){let{privateKey:i,publicKey:p}=y(n),l=c(a({},r),{publicKey:p,txType:"smart_contract"});return t&&(l.appDetails=t),C(l,i)}let s=c(a({},r),{txType:"smart_contract"});return t&&(s.appDetails=t),w(s)},ut=async e=>{let i=e,{amount:t,appDetails:n,userSession:r}=i,s=f(i,["amount","appDetails","userSession"]);if(g(r)){let{privateKey:p,publicKey:l}=y(r),d=c(a({},s),{amount:t.toString(10),publicKey:l,txType:"token_transfer"});return n&&(d.appDetails=n),C(d,p)}let o=c(a({},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(a(a({},at(e)),e));return it({token:r,options:e},n)}function le(e,t=u()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return k(e,ct,t)}function de(e,t=u()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return k(e,pt,t)}function fe(e,t=u()){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(a({},e))}function yt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({},r)}async function xt({token:e,options:t},n=u()){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:l,publicKey:d}=y(s),S=c(a({},o),{allowedSighash:t,hex:n,signAtIndex:r,publicKey:d});return gt(S,l)}let i=a({},o);return jsontokens.createUnsecuredToken(i)};async function mt(e,t,n=u()){let r=await t(a(a({},yt(e)),e));return xt({token:r,options:e},n)}function he(e,t=u()){return mt(e,St,t)}function Ct(e){var i;let{userSession:t,network:n}=e;if(!t||!n)return;let r=(i=t==null?void 0:t.loadUserData().profile)==null?void 0:i.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(a({},e))}function O(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({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:i}=y(t),p=c(a({},n),{publicKey:i});return wt(p,o)}let r=a({},n);return jsontokens.createUnsecuredToken(r)};async function bt(e,t,n){let r=await t(a(a({},O(e)),e));return kt({token:r,options:e},n)}function Be(e,t=u()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return bt(e,Ot,t)}async function Bt(e,t,n){let r=await t(a(a({},O(e)),e));return It({token:r,options:e},n)}function N(e){return c(a({},e),{message:m(transactions.serializeCV(e.message)),domain:m(transactions.serializeCV(e.domain))})}async function Ut(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(N(e))}async function At(e){let r=e,{userSession:t}=r,n=f(r,["userSession"]);if(g(t)){let{privateKey:s,publicKey:o}=y(t),i=c(a({},n),{publicKey:o});return Ut(i,s)}return jsontokens.createUnsecuredToken(N(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 Fe(e,t=u()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Bt(e,At,t)}async function Kt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(a({},e))}function Nt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({},r)}async function Ft({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 $t=async e=>{let o=e,{userSession:t,profile:n}=o,r=f(o,["userSession","profile"]);if(g(t)){let{privateKey:i,publicKey:p}=y(t),l=c(a({},r),{profile:n,publicKey:p});return Kt(l,i)}let s=a({},r);return jsontokens.createUnsecuredToken(s)};async function Xt(e,t,n){let r=await t(a(a({},Nt(e)),e));return Ft({token:r,options:e},n)}function ze(e,t=u()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Xt(e,$t,t)}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=(e,t=u())=>{if(t){A(e);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);}},Ze=e=>_t(e); | ||
var X=Object.defineProperty,M=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,R=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,a=(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))R.call(t,n)&&b(e,n,t[n]);return e},c=(e,t)=>M(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&&R.call(e,r)&&(n[r]=e[r]);return n};function d(){return window.StacksProvider||window.BlockstackProvider}function zt(){return !!d()}var Ht="https://app.blockstack.org",B="7.4.0";typeof window!="undefined"&&(window.__CONNECT_VERSION__=B);var z=()=>{let e=navigator.userAgent;return /android/i.test(e)||/iPad|iPhone|iPod/.test(e)?!0:/windows phone/i.test(e)},Qt=()=>!z(),U=e=>{if(!e){let t=new auth.AppConfig(["store_write"],document.location.href);e=new auth.UserSession({appConfig:t});}return e},A=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:i=!1,userSession:p,appDetails:u}=e,l=U(p);l.isUserSignedIn()&&l.signUserOut();let S=l.generateAndStoreTransitKey(),F=l.makeAuthRequest(S,`${document.location.origin}${n}`,`${document.location.origin}${r}`,l.appConfig.scopes,void 0,void 0,{sendToSignIn:i,appDetails:u,connectVersion:B});try{let P=await t.authenticationRequest(F);await l.handlePendingSignIn(P);let h=jsontokens.decodeToken(P),$=h==null?void 0:h.payload;s==null||s({authResponse:P,authResponsePayload:$,userSession:l});}catch(P){console.error("[Connect] Error during auth request",P),o==null||o();}},Zt=async e=>(e=U(e),e.isUserSignedIn()?e.loadUserData():e.isSignInPending()?e.handlePendingSignIn():null);var Y=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+=Y[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),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i;}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(a({},e),{network:t,userSession:n});return a({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(a({},e),{postConditions:n}))}function w(e){let{postConditions:t}=e;return t&&typeof t[0]!="string"&&(t=E(t)),jsontokens.createUnsecuredToken(c(a({},e),{postConditions:t}))}var it=async({token:e,options:t},n)=>{var r,s,o;try{let i=await n.transactionRequest(e),{txRaw:p}=i,u=I(p.replace(/^0x/,"")),l=transactions.deserializeTransaction(u);if("sponsored"in t&&t.sponsored){(r=t.onFinish)==null||r.call(t,c(a({},i),{stacksTransaction:l}));return}(s=t.onFinish)==null||s.call(t,c(a({},i),{stacksTransaction:l}));}catch(i){console.error("[Connect] Error during transaction request",i),(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(a({},s),{functionArgs:o,txType:"contract_call",publicKey:l});return n&&(S.appDetails=n),C(S,u)}let i=c(a({},s),{functionArgs:o,txType:"contract_call"});return n&&(i.appDetails=n),w(i)},pt=async e=>{let o=e,{appDetails:t,userSession:n}=o,r=f(o,["appDetails","userSession"]);if(g(n)){let{privateKey:i,publicKey:p}=y(n),u=c(a({},r),{publicKey:p,txType:"smart_contract"});return t&&(u.appDetails=t),C(u,i)}let s=c(a({},r),{txType:"smart_contract"});return t&&(s.appDetails=t),w(s)},ut=async e=>{let i=e,{amount:t,appDetails:n,userSession:r}=i,s=f(i,["amount","appDetails","userSession"]);if(g(r)){let{privateKey:p,publicKey:u}=y(r),l=c(a({},s),{amount:t.toString(10),publicKey:u,txType:"token_transfer"});return n&&(l.appDetails=n),C(l,p)}let o=c(a({},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(a(a({},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(a({},e))}function yt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({},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(a({},o),{allowedSighash:t,hex:n,signAtIndex:r,publicKey:l});return gt(S,u)}let i=a({},o);return jsontokens.createUnsecuredToken(i)};async function mt(e,t,n){let r=await t(a(a({},yt(e)),e));return xt({token:r,options:e},n)}function he(e,t=d()){return mt(e,St,t)}function Ct(e){var i;let{userSession:t,network:n}=e;if(!t||!n)return;let r=(i=t==null?void 0:t.loadUserData().profile)==null?void 0:i.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(a({},e))}function O(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({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:i}=y(t),p=c(a({},n),{publicKey:i});return wt(p,o)}let r=a({},n);return jsontokens.createUnsecuredToken(r)};async function bt(e,t,n){let r=await t(a(a({},O(e)),e));return kt({token:r,options:e},n)}function Be(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return bt(e,Ot,t)}async function Bt(e,t,n){let r=await t(a(a({},O(e)),e));return It({token:r,options:e},n)}function N(e){return c(a({},e),{message:m(transactions.serializeCV(e.message)),domain:m(transactions.serializeCV(e.domain))})}async function Ut(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(N(e))}async function At(e){let r=e,{userSession:t}=r,n=f(r,["userSession"]);if(g(t)){let{privateKey:s,publicKey:o}=y(t),i=c(a({},n),{publicKey:o});return Ut(i,s)}return jsontokens.createUnsecuredToken(N(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 Fe(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Bt(e,At,t)}async function Kt(e,t){return new jsontokens.TokenSigner("ES256k",t).signAsync(a({},e))}function Nt(e){let t=e.network||new network.StacksTestnet,n=x(e.userSession),r=c(a({},e),{network:t,userSession:n});return a({},r)}async function Ft({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 $t=async e=>{let o=e,{userSession:t,profile:n}=o,r=f(o,["userSession","profile"]);if(g(t)){let{privateKey:i,publicKey:p}=y(t),u=c(a({},r),{profile:n,publicKey:p});return Kt(u,i)}let s=a({},r);return jsontokens.createUnsecuredToken(s)};async function Xt(e,t,n){let r=await t(a(a({},Nt(e)),e));return Ft({token:r,options:e},n)}function ze(e,t=d()){if(!t)throw new Error("[Connect] No installed Stacks wallet found");return Xt(e,$t,t)}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=(e,t=d())=>{if(t){A(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);}},Ze=e=>_t(e); | ||
@@ -22,3 +22,3 @@ exports.ContractCallArgumentType = W; | ||
exports.getOrCreateUserSession = U; | ||
exports.getStacksProvider = u; | ||
exports.getStacksProvider = d; | ||
exports.getStxAddress = st; | ||
@@ -25,0 +25,0 @@ exports.getUserData = Zt; |
{ | ||
"name": "@stacks/connect", | ||
"version": "7.3.2-alpha.f1fab3e.0", | ||
"version": "7.4.0", | ||
"license": "MIT", | ||
@@ -14,3 +14,3 @@ "prettier": "@stacks/prettier-config", | ||
"@stacks/auth": "^6.1.1", | ||
"@stacks/connect-ui": "^6.1.2-alpha.f1fab3e.0", | ||
"@stacks/connect-ui": "6.1.1", | ||
"@stacks/network": "^6.1.1", | ||
@@ -39,3 +39,3 @@ "@stacks/profile": "^6.1.1", | ||
}, | ||
"gitHead": "459d869f128010b88d3c5627b70697c05e96b225" | ||
"gitHead": "16bdebba0de023194a70eabf60d71bf974913030" | ||
} |
107
README.md
@@ -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,38 +180,2 @@ ##### Post-Condition Modes | ||
#### 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, | ||
postConditions: [], | ||
onFinish: response => { | ||
// WHEN user confirms pop-up | ||
}, | ||
onCancel: () => { | ||
// WHEN user cancels/closes pop-up | ||
}, | ||
}); | ||
``` | ||
### 🛠 Advanced <!-- omit in toc --> | ||
@@ -206,3 +203,3 @@ | ||
## 📚 Option Glossary <!-- omit in toc --> | ||
## 📚 Method Parameters <!-- omit in toc --> | ||
@@ -229,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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
0
100
2
4315433
228
+ Added@stacks/connect-ui@6.1.1(transitive)
- Removed@stacks/connect-ui@6.5.0(transitive)
Updated@stacks/connect-ui@6.1.1