@revibase/lite 0.0.39 → 0.0.40
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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -28,7 +28,10 @@ declare class RevibaseProvider {
|
|
|
28
28
|
jwk: string;
|
|
29
29
|
jws: string;
|
|
30
30
|
} | undefined>;
|
|
31
|
-
|
|
31
|
+
createChannel(): Promise<{
|
|
32
|
+
channelId: any;
|
|
33
|
+
url: string;
|
|
34
|
+
}>;
|
|
32
35
|
closeChannel(): Promise<void>;
|
|
33
36
|
startRequest(): {
|
|
34
37
|
rid: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,10 @@ declare class RevibaseProvider {
|
|
|
28
28
|
jwk: string;
|
|
29
29
|
jws: string;
|
|
30
30
|
} | undefined>;
|
|
31
|
-
|
|
31
|
+
createChannel(): Promise<{
|
|
32
|
+
channelId: any;
|
|
33
|
+
url: string;
|
|
34
|
+
}>;
|
|
32
35
|
closeChannel(): Promise<void>;
|
|
33
36
|
startRequest(): {
|
|
34
37
|
rid: string;
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import {prepareTransactionMessage,getSettingsFromIndex,StartMessageRequestSchema
|
|
|
2
2
|
|
|
3
3
|
Install @solana/webcrypto-ed25519-polyfill and call its \`install\` function before generating keys in environments that do not support Ed25519.
|
|
4
4
|
|
|
5
|
-
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20.`,[An]:"No signature verification implementation could be found.",[ln]:"No key generation implementation could be found.",[En]:"No signing implementation could be found.",[Rn]:"No key export implementation could be found.",[Ut]:"Timestamp value must be in the range [-(2n ** 63n), (2n ** 63n) - 1]. `$value` given",[co]:"Transaction processing left an account with an outstanding borrowed reference",[Yr]:"Account in use",[Xr]:"Account loaded twice",[Zr]:"Attempt to debit an account but found no record of a prior credit.",[Ro]:"Transaction loads an address table account that doesn't exist",[Qr]:"This transaction has already been processed",[eo]:"Blockhash not found",[to]:"Loader call chain is too deep",[so]:"Transactions are currently disabled due to cluster maintenance",[Oo]:"Transaction contains a duplicate instruction ($index) that is not allowed",[qr]:"Insufficient funds for fee",[fo]:"Transaction results in an account ($accountIndex) with insufficient funds for rent",[Jr]:"This account may not be used to pay transaction fees",[ro]:"Transaction contains an invalid account reference",[go]:"Transaction loads an address table account with invalid data",[Do]:"Transaction address table lookup uses an invalid index",[To]:"Transaction loads an address table account with an invalid owner",[po]:"LoadedAccountsDataSizeLimit set for transaction must be greater than 0.",[io]:"This program may not be used for executing instructions",[No]:"Transaction leaves an account with a lower balance than rent-exempt minimum",[_o]:"Transaction loads a writable account that cannot be written",[mo]:"Transaction exceeded max loaded accounts data size cap",[no]:"Transaction requires a fee but has no signature present",[jr]:"Attempt to load a program that does not exist",[Mo]:"Execution of the program referenced by account at index $accountIndex is temporarily restricted.",[ho]:"ResanitizationNeeded",[ao]:"Transaction failed to sanitize accounts offsets correctly",[oo]:"Transaction did not pass signature verification",[Eo]:"Transaction locked too many accounts",[Lo]:"Sum of account balances before and after transaction do not match",[$r]:"The transaction failed with the error `$errorName`",[Io]:"Transaction version is unsupported",[lo]:"Transaction would exceed account data limit within the block",[Co]:"Transaction would exceed total account data limit",[Ao]:"Transaction would exceed max account limit within the block",[uo]:"Transaction would exceed max Block Cost Limit",[So]:"Transaction would exceed max Vote Cost Limit",[pe]:"Attempted to sign a transaction with an address that is not a signer for it",[xr]:"Transaction is missing an address at index: $index.",[he]:"Transaction has no expected signers therefore it cannot be encoded",[Me]:"Transaction size $transactionSize exceeds limit of $transactionSizeLimit bytes",[W]:"Transaction does not have a blockhash lifetime",[V]:"Transaction is not a durable nonce transaction",[Ne]:"Contents of these address lookup tables unknown: $lookupTableAddresses",[Se]:"Lookup of address at index $highestRequestedIndex failed for lookup table `$lookupTableAddress`. Highest known index is $highestKnownIndex. The lookup table may have been extended since its contents were retrieved",[Oe]:"No fee payer set in CompiledTransaction",[Ce]:"Could not find program address at index $index",[Hr]:"Failed to estimate the compute unit consumption for this transaction message. This is likely because simulating the transaction failed. Inspect the `cause` property of this error to learn more",[Kr]:"Transaction failed when it was simulated in order to estimate the compute unit consumption. The compute unit estimate provided is for a transaction that failed when simulated and may not be representative of the compute units this transaction would consume if successful. Inspect the `cause` property of this error to learn more",[Wr]:"Transaction is missing a fee payer.",[me]:"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.",[Gr]:"Transaction first instruction is not advance nonce account instruction.",[Vr]:"Transaction with no instructions cannot be durable nonce transaction.",[Te]:"This transaction includes an address (`$programAddress`) which is both invoked and set as the fee payer. Program addresses may not pay fees",[ge]:"This transaction includes an address (`$programAddress`) which is both invoked and marked writable. Program addresses may not be writable",[G]:"The transaction message expected the transaction to have $numRequiredSignatures signatures, got $signaturesLength.",[fe]:"Transaction is missing signatures for addresses: $addresses.",[De]:"Transaction version must be in the range [0, 127]. `$actualVersion` given",[H]:"This version of Kit does not support decoding transactions with version $unsupportedVersion. The current max supported version is 0.",[Le]:"The transaction has a durable nonce lifetime (with nonce `$nonce`), but the nonce account address is in a lookup table. The lifetime constraint cannot be constructed without fetching the lookup tables for the transaction."},g="i",E="t";function ui(e,t={}){let n=ci[e];if(n.length===0)return "";let r;function o(a){if(r[E]===2){let s=n.slice(r[g]+1,a);i.push(s in t?`${t[s]}`:`$${s}`);}else r[E]===1&&i.push(n.slice(r[g],a));}let i=[];return n.split("").forEach((a,s)=>{if(s===0){r={[g]:0,[E]:n[0]==="\\"?0:n[0]==="$"?2:1};return}let c;switch(r[E]){case 0:c={[g]:s,[E]:1};break;case 1:a==="\\"?c={[g]:s,[E]:0}:a==="$"&&(c={[g]:s,[E]:2});break;case 2:a==="\\"?c={[g]:s,[E]:0}:a==="$"?c={[g]:s,[E]:2}:a.match(/\w/)||(c={[g]:s,[E]:1});break}c&&(r!==c&&o(s),r=c);}),o(),i.join("")}function di(e,t={}){if(process.env.NODE_ENV!=="production")return ui(e,t);{let n=`Solana error #${e}; Decode this error by running \`npx @solana/errors decode -- ${e}`;return Object.keys(t).length&&(n+=` '${si(t)}'`),`${n}\``}}var l=class extends Error{cause=this.cause;context;constructor(...[e,t]){let n,r;t&&Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([i,a])=>{i==="cause"?r={cause:a.value}:(n===void 0&&(n={}),Object.defineProperty(n,i,a));});let o=di(e,n);super(o,r),this.context=n===void 0?{}:n,this.context.__code=e,this.name="SolanaError";}};function Ii(e,t){if(e.length>=t)return e;let n=new Uint8Array(t).fill(0);return n.set(e),n}var _i=(e,t)=>Ii(e.length<=t?e:e.slice(0,t),t);function xe(e,t){return "fixedSize"in t?t.fixedSize:t.getSizeFromValue(e)}function D(e){return Object.freeze({...e,encode:t=>{let n=new Uint8Array(xe(t,e));return e.write(t,n,0),n}})}function A(e){return Object.freeze({...e,decode:(t,n=0)=>e.read(t,n)[0]})}function O(e){return "fixedSize"in e&&typeof e.fixedSize=="number"}function Ai(e){return !O(e)}function We(e,t,n=0){if(t.length-n<=0)throw new l(K,{codecDescription:e})}function b(e,t,n,r=0){let o=n.length-r;if(o<t)throw new l($,{bytesLength:o,codecDescription:e,expected:t})}function ke(e,t,n){if(t<0||t>n)throw new l(Z,{bytesLength:n,codecDescription:e,offset:t})}function M(e,t){return D({fixedSize:t,write:(n,r,o)=>{let i=e.encode(n),a=i.length>t?i.slice(0,t):i;return r.set(a,o),o+t}})}function f(e,t){return A({fixedSize:t,read:(n,r)=>{b("fixCodecSize",t,n,r),(r>0||n.length>t)&&(n=n.slice(r,r+t)),O(e)&&(n=_i(n,e.fixedSize));let[o]=e.read(n,0);return [o,r+t]}})}function li(e,t){return A({...e,read:(n,r)=>{let o=d=>Ei(d,n.length),i=t.preOffset?t.preOffset({bytes:n,preOffset:r,wrapBytes:o}):r;ke("offsetDecoder",i,n.length);let[a,s]=e.read(n,i),c=t.postOffset?t.postOffset({bytes:n,newPreOffset:i,postOffset:s,preOffset:r,wrapBytes:o}):s;return ke("offsetDecoder",c,n.length),[a,c]}})}function Ei(e,t){return t===0?0:(e%t+t)%t}function Ri(e,t){if(O(e)){let n=t(e.fixedSize);if(n<0)throw new l(X,{bytesLength:n,codecDescription:"resizeDecoder"});return A({...e,fixedSize:n})}return e}function Ve(e,t){return li(Ri(e,n=>n+t),{postOffset:({postOffset:n})=>n+t})}function L(e,t){return D({...Ai(e)?{...e,getSizeFromValue:n=>e.getSizeFromValue(t(n))}:e,write:(n,r,o)=>e.write(t(n),r,o)})}function F(e,t){return A({...e,read:(n,r)=>{let[o,i]=e.read(n,r);return [t(o,n,r),i]}})}function Ke(e,t,n=t){if(!t.match(new RegExp(`^[${e}]*$`)))throw new l(U,{alphabet:e,base:e.length,value:n})}var Ti=e=>D({getSizeFromValue:t=>{let[n,r]=Ge(t,e[0]);if(!r)return t.length;let o=He(r,e);return n.length+Math.ceil(o.toString(16).length/2)},write(t,n,r){if(Ke(e,t),t==="")return r;let[o,i]=Ge(t,e[0]);if(!i)return n.set(new Uint8Array(o.length).fill(0),r),r+o.length;let a=He(i,e),s=[];for(;a>0n;)s.unshift(Number(a%256n)),a/=256n;let c=[...Array(o.length).fill(0),...s];return n.set(c,r),r+c.length}}),gi=e=>A({read(t,n){let r=n===0?t:t.slice(n);if(r.length===0)return ["",0];let o=r.findIndex(c=>c!==0);o=o===-1?r.length:o;let i=e[0].repeat(o);if(o===r.length)return [i,t.length];let a=r.slice(o).reduce((c,d)=>c*256n+BigInt(d),0n),s=Di(a,e);return [i+s,t.length]}});function Ge(e,t){let[n,r]=e.split(new RegExp(`((?!${t}).*)`));return [n,r]}function He(e,t){let n=BigInt(t.length),r=0n;for(let o of e)r*=n,r+=BigInt(t.indexOf(o));return r}function Di(e,t){let n=BigInt(t.length),r=[];for(;e>0n;)r.unshift(t[Number(e%n)]),e/=n;return r.join("")}var $e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Ye=()=>Ti($e),v=()=>gi($e);var Ni="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xe=()=>D({getSizeFromValue:e=>Buffer.from(e,"base64").length,write(e,t,n){Ke(Ni,e.replace(/=/g,""));let r=Buffer.from(e,"base64");return t.set(r,n),r.length+n}}),N=()=>A({read:(e,t=0)=>[Buffer.from(e,t).toString("base64"),e.length]});var j,q;function Ze(){return j||(j=Ye()),j}function Si(){return q||(q=v()),q}function Ci(e){if(e.length<32||e.length>44)throw new l(x,{actualLength:e.length});let r=Ze().encode(e).byteLength;if(r!==32)throw new l(k,{actualLength:r})}function m(e){return Ci(e),e}function J(){return L(M(Ze(),32),e=>m(e))}function je(){return f(Si(),32)}function Oi(e,t,n,r){if(r<t||r>n)throw new l(Y,{codecDescription:e,max:n,min:t,value:r})}function qe(e){return e?.endian!==1}function fi(e){return D({fixedSize:e.size,write(t,n,r){e.range&&Oi(e.name,e.range[0],e.range[1],t);let o=new ArrayBuffer(e.size);return e.set(new DataView(o),t,qe(e.config)),n.set(new Uint8Array(o),r),r+e.size}})}function Je(e){return A({fixedSize:e.size,read(t,n=0){We(e.name,t,n),b(e.name,e.size,t,n);let r=new DataView(mi(t,n,e.size));return [e.get(r,qe(e.config)),n+e.size]}})}function mi(e,t,n){let r=e.byteOffset+(t??0),o=n??e.byteLength;return e.buffer.slice(r,r+o)}var Q=()=>A({maxSize:3,read:(e,t)=>{let n=0,r=0;for(;++r;){let o=r-1,i=e[t+o],a=127&i;if(n|=a<<o*7,(i&128)===0)break}return [n,t+r]}});var Qe=(e={})=>Je({config:e,get:(t,n)=>t.getUint32(0,n),name:"u32",size:4});var et=(e={})=>fi({config:e,name:"u64",range:[0n,BigInt("0xffffffffffffffff")],set:(t,n,r)=>t.setBigUint64(0,BigInt(n),r),size:8});var ee=()=>Je({get:e=>e.getUint8(0),name:"u8",size:1});function P(e){return e.reduce((t,n)=>t===null||n===null?null:t+n,0)}function te(e){return O(e)?e.fixedSize:null}function ne(e){return O(e)?e.fixedSize:e.maxSize??null}function re(e,t={}){let n=t.size??Qe(),r=te(e),o=tt(n,r),i=tt(n,ne(e))??void 0;return A({...o!==null?{fixedSize:o}:{maxSize:i},read:(a,s)=>{let c=[];if(typeof n=="object"&&a.slice(s).length===0)return [c,s];if(n==="remainder"){for(;s<a.length;){let[u,I]=e.read(a,s);s=I,c.push(u);}return [c,s]}let[d,_]=typeof n=="number"?[n,s]:n.read(a,s);s=_;for(let u=0;u<d;u+=1){let[I,T]=e.read(a,s);s=T,c.push(I);}return [c,s]}})}function tt(e,t){return typeof e!="number"?null:e===0?0:t===null?null:t*e}function oe(){return A({read:(e,t)=>{let n=e.slice(t);return [n,t+n.length]}})}function nt(e){let t=P(e.map(te)),n=P(e.map(ne))??void 0;return A({...t===null?{maxSize:n}:{fixedSize:t},read:(r,o)=>{let i=[];return e.forEach(a=>{let[s,c]=a.read(r,o);i.push(s),o=c;}),[i,o]}})}function rt(e){let t=e.map(([,o])=>o),n=P(t.map(te)),r=P(t.map(ne))??void 0;return A({...n===null?{maxSize:r}:{fixedSize:n},read:(o,i)=>{let a={};return e.forEach(([s,c])=>{let[d,_]=c.read(o,i);i=_,a[s]=d;}),[a,i]}})}var pi=0,ot=128;function it(){return A({maxSize:1,read:(e,t)=>{let n=e[t];if((n&ot)===0)return ["legacy",t];{let r=n^ot;if(r>pi)throw new l(H,{unsupportedVersion:r});return [r,t+1]}}})}function at(){return F(rt([["signatures",re(f(oe(),64),{size:Q()})],["messageBytes",oe()]]),hi)}function hi(e){let{messageBytes:t,signatures:n}=e,r=nt([it(),Ve(ee(),2),re(je(),{size:Q()})]),[o,i,a]=r.decode(t),s=a.slice(0,i);if(s.length!==n.length)throw new l(G,{numRequiredSignatures:i,signaturesLength:n.length,signerAddresses:s});let c={};return s.forEach((d,_)=>{let u=n[_];u.every(I=>I===0)?c[d]=null:c[d]=u;}),{messageBytes:t,signatures:Object.freeze(c)}}function st(e){if(typeof window>"u")throw new Error("Function can only be called in a browser environment");let t=window.innerWidth||window.screen.availWidth,n=window.innerHeight||window.screen.availHeight,r=t<=768,o,i,a,s;if(r)o=t,i=n,a=0,s=0;else {let d=window.screenLeft??window.screenX??0,_=window.screenTop??window.screenY??0,u=window.innerWidth??document.documentElement.clientWidth??window.screen.width,I=window.innerHeight??document.documentElement.clientHeight??window.screen.height;o=500,i=600,s=Math.round(d+(u-o)/2),a=Math.round(_+(I-i)/2);}let c=["popup=yes",`width=${o}`,`height=${i}`,`top=${a}`,`left=${s}`,"toolbar=no","location=no","status=no","menubar=no","scrollbars=yes","resizable=yes"].join(",");return window.open(e??"","_blank",c)}function ct(e){let t=e.domain?`${e.domain} wants you to sign in with your account.`:"Sign in with your account.",n=[];return e.nonce&&n.push(`Nonce: ${e.nonce}`),n.length>0?`${t}
|
|
5
|
+
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20.`,[An]:"No signature verification implementation could be found.",[ln]:"No key generation implementation could be found.",[En]:"No signing implementation could be found.",[Rn]:"No key export implementation could be found.",[Ut]:"Timestamp value must be in the range [-(2n ** 63n), (2n ** 63n) - 1]. `$value` given",[co]:"Transaction processing left an account with an outstanding borrowed reference",[Yr]:"Account in use",[Xr]:"Account loaded twice",[Zr]:"Attempt to debit an account but found no record of a prior credit.",[Ro]:"Transaction loads an address table account that doesn't exist",[Qr]:"This transaction has already been processed",[eo]:"Blockhash not found",[to]:"Loader call chain is too deep",[so]:"Transactions are currently disabled due to cluster maintenance",[Oo]:"Transaction contains a duplicate instruction ($index) that is not allowed",[qr]:"Insufficient funds for fee",[fo]:"Transaction results in an account ($accountIndex) with insufficient funds for rent",[Jr]:"This account may not be used to pay transaction fees",[ro]:"Transaction contains an invalid account reference",[go]:"Transaction loads an address table account with invalid data",[Do]:"Transaction address table lookup uses an invalid index",[To]:"Transaction loads an address table account with an invalid owner",[po]:"LoadedAccountsDataSizeLimit set for transaction must be greater than 0.",[io]:"This program may not be used for executing instructions",[No]:"Transaction leaves an account with a lower balance than rent-exempt minimum",[_o]:"Transaction loads a writable account that cannot be written",[mo]:"Transaction exceeded max loaded accounts data size cap",[no]:"Transaction requires a fee but has no signature present",[jr]:"Attempt to load a program that does not exist",[Mo]:"Execution of the program referenced by account at index $accountIndex is temporarily restricted.",[ho]:"ResanitizationNeeded",[ao]:"Transaction failed to sanitize accounts offsets correctly",[oo]:"Transaction did not pass signature verification",[Eo]:"Transaction locked too many accounts",[Lo]:"Sum of account balances before and after transaction do not match",[$r]:"The transaction failed with the error `$errorName`",[Io]:"Transaction version is unsupported",[lo]:"Transaction would exceed account data limit within the block",[Co]:"Transaction would exceed total account data limit",[Ao]:"Transaction would exceed max account limit within the block",[uo]:"Transaction would exceed max Block Cost Limit",[So]:"Transaction would exceed max Vote Cost Limit",[pe]:"Attempted to sign a transaction with an address that is not a signer for it",[xr]:"Transaction is missing an address at index: $index.",[he]:"Transaction has no expected signers therefore it cannot be encoded",[Me]:"Transaction size $transactionSize exceeds limit of $transactionSizeLimit bytes",[W]:"Transaction does not have a blockhash lifetime",[V]:"Transaction is not a durable nonce transaction",[Ne]:"Contents of these address lookup tables unknown: $lookupTableAddresses",[Se]:"Lookup of address at index $highestRequestedIndex failed for lookup table `$lookupTableAddress`. Highest known index is $highestKnownIndex. The lookup table may have been extended since its contents were retrieved",[Oe]:"No fee payer set in CompiledTransaction",[Ce]:"Could not find program address at index $index",[Hr]:"Failed to estimate the compute unit consumption for this transaction message. This is likely because simulating the transaction failed. Inspect the `cause` property of this error to learn more",[Kr]:"Transaction failed when it was simulated in order to estimate the compute unit consumption. The compute unit estimate provided is for a transaction that failed when simulated and may not be representative of the compute units this transaction would consume if successful. Inspect the `cause` property of this error to learn more",[Wr]:"Transaction is missing a fee payer.",[me]:"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.",[Gr]:"Transaction first instruction is not advance nonce account instruction.",[Vr]:"Transaction with no instructions cannot be durable nonce transaction.",[Te]:"This transaction includes an address (`$programAddress`) which is both invoked and set as the fee payer. Program addresses may not pay fees",[ge]:"This transaction includes an address (`$programAddress`) which is both invoked and marked writable. Program addresses may not be writable",[G]:"The transaction message expected the transaction to have $numRequiredSignatures signatures, got $signaturesLength.",[fe]:"Transaction is missing signatures for addresses: $addresses.",[De]:"Transaction version must be in the range [0, 127]. `$actualVersion` given",[H]:"This version of Kit does not support decoding transactions with version $unsupportedVersion. The current max supported version is 0.",[Le]:"The transaction has a durable nonce lifetime (with nonce `$nonce`), but the nonce account address is in a lookup table. The lifetime constraint cannot be constructed without fetching the lookup tables for the transaction."},g="i",E="t";function ui(e,t={}){let n=ci[e];if(n.length===0)return "";let r;function o(a){if(r[E]===2){let s=n.slice(r[g]+1,a);i.push(s in t?`${t[s]}`:`$${s}`);}else r[E]===1&&i.push(n.slice(r[g],a));}let i=[];return n.split("").forEach((a,s)=>{if(s===0){r={[g]:0,[E]:n[0]==="\\"?0:n[0]==="$"?2:1};return}let c;switch(r[E]){case 0:c={[g]:s,[E]:1};break;case 1:a==="\\"?c={[g]:s,[E]:0}:a==="$"&&(c={[g]:s,[E]:2});break;case 2:a==="\\"?c={[g]:s,[E]:0}:a==="$"?c={[g]:s,[E]:2}:a.match(/\w/)||(c={[g]:s,[E]:1});break}c&&(r!==c&&o(s),r=c);}),o(),i.join("")}function di(e,t={}){if(process.env.NODE_ENV!=="production")return ui(e,t);{let n=`Solana error #${e}; Decode this error by running \`npx @solana/errors decode -- ${e}`;return Object.keys(t).length&&(n+=` '${si(t)}'`),`${n}\``}}var l=class extends Error{cause=this.cause;context;constructor(...[e,t]){let n,r;t&&Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([i,a])=>{i==="cause"?r={cause:a.value}:(n===void 0&&(n={}),Object.defineProperty(n,i,a));});let o=di(e,n);super(o,r),this.context=n===void 0?{}:n,this.context.__code=e,this.name="SolanaError";}};function Ii(e,t){if(e.length>=t)return e;let n=new Uint8Array(t).fill(0);return n.set(e),n}var _i=(e,t)=>Ii(e.length<=t?e:e.slice(0,t),t);function xe(e,t){return "fixedSize"in t?t.fixedSize:t.getSizeFromValue(e)}function D(e){return Object.freeze({...e,encode:t=>{let n=new Uint8Array(xe(t,e));return e.write(t,n,0),n}})}function A(e){return Object.freeze({...e,decode:(t,n=0)=>e.read(t,n)[0]})}function O(e){return "fixedSize"in e&&typeof e.fixedSize=="number"}function Ai(e){return !O(e)}function We(e,t,n=0){if(t.length-n<=0)throw new l(K,{codecDescription:e})}function b(e,t,n,r=0){let o=n.length-r;if(o<t)throw new l($,{bytesLength:o,codecDescription:e,expected:t})}function ke(e,t,n){if(t<0||t>n)throw new l(Z,{bytesLength:n,codecDescription:e,offset:t})}function M(e,t){return D({fixedSize:t,write:(n,r,o)=>{let i=e.encode(n),a=i.length>t?i.slice(0,t):i;return r.set(a,o),o+t}})}function f(e,t){return A({fixedSize:t,read:(n,r)=>{b("fixCodecSize",t,n,r),(r>0||n.length>t)&&(n=n.slice(r,r+t)),O(e)&&(n=_i(n,e.fixedSize));let[o]=e.read(n,0);return [o,r+t]}})}function li(e,t){return A({...e,read:(n,r)=>{let o=d=>Ei(d,n.length),i=t.preOffset?t.preOffset({bytes:n,preOffset:r,wrapBytes:o}):r;ke("offsetDecoder",i,n.length);let[a,s]=e.read(n,i),c=t.postOffset?t.postOffset({bytes:n,newPreOffset:i,postOffset:s,preOffset:r,wrapBytes:o}):s;return ke("offsetDecoder",c,n.length),[a,c]}})}function Ei(e,t){return t===0?0:(e%t+t)%t}function Ri(e,t){if(O(e)){let n=t(e.fixedSize);if(n<0)throw new l(X,{bytesLength:n,codecDescription:"resizeDecoder"});return A({...e,fixedSize:n})}return e}function Ve(e,t){return li(Ri(e,n=>n+t),{postOffset:({postOffset:n})=>n+t})}function L(e,t){return D({...Ai(e)?{...e,getSizeFromValue:n=>e.getSizeFromValue(t(n))}:e,write:(n,r,o)=>e.write(t(n),r,o)})}function F(e,t){return A({...e,read:(n,r)=>{let[o,i]=e.read(n,r);return [t(o,n,r),i]}})}function Ke(e,t,n=t){if(!t.match(new RegExp(`^[${e}]*$`)))throw new l(U,{alphabet:e,base:e.length,value:n})}var Ti=e=>D({getSizeFromValue:t=>{let[n,r]=Ge(t,e[0]);if(!r)return t.length;let o=He(r,e);return n.length+Math.ceil(o.toString(16).length/2)},write(t,n,r){if(Ke(e,t),t==="")return r;let[o,i]=Ge(t,e[0]);if(!i)return n.set(new Uint8Array(o.length).fill(0),r),r+o.length;let a=He(i,e),s=[];for(;a>0n;)s.unshift(Number(a%256n)),a/=256n;let c=[...Array(o.length).fill(0),...s];return n.set(c,r),r+c.length}}),gi=e=>A({read(t,n){let r=n===0?t:t.slice(n);if(r.length===0)return ["",0];let o=r.findIndex(c=>c!==0);o=o===-1?r.length:o;let i=e[0].repeat(o);if(o===r.length)return [i,t.length];let a=r.slice(o).reduce((c,d)=>c*256n+BigInt(d),0n),s=Di(a,e);return [i+s,t.length]}});function Ge(e,t){let[n,r]=e.split(new RegExp(`((?!${t}).*)`));return [n,r]}function He(e,t){let n=BigInt(t.length),r=0n;for(let o of e)r*=n,r+=BigInt(t.indexOf(o));return r}function Di(e,t){let n=BigInt(t.length),r=[];for(;e>0n;)r.unshift(t[Number(e%n)]),e/=n;return r.join("")}var $e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Ye=()=>Ti($e),v=()=>gi($e);var Ni="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xe=()=>D({getSizeFromValue:e=>Buffer.from(e,"base64").length,write(e,t,n){Ke(Ni,e.replace(/=/g,""));let r=Buffer.from(e,"base64");return t.set(r,n),r.length+n}}),S=()=>A({read:(e,t=0)=>[Buffer.from(e,t).toString("base64"),e.length]});var j,q;function Ze(){return j||(j=Ye()),j}function Si(){return q||(q=v()),q}function Ci(e){if(e.length<32||e.length>44)throw new l(x,{actualLength:e.length});let r=Ze().encode(e).byteLength;if(r!==32)throw new l(k,{actualLength:r})}function m(e){return Ci(e),e}function J(){return L(M(Ze(),32),e=>m(e))}function je(){return f(Si(),32)}function Oi(e,t,n,r){if(r<t||r>n)throw new l(Y,{codecDescription:e,max:n,min:t,value:r})}function qe(e){return e?.endian!==1}function fi(e){return D({fixedSize:e.size,write(t,n,r){e.range&&Oi(e.name,e.range[0],e.range[1],t);let o=new ArrayBuffer(e.size);return e.set(new DataView(o),t,qe(e.config)),n.set(new Uint8Array(o),r),r+e.size}})}function Je(e){return A({fixedSize:e.size,read(t,n=0){We(e.name,t,n),b(e.name,e.size,t,n);let r=new DataView(mi(t,n,e.size));return [e.get(r,qe(e.config)),n+e.size]}})}function mi(e,t,n){let r=e.byteOffset+(t??0),o=n??e.byteLength;return e.buffer.slice(r,r+o)}var Q=()=>A({maxSize:3,read:(e,t)=>{let n=0,r=0;for(;++r;){let o=r-1,i=e[t+o],a=127&i;if(n|=a<<o*7,(i&128)===0)break}return [n,t+r]}});var Qe=(e={})=>Je({config:e,get:(t,n)=>t.getUint32(0,n),name:"u32",size:4});var et=(e={})=>fi({config:e,name:"u64",range:[0n,BigInt("0xffffffffffffffff")],set:(t,n,r)=>t.setBigUint64(0,BigInt(n),r),size:8});var ee=()=>Je({get:e=>e.getUint8(0),name:"u8",size:1});function P(e){return e.reduce((t,n)=>t===null||n===null?null:t+n,0)}function te(e){return O(e)?e.fixedSize:null}function ne(e){return O(e)?e.fixedSize:e.maxSize??null}function re(e,t={}){let n=t.size??Qe(),r=te(e),o=tt(n,r),i=tt(n,ne(e))??void 0;return A({...o!==null?{fixedSize:o}:{maxSize:i},read:(a,s)=>{let c=[];if(typeof n=="object"&&a.slice(s).length===0)return [c,s];if(n==="remainder"){for(;s<a.length;){let[u,I]=e.read(a,s);s=I,c.push(u);}return [c,s]}let[d,_]=typeof n=="number"?[n,s]:n.read(a,s);s=_;for(let u=0;u<d;u+=1){let[I,T]=e.read(a,s);s=T,c.push(I);}return [c,s]}})}function tt(e,t){return typeof e!="number"?null:e===0?0:t===null?null:t*e}function oe(){return A({read:(e,t)=>{let n=e.slice(t);return [n,t+n.length]}})}function nt(e){let t=P(e.map(te)),n=P(e.map(ne))??void 0;return A({...t===null?{maxSize:n}:{fixedSize:t},read:(r,o)=>{let i=[];return e.forEach(a=>{let[s,c]=a.read(r,o);i.push(s),o=c;}),[i,o]}})}function rt(e){let t=e.map(([,o])=>o),n=P(t.map(te)),r=P(t.map(ne))??void 0;return A({...n===null?{maxSize:r}:{fixedSize:n},read:(o,i)=>{let a={};return e.forEach(([s,c])=>{let[d,_]=c.read(o,i);i=_,a[s]=d;}),[a,i]}})}var pi=0,ot=128;function it(){return A({maxSize:1,read:(e,t)=>{let n=e[t];if((n&ot)===0)return ["legacy",t];{let r=n^ot;if(r>pi)throw new l(H,{unsupportedVersion:r});return [r,t+1]}}})}function at(){return F(rt([["signatures",re(f(oe(),64),{size:Q()})],["messageBytes",oe()]]),hi)}function hi(e){let{messageBytes:t,signatures:n}=e,r=nt([it(),Ve(ee(),2),re(je(),{size:Q()})]),[o,i,a]=r.decode(t),s=a.slice(0,i);if(s.length!==n.length)throw new l(G,{numRequiredSignatures:i,signaturesLength:n.length,signerAddresses:s});let c={};return s.forEach((d,_)=>{let u=n[_];u.every(I=>I===0)?c[d]=null:c[d]=u;}),{messageBytes:t,signatures:Object.freeze(c)}}function st(e){if(typeof window>"u")throw new Error("Function can only be called in a browser environment");let t=window.innerWidth||window.screen.availWidth,n=window.innerHeight||window.screen.availHeight,r=t<=768,o,i,a,s;if(r)o=t,i=n,a=0,s=0;else {let d=window.screenLeft??window.screenX??0,_=window.screenTop??window.screenY??0,u=window.innerWidth??document.documentElement.clientWidth??window.screen.width,I=window.innerHeight??document.documentElement.clientHeight??window.screen.height;o=500,i=600,s=Math.round(d+(u-o)/2),a=Math.round(_+(I-i)/2);}let c=["popup=yes",`width=${o}`,`height=${i}`,`top=${a}`,`left=${s}`,"toolbar=no","location=no","status=no","menubar=no","scrollbars=yes","resizable=yes"].join(",");return window.open(e??"","_blank",c)}function ct(e){let t=e.domain?`${e.domain} wants you to sign in with your account.`:"Sign in with your account.",n=[];return e.nonce&&n.push(`Nonce: ${e.nonce}`),n.length>0?`${t}
|
|
6
6
|
|
|
7
7
|
${n.join(`
|
|
8
|
-
`)}`:t}async function Xa(e){let{rid:t,redirectOrigin:n}=e.startRequest();await new Promise(i=>setTimeout(i,0));let r={phase:"start",rid:t,validTill:Date.now()+6e5,data:{type:"message",payload:ct({domain:n,nonce:N().decode(crypto.getRandomValues(new Uint8Array(16)))})},redirectOrigin:n},o=new AbortController;return e.sendPayloadToProviderViaPopup({rid:t,signal:o.signal}).catch(i=>o.abort(i)),await e.onClientAuthorizationCallback(r,o.signal,await e.getDeviceSignature(t),e.channelId)}async function Qa(e,t){let{redirectOrigin:n,rid:r}=e.startRequest();await new Promise(T=>setTimeout(T,0));let{instructions:o,signer:i,addressesByLookupTableAddress:a,hasTxManager:s=true}=t,c=prepareTransactionMessage({payer:m(i.walletAddress),instructions:o,addressesByLookupTableAddress:a}),d=await getSettingsFromIndex(i.settingsIndexWithAddress.index),_={transactionMessageBytes:N().decode(c),transactionAddress:d,transactionActionType:s?"execute":"create_with_preauthorized_execution"},u={phase:"start",rid:r,validTill:Date.now()+6e5,data:{type:"transaction",payload:_,sendTx:true,additionalSigners:t.additionalSigners},redirectOrigin:n,signer:i.publicKey},I=new AbortController;return e.sendPayloadToProviderViaPopup({rid:r,signal:I.signal}).catch(T=>I.abort(T)),await e.onClientAuthorizationCallback(u,I.signal,await e.getDeviceSignature(r),e.channelId)}var B="11111111111111111111111111111111";var ut=0,dt=1,It=2,_t=3,At=4,lt=5,Et=6,Rt=7,Tt=8;process.env.NODE_ENV!=="production"&&({[ut]:"an account with the same address already exists",[lt]:"provided address does not match addressed derived from seed",[_t]:"cannot allocate account data of this length",[It]:"cannot assign account to this program id",[At]:"length of requested seed is too long",[Rt]:"stored nonce is still in recent_blockhashes",[Et]:"advancing stored nonce requires a populated RecentBlockhashes sysvar",[Tt]:"specified nonce does not match stored nonce",[dt]:"account does not have enough SOL to perform the operation"});var ie="TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";async function mm(e,t){if(t.amount<=0)throw new Error("Transfer amount must be greater than 0");if(!t.destination||typeof t.destination!="string")throw new Error("Destination address is required");let{rid:n,redirectOrigin:r}=e.startRequest();await new Promise(I=>setTimeout(I,0));let{mint:o,tokenProgram:i=ie,amount:a,destination:s,signer:c}=t,d={transactionActionType:"transfer_intent",transactionAddress:o?i:B,transactionMessageBytes:N().decode(new Uint8Array([...et().encode(a),...J().encode(m(s)),...J().encode(m(o??B))]))},_={phase:"start",rid:n,validTill:Date.now()+6e5,data:{type:"transaction",payload:d,sendTx:true},redirectOrigin:r,signer:c?.publicKey},u=new AbortController;return e.sendPayloadToProviderViaPopup({rid:n,signal:u.signal}).catch(I=>u.abort(I)),await e.onClientAuthorizationCallback(_,u.signal,await e.getDeviceSignature(n),e.channelId)}var p="https://auth.revibase.com";var gt="revibase.com";var Pi="device-keys",h="ed25519-keys",Dt="private-key",Nt="public-key",C=class e{static openDB(){return new Promise((t,n)=>{let r=indexedDB.open(Pi,1);r.onupgradeneeded=()=>{let o=r.result;o.objectStoreNames.contains(h)||o.createObjectStore(h);},r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error);})}static async saveToDB(t,n){let r=await e.openDB();return new Promise((o,i)=>{let a=r.transaction(h,"readwrite");a.objectStore(h).put(n,t),a.oncomplete=()=>o(),a.onerror=()=>i(a.error);})}static async loadFromDB(t){let n=await e.openDB();return new Promise((r,o)=>{let a=n.transaction(h,"readonly").objectStore(h).get(t);a.onsuccess=()=>r(a.result),a.onerror=()=>o(a.error);})}static async create(){let t=await crypto.subtle.generateKey({name:"Ed25519"},false,["sign","verify"]),n=await crypto.subtle.exportKey("jwk",t.publicKey),r=convertJWKToBase64String({...n,alg:"EdDSA"});try{await e.saveToDB(Dt,t.privateKey);}catch(o){throw o instanceof DOMException&&o.name==="DataCloneError"?new Error("Storing device key in this browser is not supported. Try Chrome or ensure you are in a secure context."):o}return await e.saveToDB(Nt,r),r}static async getOrCreateDevicePublickey(){let t=await e.loadFromDB(Nt);return t||(t=await e.create()),{publicKey:t}}static async sign(t){let n=await e.loadFromDB(Dt);if(!n)throw new Error("Device key not found. Call DeviceKeyManager.create() first.");return await new CompactSign(t).setProtectedHeader({alg:"EdDSA"}).sign(n)}};var St=class{pending=new Map;onClientAuthorizationCallback;providerOrigin;popUp=null;channelId=void 0;defaultCallback=async(t,n,r,o)=>{let i=await fetch("/api/clientAuthorization",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({request:t,device:r,channelId:o}),signal:n}),a=await i.json();if(!i.ok)throw new Error(a.error??"Authorization failed");return a};constructor(t,n){this.onClientAuthorizationCallback=t??this.defaultCallback,this.providerOrigin=n??p;}async getDeviceSignature(t){if(this.channelId)return {jwk:(await C.getOrCreateDevicePublickey()).publicKey,jws:await C.sign(new TextEncoder().encode(JSON.stringify({channelId:this.channelId,rid:t})))}}setChannelId(t){this.channelId=t;}async closeChannel(){let t={jwk:(await C.getOrCreateDevicePublickey()).publicKey,jws:await C.sign(new TextEncoder().encode(this.channelId))},n=await fetch(`${this.providerOrigin}/api/channel/close`,{method:"POST",body:JSON.stringify({device:t,channelId:this.channelId})});if(!n.ok){let r=await n.json();throw new Error(r.error??"Unable to close channel")}this.channelId=void 0;}startRequest(){let t=window.origin,n=N().decode(crypto.getRandomValues(new Uint8Array(16)));if(!this.channelId){let r=new URL(this.providerOrigin);if(r.searchParams.set("rid",n),r.searchParams.set("redirectOrigin",t),this.popUp=st(r.toString()),!this.popUp)throw new Error("Popup blocked. Please enable popups.")}return {rid:n,redirectOrigin:t}}async sendPayloadToProviderViaPopup({rid:t,timeoutMs:n=6e5,signal:r}){if(!this.channelId){if(typeof window>"u")throw new Error("Provider can only be used in a browser environment");if(this.pending.size>0)throw new Error("An authorization flow is already in progress");return new Promise((o,i)=>{let a=setTimeout(()=>{let s=this.pending.get(t);s&&(s.cancel?s.cancel(new Error("Authentication timed out")):(this.pending.delete(t),i(new Error("Authentication timed out"))));},n);if(!this.popUp||this.popUp.closed)throw new Error("Popup is not open. Call createNewPopup() first.");this.pending.set(t,{rid:t,resolve:o,reject:i,timeoutId:a}),this.attachTransport({popup:this.popUp,origin:new URL(this.providerOrigin).origin,rid:t,signal:r});})}}attachTransport(t){let{popup:n,origin:r,rid:o,signal:i}=t,a=this.pending.get(o);if(!a)return;let s=null,c=false,d=()=>{u(new Error("Aborted"));},_=()=>{i.removeEventListener("abort",d),window.removeEventListener("message",z);try{s?.close();}catch{}s=null;try{n&&!n.closed&&n.close();}catch{}this.popUp=null,clearInterval(T);},u=S=>{c||(c=true,clearTimeout(a.timeoutId),this.pending.delete(o),_(),a.reject(S));},I=()=>{c||(c=true,clearTimeout(a.timeoutId),this.pending.delete(o),_(),a.resolve({rid:o}));};if(a.cancel=u,i.aborted){u(new Error("Aborted"));return}i.addEventListener("abort",d);let T=setInterval(()=>{n?.closed&&u(new Error("Popup was closed by the user"));},2e3),z=S=>{if(S.origin!==r||S.source!==n)return;let w=S.data;!w||w.type!=="popup-connect"||w.rid!==o||S.ports?.[0]&&(s=S.ports[0],s.start(),s.postMessage({type:"popup-init"}),s.onmessage=se=>{switch(se.data.type){case "popup-complete":I();break;case "popup-error":u(new Error(se.data.error));break;case "popup-closed":{u(new Error("Lost connection with the popup."));break}}},window.removeEventListener("message",z));};window.addEventListener("message",z);}};async function Gm(e,t){let n=new Array(e.transactions.length);for(let r=0;r<e.transactions.length;r++){let{messageBytes:o}=at().decode(Xe().encode(e.transactions[r])),i=await crypto.subtle.sign({name:"Ed25519"},t.keyPair.privateKey,new Uint8Array(o));n[r]=v().decode(new Uint8Array(i));}return {signatures:n}}async function ae({privateKey:e,request:t,providerOrigin:n=p,signal:r,device:o,channelId:i}){let a=convertBase64StringToJWK(e);if(!a.alg)throw new Error("Property alg in JWK is missing.");let s=await new CompactSign(createClientAuthorizationStartRequestChallenge(t)).setProtectedHeader({alg:a.alg}).sign(a),c=await fetch(`${n}/api/startRequest`,{method:"POST",body:JSON.stringify({signature:s,request:t,device:o,channelId:i}),signal:r});if(!c.ok)throw new Error((await c.json()).error);return await c.json()}async function Ct(e,t=p,n=gt){let{payload:r}=e.data;if(r.startRequest.data.type!=="message")throw new Error("Invalid request type.");let o=r.startRequest.data.payload,i=createMessageChallenge(o,r.client.clientOrigin,r.device.jwk,r.startRequest.rid),{verified:a}=await verifyAuthenticationResponse({response:r.authResponse,expectedChallenge:bufferToBase64URLString(i),expectedRPID:n,expectedOrigin:t,requireUserVerification:false,credential:{counter:0,id:r.authResponse.id,publicKey:convertPubkeyCompressedToCose(r.signer)}});if(!a)throw new Error("WebAuthn message verification failed");let s=r.additionalInfo?.settingsIndexWithAddress;if(!s)throw new Error("User is not delegated");let c=await getWalletAddressFromIndex(s.index);return {user:UserInfoSchema.parse({publicKey:r.signer,walletAddress:c,settingsIndexWithAddress:s,...r.additionalInfo})}}async function op({request:e,privateKey:t,providerOrigin:n,rpId:r,signal:o,device:i,channelId:a}){let s=Xi.union([StartMessageRequestSchema,StartTransactionRequestSchema]).parse(e),{data:c,signer:d,redirectOrigin:_,rid:u}=s;if(c.type==="message"){let T=await ae({request:{phase:"start",redirectOrigin:_,signer:d,rid:u,validTill:Date.now()+6e5,data:{type:"message",payload:c.payload}},privateKey:t,providerOrigin:n,signal:o,device:i,channelId:a});return Ct({data:T.data},n,r)}let I=await ae({request:{phase:"start",redirectOrigin:_,signer:d,rid:u,validTill:Date.now()+6e5,data:{type:"transaction",payload:c.payload,sendTx:true,additionalSigners:c.additionalSigners}},providerOrigin:n,privateKey:t,signal:o,device:i,channelId:a});return {txSig:I.data.payload.txSig,user:I.data.payload.user}}
|
|
8
|
+
`)}`:t}async function Xa(e){let{rid:t,redirectOrigin:n}=e.startRequest();await new Promise(i=>setTimeout(i,0));let r={phase:"start",rid:t,validTill:Date.now()+6e5,data:{type:"message",payload:ct({domain:n,nonce:S().decode(crypto.getRandomValues(new Uint8Array(16)))})},redirectOrigin:n},o=new AbortController;return e.sendPayloadToProviderViaPopup({rid:t,signal:o.signal}).catch(i=>o.abort(i)),await e.onClientAuthorizationCallback(r,o.signal,await e.getDeviceSignature(t),e.channelId)}async function Qa(e,t){let{redirectOrigin:n,rid:r}=e.startRequest();await new Promise(T=>setTimeout(T,0));let{instructions:o,signer:i,addressesByLookupTableAddress:a,hasTxManager:s=true}=t,c=prepareTransactionMessage({payer:m(i.walletAddress),instructions:o,addressesByLookupTableAddress:a}),d=await getSettingsFromIndex(i.settingsIndexWithAddress.index),_={transactionMessageBytes:S().decode(c),transactionAddress:d,transactionActionType:s?"execute":"create_with_preauthorized_execution"},u={phase:"start",rid:r,validTill:Date.now()+6e5,data:{type:"transaction",payload:_,sendTx:true,additionalSigners:t.additionalSigners},redirectOrigin:n,signer:i.publicKey},I=new AbortController;return e.sendPayloadToProviderViaPopup({rid:r,signal:I.signal}).catch(T=>I.abort(T)),await e.onClientAuthorizationCallback(u,I.signal,await e.getDeviceSignature(r),e.channelId)}var B="11111111111111111111111111111111";var ut=0,dt=1,It=2,_t=3,At=4,lt=5,Et=6,Rt=7,Tt=8;process.env.NODE_ENV!=="production"&&({[ut]:"an account with the same address already exists",[lt]:"provided address does not match addressed derived from seed",[_t]:"cannot allocate account data of this length",[It]:"cannot assign account to this program id",[At]:"length of requested seed is too long",[Rt]:"stored nonce is still in recent_blockhashes",[Et]:"advancing stored nonce requires a populated RecentBlockhashes sysvar",[Tt]:"specified nonce does not match stored nonce",[dt]:"account does not have enough SOL to perform the operation"});var ie="TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";async function mm(e,t){if(t.amount<=0)throw new Error("Transfer amount must be greater than 0");if(!t.destination||typeof t.destination!="string")throw new Error("Destination address is required");let{rid:n,redirectOrigin:r}=e.startRequest();await new Promise(I=>setTimeout(I,0));let{mint:o,tokenProgram:i=ie,amount:a,destination:s,signer:c}=t,d={transactionActionType:"transfer_intent",transactionAddress:o?i:B,transactionMessageBytes:S().decode(new Uint8Array([...et().encode(a),...J().encode(m(s)),...J().encode(m(o??B))]))},_={phase:"start",rid:n,validTill:Date.now()+6e5,data:{type:"transaction",payload:d,sendTx:true},redirectOrigin:r,signer:c?.publicKey},u=new AbortController;return e.sendPayloadToProviderViaPopup({rid:n,signal:u.signal}).catch(I=>u.abort(I)),await e.onClientAuthorizationCallback(_,u.signal,await e.getDeviceSignature(n),e.channelId)}var p="https://auth.revibase.com";var gt="revibase.com";var Pi="device-keys",h="ed25519-keys",Dt="private-key",Nt="public-key",N=class e{static openDB(){return new Promise((t,n)=>{let r=indexedDB.open(Pi,1);r.onupgradeneeded=()=>{let o=r.result;o.objectStoreNames.contains(h)||o.createObjectStore(h);},r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error);})}static async saveToDB(t,n){let r=await e.openDB();return new Promise((o,i)=>{let a=r.transaction(h,"readwrite");a.objectStore(h).put(n,t),a.oncomplete=()=>o(),a.onerror=()=>i(a.error);})}static async loadFromDB(t){let n=await e.openDB();return new Promise((r,o)=>{let a=n.transaction(h,"readonly").objectStore(h).get(t);a.onsuccess=()=>r(a.result),a.onerror=()=>o(a.error);})}static async create(){let t=await crypto.subtle.generateKey({name:"Ed25519"},false,["sign","verify"]),n=await crypto.subtle.exportKey("jwk",t.publicKey),r=convertJWKToBase64String({...n,alg:"EdDSA"});try{await e.saveToDB(Dt,t.privateKey);}catch(o){throw o instanceof DOMException&&o.name==="DataCloneError"?new Error("Storing device key in this browser is not supported. Try Chrome or ensure you are in a secure context."):o}return await e.saveToDB(Nt,r),r}static async getOrCreateDevicePublickey(){let t=await e.loadFromDB(Nt);return t||(t=await e.create()),{publicKey:t}}static async sign(t){let n=await e.loadFromDB(Dt);if(!n)throw new Error("Device key not found. Call DeviceKeyManager.create() first.");return await new CompactSign(t).setProtectedHeader({alg:"EdDSA"}).sign(n)}};var St=class{pending=new Map;onClientAuthorizationCallback;providerOrigin;popUp=null;channelId=void 0;defaultCallback=async(t,n,r,o)=>{let i=await fetch("/api/clientAuthorization",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({request:t,device:r,channelId:o}),signal:n}),a=await i.json();if(!i.ok)throw new Error(a.error??"Authorization failed");return a};constructor(t,n){this.onClientAuthorizationCallback=t??this.defaultCallback,this.providerOrigin=n??p;}async getDeviceSignature(t){if(this.channelId)return {jwk:(await N.getOrCreateDevicePublickey()).publicKey,jws:await N.sign(new TextEncoder().encode(JSON.stringify({channelId:this.channelId,rid:t})))}}async createChannel(){if(this.channelId)throw new Error("Close your existing channel before creating a new one.");let t=await fetch(`${this.providerOrigin}/api/channel/challenge`);if(!t.ok){let s=await t.json();throw new Error(s.error??"Unable to generate challenge")}let{id:n,challenge:r}=await t.json(),o={jwk:(await N.getOrCreateDevicePublickey()).publicKey,jws:await N.sign(new TextEncoder().encode(r))},i=await fetch(`${this.providerOrigin}/api/channel/create`,{method:"POST",body:JSON.stringify({device:o,challengeId:n})});if(!i.ok){let s=await i.json();throw new Error(s.error??"Unable to create channel")}let{channelId:a}=await i.json();return this.channelId=a,{channelId:a,url:`${this.providerOrigin}?channelId=${a}`}}async closeChannel(){let t={jwk:(await N.getOrCreateDevicePublickey()).publicKey,jws:await N.sign(new TextEncoder().encode(this.channelId))},n=await fetch(`${this.providerOrigin}/api/channel/close`,{method:"POST",body:JSON.stringify({device:t,channelId:this.channelId})});if(!n.ok){let r=await n.json();throw new Error(r.error??"Unable to close channel")}this.channelId=void 0;}startRequest(){let t=window.origin,n=S().decode(crypto.getRandomValues(new Uint8Array(16)));if(!this.channelId){let r=new URL(this.providerOrigin);if(r.searchParams.set("rid",n),r.searchParams.set("redirectOrigin",t),this.popUp=st(r.toString()),!this.popUp)throw new Error("Popup blocked. Please enable popups.")}return {rid:n,redirectOrigin:t}}async sendPayloadToProviderViaPopup({rid:t,timeoutMs:n=6e5,signal:r}){if(!this.channelId){if(typeof window>"u")throw new Error("Provider can only be used in a browser environment");if(this.pending.size>0)throw new Error("An authorization flow is already in progress");return new Promise((o,i)=>{let a=setTimeout(()=>{let s=this.pending.get(t);s&&(s.cancel?s.cancel(new Error("Authentication timed out")):(this.pending.delete(t),i(new Error("Authentication timed out"))));},n);if(!this.popUp||this.popUp.closed)throw new Error("Popup is not open. Call createNewPopup() first.");this.pending.set(t,{rid:t,resolve:o,reject:i,timeoutId:a}),this.attachTransport({popup:this.popUp,origin:new URL(this.providerOrigin).origin,rid:t,signal:r});})}}attachTransport(t){let{popup:n,origin:r,rid:o,signal:i}=t,a=this.pending.get(o);if(!a)return;let s=null,c=false,d=()=>{u(new Error("Aborted"));},_=()=>{i.removeEventListener("abort",d),window.removeEventListener("message",z);try{s?.close();}catch{}s=null;try{n&&!n.closed&&n.close();}catch{}this.popUp=null,clearInterval(T);},u=C=>{c||(c=true,clearTimeout(a.timeoutId),this.pending.delete(o),_(),a.reject(C));},I=()=>{c||(c=true,clearTimeout(a.timeoutId),this.pending.delete(o),_(),a.resolve({rid:o}));};if(a.cancel=u,i.aborted){u(new Error("Aborted"));return}i.addEventListener("abort",d);let T=setInterval(()=>{n?.closed&&u(new Error("Popup was closed by the user"));},2e3),z=C=>{if(C.origin!==r||C.source!==n)return;let w=C.data;!w||w.type!=="popup-connect"||w.rid!==o||C.ports?.[0]&&(s=C.ports[0],s.start(),s.postMessage({type:"popup-init"}),s.onmessage=se=>{switch(se.data.type){case "popup-complete":I();break;case "popup-error":u(new Error(se.data.error));break;case "popup-closed":{u(new Error("Lost connection with the popup."));break}}},window.removeEventListener("message",z));};window.addEventListener("message",z);}};async function Gm(e,t){let n=new Array(e.transactions.length);for(let r=0;r<e.transactions.length;r++){let{messageBytes:o}=at().decode(Xe().encode(e.transactions[r])),i=await crypto.subtle.sign({name:"Ed25519"},t.keyPair.privateKey,new Uint8Array(o));n[r]=v().decode(new Uint8Array(i));}return {signatures:n}}async function ae({privateKey:e,request:t,providerOrigin:n=p,signal:r,device:o,channelId:i}){let a=convertBase64StringToJWK(e);if(!a.alg)throw new Error("Property alg in JWK is missing.");let s=await new CompactSign(createClientAuthorizationStartRequestChallenge(t)).setProtectedHeader({alg:a.alg}).sign(a),c=await fetch(`${n}/api/startRequest`,{method:"POST",body:JSON.stringify({signature:s,request:t,device:o,channelId:i}),signal:r});if(!c.ok)throw new Error((await c.json()).error);return await c.json()}async function Ct(e,t=p,n=gt){let{payload:r}=e.data;if(r.startRequest.data.type!=="message")throw new Error("Invalid request type.");let o=r.startRequest.data.payload,i=createMessageChallenge(o,r.client.clientOrigin,r.device.jwk,r.startRequest.rid),{verified:a}=await verifyAuthenticationResponse({response:r.authResponse,expectedChallenge:bufferToBase64URLString(i),expectedRPID:n,expectedOrigin:t,requireUserVerification:false,credential:{counter:0,id:r.authResponse.id,publicKey:convertPubkeyCompressedToCose(r.signer)}});if(!a)throw new Error("WebAuthn message verification failed");let s=r.additionalInfo?.settingsIndexWithAddress;if(!s)throw new Error("User is not delegated");let c=await getWalletAddressFromIndex(s.index);return {user:UserInfoSchema.parse({publicKey:r.signer,walletAddress:c,settingsIndexWithAddress:s,...r.additionalInfo})}}async function op({request:e,privateKey:t,providerOrigin:n,rpId:r,signal:o,device:i,channelId:a}){let s=Xi.union([StartMessageRequestSchema,StartTransactionRequestSchema]).parse(e),{data:c,signer:d,redirectOrigin:_,rid:u}=s;if(c.type==="message"){let T=await ae({request:{phase:"start",redirectOrigin:_,signer:d,rid:u,validTill:Date.now()+6e5,data:{type:"message",payload:c.payload}},privateKey:t,providerOrigin:n,signal:o,device:i,channelId:a});return Ct({data:T.data},n,r)}let I=await ae({request:{phase:"start",redirectOrigin:_,signer:d,rid:u,validTill:Date.now()+6e5,data:{type:"transaction",payload:c.payload,sendTx:true,additionalSigners:c.additionalSigners}},providerOrigin:n,privateKey:t,signal:o,device:i,channelId:a});return {txSig:I.data.payload.txSig,user:I.data.payload.user}}
|
|
9
9
|
export{St as RevibaseProvider,Gm as createTransactionSigner,Qa as executeTransaction,op as processClientAuthCallback,Xa as signIn,mm as transferTokens};//# sourceMappingURL=index.js.map
|
|
10
10
|
//# sourceMappingURL=index.js.map
|