@solana/transactions 2.0.0-experimental.fe07532 → 2.0.0-experimental.ffeddf6
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.browser.cjs +2 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +0 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +2 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +9 -9
- package/dist/types/compilable-transaction.d.ts +6 -0
- package/dist/types/compile-transaction.d.ts +3 -4
- package/dist/types/decompile-transaction.d.ts +2 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/serializers/transaction.d.ts +1 -3
- package/dist/types/signatures.d.ts +3 -3
- package/package.json +9 -9
|
@@ -2,27 +2,27 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
function N(e,n,r=0){if(n.length-r<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function w(e,n,r,t=0){let o=r.length-t;if(o<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${o}.`)}var k=e=>{let n=e.filter(i=>i.length);if(n.length===0)return e.length?e[0]:new Uint8Array;if(n.length===1)return n[0];let r=n.reduce((i,s)=>i+s.length,0),t=new Uint8Array(r),o=0;return n.forEach(i=>{t.set(i,o),o+=i.length;}),t},Bn=(e,n)=>{if(e.length>=n)return e;let r=new Uint8Array(n).fill(0);return r.set(e),r},Z=(e,n)=>Bn(e.length<=n?e:e.slice(0,n),n);function z(e,n,r){if(e.fixedSize!==n.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${n.fixedSize}].`);if(e.maxSize!==n.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${n.maxSize}].`);if(r===void 0&&e.description!==n.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${n.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:n.decode,description:r??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function ge(e,n,r){return {description:r??`fixed(${n}, ${e.description})`,fixedSize:n,maxSize:n}}function U(e,n,r){return {...ge(e,n,r),encode:t=>Z(e.encode(t),n)}}function O(e,n,r){return {...ge(e,n,r),decode:(t,o=0)=>{w("fixCodec",n,t,o),(o>0||t.length>n)&&(t=t.slice(o,o+n)),e.fixedSize!==null&&(t=Z(t,e.fixedSize));let[i]=e.decode(t,0);return [i,o+n]}}}function B(e,n){return {description:e.description,encode:r=>e.encode(n(r)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function D(e,n){return {decode:(r,t=0)=>{let[o,i]=e.decode(r,t);return [n(o,r,t),i]},description:e.description,fixedSize:e.fixedSize,maxSize:e.maxSize}}function pe(e,n,r,t){if(t<n||t>r)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${r}], got ${t}.`)}function me(e){let n,r=e.name;return e.size>1&&(n=!("endian"in e.options)||e.options.endian===0,r+=n?"(le)":"(be)"),{description:e.options.description??r,fixedSize:e.size,littleEndian:n,maxSize:e.size}}function Te(e){let n=me(e);return {description:n.description,encode(r){e.range&&pe(e.name,e.range[0],e.range[1],r);let t=new ArrayBuffer(e.size);return e.set(new DataView(t),r,n.littleEndian),new Uint8Array(t)},fixedSize:n.fixedSize,maxSize:n.maxSize}}function ye(e){let n=me(e);return {decode(r,t=0){N(n.description,r,t),w(n.description,e.size,r,t);let o=new DataView(wn(r,t,e.size));return [e.get(o,n.littleEndian),t+e.size]},description:n.description,fixedSize:n.fixedSize,maxSize:n.maxSize}}function wn(e,n,r){let t=e.byteOffset+(n??0),o=r??e.byteLength;return e.buffer.slice(t,t+o)}var m=(e={})=>({description:e.description??"shortU16",encode:n=>{pe("shortU16",0,65535,n);let r=[0];for(let t=0;;t+=1){let o=n>>t*7;if(o===0)break;let i=127&o;r[t]=i,t>0&&(r[t-1]|=128);}return new Uint8Array(r)},fixedSize:null,maxSize:3}),T=(e={})=>({decode:(n,r=0)=>{let t=0,o=0;for(;++o;){let i=o-1,s=n[r+i],c=127&s;if(t|=c<<i*7,!(s&128))break}return [t,r+o]},description:e.description??"shortU16",fixedSize:null,maxSize:3});var P=(e={})=>Te({name:"u32",options:e,range:[0,+"0xffffffff"],set:(n,r,t)=>n.setUint32(0,r,t),size:4}),W=(e={})=>ye({get:(n,r)=>n.getUint32(0,r),name:"u32",options:e,size:4});var S=(e={})=>Te({name:"u8",options:e,range:[0,+"0xff"],set:(n,r)=>n.setUint8(0,r),size:1}),x=(e={})=>ye({get:n=>n.getUint8(0),name:"u8",options:e,size:1});function Dn(e,n,r=n){if(!n.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${r}].`)}var vn=e=>{let n=e.length,r=BigInt(n);return {description:`base${n}`,encode(t){if(Dn(e,t),t==="")return new Uint8Array;let o=[...t],i=o.findIndex(p=>p!==e[0]);i=i===-1?o.length:i;let s=Array(i).fill(0);if(i===o.length)return Uint8Array.from(s);let c=o.slice(i),u=0n,a=1n;for(let p=c.length-1;p>=0;p-=1)u+=a*BigInt(e.indexOf(c[p])),a*=r;let l=[];for(;u>0n;)l.unshift(Number(u%256n)),u/=256n;return Uint8Array.from(s.concat(l))},fixedSize:null,maxSize:null}},Nn=e=>{let n=e.length,r=BigInt(n);return {decode(t,o=0){let i=o===0?t:t.slice(o);if(i.length===0)return ["",0];let s=i.findIndex(l=>l!==0);s=s===-1?i.length:s;let c=e[0].repeat(s);if(s===i.length)return [c,t.length];let u=i.slice(s).reduce((l,p)=>l*256n+BigInt(p),0n),a=[];for(;u>0n;)a.unshift(e[Number(u%r)]),u/=r;return [c+a.join(""),t.length]},description:`base${n}`,fixedSize:null,maxSize:null}};var Ae="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",I=()=>vn(Ae),_=()=>Nn(Ae);var kn=e=>e.replace(/\u0000/g,"");var _n=globalThis.TextDecoder,Ln=globalThis.TextEncoder,Rn=()=>{let e;return {description:"utf8",encode:n=>new Uint8Array((e||(e=new Ln)).encode(n)),fixedSize:null,maxSize:null}},Mn=()=>{let e;return {decode(n,r=0){let t=(e||(e=new _n)).decode(n.slice(r));return [kn(t),n.length]},description:"utf8",fixedSize:null,maxSize:null}};var $=(e={})=>{let n=e.size??P(),r=e.encoding??Rn(),t=e.description??`string(${r.description}; ${he(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?U(r,n,t):{description:t,encode:o=>{let i=r.encode(o),s=n.encode(i.length);return k([s,i])},fixedSize:null,maxSize:null}},V=(e={})=>{let n=e.size??W(),r=e.encoding??Mn(),t=e.description??`string(${r.description}; ${he(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?O(r,n,t):{decode:(o,i=0)=>{N("string",o,i);let[s,c]=n.decode(o,i),u=Number(s);i=c;let a=o.slice(i,i+u);w("string",u,a);let[l,p]=r.decode(a);return i+=p,[l,i]},description:t,fixedSize:null,maxSize:null}};function he(e){return typeof e=="object"?e.description:`${e}`}function C(e){if("signatures"in e){let{signatures:n,...r}=e;return r}else return e}var J;function Cr(e){J||(J=I());try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let r=J.encode(e).byteLength;if(r!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${r}`)}catch(n){throw new Error(`\`${e}\` is not a blockhash`,{cause:n})}}function be(e,n){if("lifetimeConstraint"in n&&n.lifetimeConstraint.blockhash===e.blockhash&&n.lifetimeConstraint.lastValidBlockHeight===e.lastValidBlockHeight)return n;let r={...C(n),lifetimeConstraint:e};return Object.freeze(r),r}function Ee({version:e}){let n={instructions:[],version:e};return Object.freeze(n),n}var g=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(g||{});var Un=1;function y(e){return e>=2}function v(e){return (e&Un)!==0}function Q(e,n){return e|n}var xe="SysvarRecentB1ockHashes11111111111111111111",Ie="11111111111111111111111111111111";function $r(e){if(!Ce(e))throw new Error("Transaction is not a durable nonce transaction")}function Se(e,n){return {accounts:[{address:e,role:g.WRITABLE},{address:xe,role:g.READONLY},{address:n,role:g.READONLY_SIGNER}],data:new Uint8Array([4,0,0,0]),programAddress:Ie}}function F(e){return e.programAddress===Ie&&e.data!=null&&On(e.data)&&e.accounts?.length===3&&e.accounts[0].address!=null&&e.accounts[0].role===g.WRITABLE&&e.accounts[1].address===xe&&e.accounts[1].role===g.READONLY&&e.accounts[2].address!=null&&y(e.accounts[2].role)}function On(e){return e.byteLength===4&&e[0]===4&&e[1]===0&&e[2]===0&&e[3]===0}function Ce(e){return "lifetimeConstraint"in e&&typeof e.lifetimeConstraint.nonce=="string"&&e.instructions[0]!=null&&F(e.instructions[0])}function Pn(e,n,r){return e.accounts[0].address===n&&e.accounts[2].address===r}function ze({nonce:e,nonceAccountAddress:n,nonceAuthorityAddress:r},t){let o,i=t.instructions[0];if(i&&F(i))if(Pn(i,n,r)){if(Ce(t)&&t.lifetimeConstraint.nonce===e)return t;o=[i,...t.instructions.slice(1)];}else o=[Se(n,r),...t.instructions.slice(1)];else o=[Se(n,r),...t.instructions];let s={...C(t),instructions:o,lifetimeConstraint:{nonce:e}};return Object.freeze(s),s}function Be(e,n){if("feePayer"in n&&e===n.feePayer)return n;let r={...C(n),feePayer:e};return Object.freeze(r),r}function we(e,n){let r={...C(n),instructions:[...n.instructions,e]};return Object.freeze(r),r}function qr(e,n){let r={...C(n),instructions:[e,...n.instructions]};return Object.freeze(r),r}function H(e){return e.reduce((n,r)=>n===null||r===null?null:n+r,0)}function Wn(e,n,r,t){if(typeof e=="number")return [e,t];if(typeof e=="object")return e.decode(r,t);if(e==="remainder"){let o=H(n);if(o===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');let i=r.slice(t).length;if(i%o!==0)throw new Error(`The remainder of the byte array (${i} bytes) cannot be split into chunks of ${o} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${i} modulo ${o} should be equal to zero.`);return [i/o,t]}throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(e)}`)}function $n(e){return typeof e=="object"?e.description:`${e}`}function De(e,n){if(typeof e!="number")return null;if(e===0)return 0;let r=H(n);return r===null?null:r*e}function Vn(e,n){return typeof e=="object"?e.encode(n):new Uint8Array}function Fn(e,n,r){if(n!==r)throw new Error(`Expected [${e}] to have ${n} items, got ${r}.`)}function ve(e,n,r){if(n==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:r??`array(${e.description}; ${$n(n)})`,fixedSize:De(n,[e.fixedSize]),maxSize:De(n,[e.maxSize])}}function A(e,n={}){let r=n.size??P();return {...ve(e,r,n.description),encode:t=>(typeof r=="number"&&Fn("array",r,t.length),k([Vn(r,t.length),...t.map(o=>e.encode(o))]))}}function h(e,n={}){let r=n.size??W();return {...ve(e,r,n.description),decode:(t,o=0)=>{if(typeof r=="object"&&t.slice(o).length===0)return [[],o];let[i,s]=Wn(r,[e.fixedSize],t,o);o=s;let c=[];for(let u=0;u<i;u+=1){let[a,l]=e.decode(t,o);c.push(a),o=l;}return [c,o]}}}function K(e={}){let n=e.size??"variable",r=typeof n=="object"?n.description:`${n}`,t=e.description??`bytes(${r})`,o={description:t,encode:i=>i,fixedSize:null,maxSize:null};return n==="variable"?o:typeof n=="number"?U(o,n,t):{...o,encode:i=>{let s=o.encode(i),c=n.encode(s.length);return k([c,s])}}}function j(e={}){let n=e.size??"variable",r=typeof n=="object"?n.description:`${n}`,t=e.description??`bytes(${r})`,o={decode:(i,s=0)=>{let c=i.slice(s);return [c,s+c.length]},description:t,fixedSize:null,maxSize:null};return n==="variable"?o:typeof n=="number"?O(o,n,t):{...o,decode:(i,s=0)=>{N("bytes",i,s);let[c,u]=n.decode(i,s),a=Number(c);s=u;let l=i.slice(s,s+a);w("bytes",a,l);let[p,zn]=o.decode(l);return s+=zn,[p,s]}}}function Ne(e,n){let r=e.map(([t,o])=>`${String(t)}: ${o.description}`).join(", ");return {description:n??`struct(${r})`,fixedSize:H(e.map(([,t])=>t.fixedSize)),maxSize:H(e.map(([,t])=>t.maxSize))}}function b(e,n={}){return {...Ne(e,n.description),encode:r=>{let t=e.map(([o,i])=>i.encode(r[o]));return k(t)}}}function E(e,n={}){return {...Ne(e,n.description),decode:(r,t=0)=>{let o={};return e.forEach(([i,s])=>{let[c,u]=s.decode(r,t);t=u,o[i]=c;}),[o,t]}}}function ke(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}async function _e(){if(ke(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function Le(){if(ke(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}var ee,ne;function Re(){return ee||(ee=I()),ee}function Hn(){return ne||(ne=_()),ne}function Y(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=Re().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(n){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:n})}}function Kn(e){return Y(e),e}function q(e){return B($({description:e?.description??"Base58EncodedAddress",encoding:Re(),size:32}),n=>Kn(n))}function R(e){return V({description:e?.description??"Base58EncodedAddress",encoding:Hn(),size:32})}function M(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}async function Me(e){if(await _e(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let n=await crypto.subtle.exportKey("raw",e),[r]=R().decode(new Uint8Array(n));return r}function Ue(e,n,r){e[n]=r(e[n]??{role:g.READONLY});}var f=Symbol("AddressMapTypeProperty");function Oe(e,n){let r={[e]:{[f]:0,role:g.WRITABLE_SIGNER}},t=new Set;for(let o of n){Ue(r,o.programAddress,s=>{if(t.add(o.programAddress),f in s){if(v(s.role))switch(s[f]){case 0:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`);default:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`)}if(s[f]===2)return s}return {[f]:2,role:g.READONLY}});let i;if(o.accounts)for(let s of o.accounts)Ue(r,s.address,c=>{let{address:u,...a}=s;if(f in c)switch(c[f]){case 0:return c;case 1:{let l=Q(c.role,a.role);if("lookupTableAddress"in a){if(c.lookupTableAddress!==a.lookupTableAddress&&(i||(i=M()))(a.lookupTableAddress,c.lookupTableAddress)<0)return {[f]:1,...a,role:l}}else if(y(a.role))return {[f]:2,role:l};return c.role!==l?{...c,role:l}:c}case 2:{let l=Q(c.role,a.role);if(t.has(s.address)){if(v(a.role))throw new Error(`This transaction includes an address (\`${s.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`);return c.role!==l?{...c,role:l}:c}else return "lookupTableAddress"in a&&!y(c.role)?{...a,[f]:1,role:l}:c.role!==l?{...c,role:l}:c}}return "lookupTableAddress"in a?{...a,[f]:1}:{...a,[f]:2}});}return r}function Pe(e){let n;return Object.entries(e).sort(([t,o],[i,s])=>{if(o[f]!==s[f]){if(o[f]===0)return -1;if(s[f]===0)return 1;if(o[f]===2)return -1;if(s[f]===2)return 1}let c=y(o.role);if(c!==y(s.role))return c?-1:1;let u=v(o.role);return u!==v(s.role)?u?-1:1:(n||(n=M()),o[f]===1&&s[f]===1&&o.lookupTableAddress!==s.lookupTableAddress?n(o.lookupTableAddress,s.lookupTableAddress):n(t,i))}).map(([t,o])=>({address:t,...o}))}function We(e){var r;let n={};for(let t of e){if(!("lookupTableAddress"in t))continue;let o=n[r=t.lookupTableAddress]||(n[r]={readableIndices:[],writableIndices:[]});t.role===g.WRITABLE?o.writableIndices.push(t.addressIndex):o.readableIndices.push(t.addressIndex);}return Object.keys(n).sort(M()).map(t=>({lookupTableAddress:t,...n[t]}))}function $e(e){let n=0,r=0,t=0;for(let o of e){if("lookupTableAddress"in o)break;let i=v(o.role);y(o.role)?(t++,i||r++):i||n++;}return {numReadonlyNonSignerAccounts:n,numReadonlySignerAccounts:r,numSignerAccounts:t}}function jn(e){let n={};for(let[r,t]of e.entries())n[t.address]=r;return n}function Ve(e,n){let r=jn(n);return e.map(({accounts:t,data:o,programAddress:i})=>({programAddressIndex:r[i],...t?{accountIndices:t.map(({address:s})=>r[s])}:null,...o?{data:o}:null}))}function Fe(e){return "nonce"in e?e.nonce:e.blockhash}function He(e){let n=e.findIndex(t=>"lookupTableAddress"in t);return (n===-1?e:e.slice(0,n)).map(({address:t})=>t)}function G(e){let n=Oe(e.feePayer,e.instructions),r=Pe(n);return {...e.version!=="legacy"?{addressTableLookups:We(r)}:null,header:$e(r),instructions:Ve(e.instructions,r),lifetimeToken:Fe(e.lifetimeConstraint),staticAccounts:He(r),version:e.version}}function Ke(e){let n=G(e),r;if("signatures"in e){r=[];for(let t=0;t<n.header.numSignerAccounts;t++)r[t]=e.signatures[n.staticAccounts[t]]??new Uint8Array(Array(64).fill(0));}else r=Array(n.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));return {compiledMessage:n,signatures:r}}function je(e,...n){return n.reduce((r,t)=>t(r),e)}function Yn(e){let{header:n}=e,r=n.numSignerAccounts-n.numReadonlySignerAccounts,t=e.staticAccounts.length-n.numSignerAccounts-n.numReadonlyNonSignerAccounts,o=[],i=0;for(let s=0;s<r;s++)o.push({address:e.staticAccounts[i],role:g.WRITABLE_SIGNER}),i++;for(let s=0;s<n.numReadonlySignerAccounts;s++)o.push({address:e.staticAccounts[i],role:g.READONLY_SIGNER}),i++;for(let s=0;s<t;s++)o.push({address:e.staticAccounts[i],role:g.WRITABLE}),i++;for(let s=0;s<n.numReadonlyNonSignerAccounts;s++)o.push({address:e.staticAccounts[i],role:g.READONLY}),i++;return o}function qn(e,n){let r=n[e.programAddressIndex]?.address;if(!r)throw new Error(`Could not find program address at index ${e.programAddressIndex}`);let t=e.accountIndices?.map(i=>n[i]),{data:o}=e;return {programAddress:r,...t&&t.length?{accounts:t}:{},...o&&o.length?{data:o}:{}}}function Gn(e,n,r){if(!n||!F(n))return {blockhash:e,lastValidBlockHeight:r??2n**64n-1n};{let t=n.accounts[0].address;Y(t);let o=n.accounts[2].address;return Y(o),{nonce:e,nonceAccountAddress:t,nonceAuthorityAddress:o}}}function Xn(e){let{compiledMessage:{staticAccounts:n},signatures:r}=e;return r.reduce((t,o,i)=>{if(o.every(u=>u===0))return t;let c=n[i];return {...t,[c]:o}},{})}function Ye(e,n){let{compiledMessage:r}=e;if("addressTableLookups"in r&&r.addressTableLookups.length>0)throw new Error("Cannot convert transaction with addressTableLookups");let t=r.staticAccounts[0];if(!t)throw new Error("No fee payer set in CompiledTransaction");let o=Yn(r),i=r.instructions.map(a=>qn(a,o)),s=i[0],c=Gn(r.lifetimeToken,s,n),u=Xn(e);return je(Ee({version:r.version}),a=>Be(t,a),a=>i.reduce((l,p)=>we(p,l),a),a=>"blockhash"in c?be(c,a):ze(c,a),a=>e.signatures.length?{...a,signatures:u}:a)}var qe="lookupTableAddress",Ge="writableIndices",Xe="readableIndices",Ze="addressTableLookup",re;function Je(){return re||(re=b([["lookupTableAddress",q({description:qe})],["writableIndices",A(S(),{description:Ge,size:m()})],["readableIndices",A(S(),{description:Xe,size:m()})]],{description:Ze})),re}var te;function Qe(){return te||(te=E([["lookupTableAddress",R({description:qe})],["writableIndices",h(x(),{description:Ge,size:T()})],["readableIndices",h(x(),{description:Xe,size:T()})]],{description:Ze})),te}var oe;function Zn(){return oe||(oe=S()),oe}function ie(e){let n=Zn();return {...n,description:e??n.description}}var se;function Jn(){return se||(se=x()),se}function ce(e){let n=Jn();return {...n,description:e??n.description}}var en=void 0,nn=void 0,rn=void 0,tn=void 0;function on(){return b([["numSignerAccounts",ie(en)],["numReadonlySignerAccounts",ie(nn)],["numReadonlyNonSignerAccounts",ie(rn)]],{description:tn})}function sn(){return E([["numSignerAccounts",ce(en)],["numReadonlySignerAccounts",ce(nn)],["numReadonlyNonSignerAccounts",ce(rn)]],{description:tn})}var cn="programAddressIndex",an=void 0,dn="accountIndices",un="data",ae;function ln(){return ae||(ae=B(b([["programAddressIndex",S({description:cn})],["accountIndices",A(S({description:an}),{description:dn,size:m()})],["data",K({description:un,size:m()})]]),e=>e.accountIndices!==void 0&&e.data!==void 0?e:{...e,accountIndices:e.accountIndices??[],data:e.data??new Uint8Array(0)})),ae}var de;function fn(){return de||(de=D(E([["programAddressIndex",x({description:cn})],["accountIndices",h(x({description:an}),{description:dn,size:T()})],["data",j({description:un,size:T()})]]),e=>{if(e.accountIndices.length&&e.data.byteLength)return e;let{accountIndices:n,data:r,...t}=e;return {...t,...n.length?{accountIndices:n}:null,...r.byteLength?{data:r}:null}})),de}var ue=128,gn={description:"",fixedSize:null,maxSize:1};function Qn(e,n=0){let r=e[n];return r&ue?[r^ue,n+1]:["legacy",n]}function er(e){if(e==="legacy")return new Uint8Array;if(e<0||e>127)throw new Error(`Transaction version must be in the range [0, 127]. \`${e}\` given.`);return new Uint8Array([e|ue])}function pn(){return {...gn,decode:Qn}}function mn(){return {...gn,encode:er}}var Tn="staticAccounts",yn="lifetimeToken",An="instructions",hn="addressTableLookups";function nr(){return b(bn())}function rr(){return B(b([...bn(),["addressTableLookups",or()]]),e=>e.version==="legacy"?e:{...e,addressTableLookups:e.addressTableLookups??[]})}function bn(){return [["version",mn()],["header",on()],["staticAccounts",A(q(),{description:Tn,size:m()})],["lifetimeToken",$({description:yn,encoding:I(),size:32})],["instructions",A(ln(),{description:An,size:m()})]]}function tr(){return [["version",pn()],["header",sn()],["staticAccounts",h(R(),{description:Tn,size:T()})],["lifetimeToken",V({description:yn,encoding:_(),size:32})],["instructions",h(fn(),{description:An,size:T()})],["addressTableLookups",ir()]]}function or(){return A(Je(),{description:hn,size:m()})}function ir(){return h(Qe(),{description:hn,size:T()})}var En="message";function X(){return {description:En,encode:e=>e.version==="legacy"?nr().encode(e):rr().encode(e),fixedSize:null,maxSize:null}}function Sn(){return D(E(tr(),{description:En}),({addressTableLookups:e,...n})=>n.version==="legacy"||!e?.length?n:{...n,addressTableLookups:e})}var xn="signatures",In="transaction";function sr(){return b([["signatures",A(K({size:64}),{description:xn,size:m()})],["compiledMessage",X()]],{description:In})}function cr(){return D(j({size:64}),e=>e)}function ar(){return E([["signatures",h(cr(),{description:xn,size:T()})],["compiledMessage",Sn()]],{description:In})}function le(){return B(sr(),Ke)}function dr(e){return D(ar(),n=>Ye(n,e))}function si(e){return z(le(),dr(e))}async function Cn(e,n){await Le();let r=await crypto.subtle.sign("Ed25519",e,n);return new Uint8Array(r)}var L,fe;function ur(e){L||(L=I());try{if(e.length<64||e.length>88)throw new Error("Expected input string to decode to a byte array of length 64.");let r=L.encode(e).byteLength;if(r!==64)throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${r}`)}catch(n){throw new Error(`\`${e}\` is not a transaction signature`,{cause:n})}}function Si(e){return L||(L=I()),!(e.length<64||e.length>88||L.encode(e).byteLength!==64)}function xi(e){fe||(fe=_());let n=e.signatures[e.feePayer];if(!n)throw new Error("Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.");return fe.decode(n)[0]}async function Ii(e,n){let r=G(n),t="signatures"in n?{...n.signatures}:{},o=X().encode(r),i=await Promise.all(e.map(c=>Promise.all([Me(c.publicKey),Cn(c.privateKey,o)])));for(let[c,u]of i)t[c]=u;let s={...n,signatures:t};return Object.freeze(s),s}function Ci(e){return ur(e),e}function zi(e){let n=e.instructions.flatMap(t=>t.accounts?.filter(o=>y(o.role))??[]).map(t=>t.address);new Set([e.feePayer,...n]).forEach(t=>{if(!e.signatures[t])throw new Error(`Transaction is missing signature for address \`${t}\``)});}function vi(e){let n=le().encode(e);return btoa(String.fromCharCode(...n))}
|
|
5
|
+
function N(e,n,r=0){if(n.length-r<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function w(e,n,r,t=0){let o=r.length-t;if(o<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${o}.`)}var k=e=>{let n=e.filter(i=>i.length);if(n.length===0)return e.length?e[0]:new Uint8Array;if(n.length===1)return n[0];let r=n.reduce((i,s)=>i+s.length,0),t=new Uint8Array(r),o=0;return n.forEach(i=>{t.set(i,o),o+=i.length;}),t},Bn=(e,n)=>{if(e.length>=n)return e;let r=new Uint8Array(n).fill(0);return r.set(e),r},Z=(e,n)=>Bn(e.length<=n?e:e.slice(0,n),n);function z(e,n,r){if(e.fixedSize!==n.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${n.fixedSize}].`);if(e.maxSize!==n.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${n.maxSize}].`);if(r===void 0&&e.description!==n.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${n.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:n.decode,description:r??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function ge(e,n,r){return {description:r??`fixed(${n}, ${e.description})`,fixedSize:n,maxSize:n}}function U(e,n,r){return {...ge(e,n,r),encode:t=>Z(e.encode(t),n)}}function O(e,n,r){return {...ge(e,n,r),decode:(t,o=0)=>{w("fixCodec",n,t,o),(o>0||t.length>n)&&(t=t.slice(o,o+n)),e.fixedSize!==null&&(t=Z(t,e.fixedSize));let[i]=e.decode(t,0);return [i,o+n]}}}function B(e,n){return {description:e.description,encode:r=>e.encode(n(r)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function D(e,n){return {decode:(r,t=0)=>{let[o,i]=e.decode(r,t);return [n(o,r,t),i]},description:e.description,fixedSize:e.fixedSize,maxSize:e.maxSize}}function pe(e,n,r,t){if(t<n||t>r)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${r}], got ${t}.`)}function me(e){let n,r=e.name;return e.size>1&&(n=!("endian"in e.options)||e.options.endian===0,r+=n?"(le)":"(be)"),{description:e.options.description??r,fixedSize:e.size,littleEndian:n,maxSize:e.size}}function Te(e){let n=me(e);return {description:n.description,encode(r){e.range&&pe(e.name,e.range[0],e.range[1],r);let t=new ArrayBuffer(e.size);return e.set(new DataView(t),r,n.littleEndian),new Uint8Array(t)},fixedSize:n.fixedSize,maxSize:n.maxSize}}function Ae(e){let n=me(e);return {decode(r,t=0){N(n.description,r,t),w(n.description,e.size,r,t);let o=new DataView(wn(r,t,e.size));return [e.get(o,n.littleEndian),t+e.size]},description:n.description,fixedSize:n.fixedSize,maxSize:n.maxSize}}function wn(e,n,r){let t=e.byteOffset+(n??0),o=r??e.byteLength;return e.buffer.slice(t,t+o)}var m=(e={})=>({description:e.description??"shortU16",encode:n=>{pe("shortU16",0,65535,n);let r=[0];for(let t=0;;t+=1){let o=n>>t*7;if(o===0)break;let i=127&o;r[t]=i,t>0&&(r[t-1]|=128);}return new Uint8Array(r)},fixedSize:null,maxSize:3}),T=(e={})=>({decode:(n,r=0)=>{let t=0,o=0;for(;++o;){let i=o-1,s=n[r+i],c=127&s;if(t|=c<<i*7,!(s&128))break}return [t,r+o]},description:e.description??"shortU16",fixedSize:null,maxSize:3});var $=(e={})=>Te({name:"u32",options:e,range:[0,+"0xffffffff"],set:(n,r,t)=>n.setUint32(0,r,t),size:4}),W=(e={})=>Ae({get:(n,r)=>n.getUint32(0,r),name:"u32",options:e,size:4});var S=(e={})=>Te({name:"u8",options:e,range:[0,+"0xff"],set:(n,r)=>n.setUint8(0,r),size:1}),x=(e={})=>Ae({get:n=>n.getUint8(0),name:"u8",options:e,size:1});function Dn(e,n,r=n){if(!n.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${r}].`)}var vn=e=>{let n=e.length,r=BigInt(n);return {description:`base${n}`,encode(t){if(Dn(e,t),t==="")return new Uint8Array;let o=[...t],i=o.findIndex(p=>p!==e[0]);i=i===-1?o.length:i;let s=Array(i).fill(0);if(i===o.length)return Uint8Array.from(s);let c=o.slice(i),u=0n,a=1n;for(let p=c.length-1;p>=0;p-=1)u+=a*BigInt(e.indexOf(c[p])),a*=r;let l=[];for(;u>0n;)l.unshift(Number(u%256n)),u/=256n;return Uint8Array.from(s.concat(l))},fixedSize:null,maxSize:null}},Nn=e=>{let n=e.length,r=BigInt(n);return {decode(t,o=0){let i=o===0?t:t.slice(o);if(i.length===0)return ["",0];let s=i.findIndex(l=>l!==0);s=s===-1?i.length:s;let c=e[0].repeat(s);if(s===i.length)return [c,t.length];let u=i.slice(s).reduce((l,p)=>l*256n+BigInt(p),0n),a=[];for(;u>0n;)a.unshift(e[Number(u%r)]),u/=r;return [c+a.join(""),t.length]},description:`base${n}`,fixedSize:null,maxSize:null}};var ye="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",I=()=>vn(ye),_=()=>Nn(ye);var kn=e=>e.replace(/\u0000/g,"");var _n=globalThis.TextDecoder,Ln=globalThis.TextEncoder,Rn=()=>{let e;return {description:"utf8",encode:n=>new Uint8Array((e||(e=new Ln)).encode(n)),fixedSize:null,maxSize:null}},Mn=()=>{let e;return {decode(n,r=0){let t=(e||(e=new _n)).decode(n.slice(r));return [kn(t),n.length]},description:"utf8",fixedSize:null,maxSize:null}};var P=(e={})=>{let n=e.size??$(),r=e.encoding??Rn(),t=e.description??`string(${r.description}; ${he(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?U(r,n,t):{description:t,encode:o=>{let i=r.encode(o),s=n.encode(i.length);return k([s,i])},fixedSize:null,maxSize:null}},V=(e={})=>{let n=e.size??W(),r=e.encoding??Mn(),t=e.description??`string(${r.description}; ${he(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?O(r,n,t):{decode:(o,i=0)=>{N("string",o,i);let[s,c]=n.decode(o,i),u=Number(s);i=c;let a=o.slice(i,i+u);w("string",u,a);let[l,p]=r.decode(a);return i+=p,[l,i]},description:t,fixedSize:null,maxSize:null}};function he(e){return typeof e=="object"?e.description:`${e}`}function C(e){if("signatures"in e){let{signatures:n,...r}=e;return r}else return e}var J;function Cr(e){J||(J=I());try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let r=J.encode(e).byteLength;if(r!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${r}`)}catch(n){throw new Error(`\`${e}\` is not a blockhash`,{cause:n})}}function be(e,n){if("lifetimeConstraint"in n&&n.lifetimeConstraint.blockhash===e.blockhash&&n.lifetimeConstraint.lastValidBlockHeight===e.lastValidBlockHeight)return n;let r={...C(n),lifetimeConstraint:e};return Object.freeze(r),r}function Ee({version:e}){let n={instructions:[],version:e};return Object.freeze(n),n}var g=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(g||{});var Un=1;function A(e){return e>=2}function v(e){return (e&Un)!==0}function Q(e,n){return e|n}var xe="SysvarRecentB1ockHashes11111111111111111111",Ie="11111111111111111111111111111111";function Pr(e){if(!Ce(e))throw new Error("Transaction is not a durable nonce transaction")}function Se(e,n){return {accounts:[{address:e,role:g.WRITABLE},{address:xe,role:g.READONLY},{address:n,role:g.READONLY_SIGNER}],data:new Uint8Array([4,0,0,0]),programAddress:Ie}}function F(e){return e.programAddress===Ie&&e.data!=null&&On(e.data)&&e.accounts?.length===3&&e.accounts[0].address!=null&&e.accounts[0].role===g.WRITABLE&&e.accounts[1].address===xe&&e.accounts[1].role===g.READONLY&&e.accounts[2].address!=null&&A(e.accounts[2].role)}function On(e){return e.byteLength===4&&e[0]===4&&e[1]===0&&e[2]===0&&e[3]===0}function Ce(e){return "lifetimeConstraint"in e&&typeof e.lifetimeConstraint.nonce=="string"&&e.instructions[0]!=null&&F(e.instructions[0])}function $n(e,n,r){return e.accounts[0].address===n&&e.accounts[2].address===r}function ze({nonce:e,nonceAccountAddress:n,nonceAuthorityAddress:r},t){let o,i=t.instructions[0];if(i&&F(i))if($n(i,n,r)){if(Ce(t)&&t.lifetimeConstraint.nonce===e)return t;o=[i,...t.instructions.slice(1)];}else o=[Se(n,r),...t.instructions.slice(1)];else o=[Se(n,r),...t.instructions];let s={...C(t),instructions:o,lifetimeConstraint:{nonce:e}};return Object.freeze(s),s}function Be(e,n){if("feePayer"in n&&e===n.feePayer)return n;let r={...C(n),feePayer:e};return Object.freeze(r),r}function we(e,n){let r={...C(n),instructions:[...n.instructions,e]};return Object.freeze(r),r}function qr(e,n){let r={...C(n),instructions:[e,...n.instructions]};return Object.freeze(r),r}function H(e){return e.reduce((n,r)=>n===null||r===null?null:n+r,0)}function Wn(e,n,r,t){if(typeof e=="number")return [e,t];if(typeof e=="object")return e.decode(r,t);if(e==="remainder"){let o=H(n);if(o===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');let i=r.slice(t).length;if(i%o!==0)throw new Error(`The remainder of the byte array (${i} bytes) cannot be split into chunks of ${o} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${i} modulo ${o} should be equal to zero.`);return [i/o,t]}throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(e)}`)}function Pn(e){return typeof e=="object"?e.description:`${e}`}function De(e,n){if(typeof e!="number")return null;if(e===0)return 0;let r=H(n);return r===null?null:r*e}function Vn(e,n){return typeof e=="object"?e.encode(n):new Uint8Array}function Fn(e,n,r){if(n!==r)throw new Error(`Expected [${e}] to have ${n} items, got ${r}.`)}function ve(e,n,r){if(n==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:r??`array(${e.description}; ${Pn(n)})`,fixedSize:De(n,[e.fixedSize]),maxSize:De(n,[e.maxSize])}}function y(e,n={}){let r=n.size??$();return {...ve(e,r,n.description),encode:t=>(typeof r=="number"&&Fn("array",r,t.length),k([Vn(r,t.length),...t.map(o=>e.encode(o))]))}}function h(e,n={}){let r=n.size??W();return {...ve(e,r,n.description),decode:(t,o=0)=>{if(typeof r=="object"&&t.slice(o).length===0)return [[],o];let[i,s]=Wn(r,[e.fixedSize],t,o);o=s;let c=[];for(let u=0;u<i;u+=1){let[a,l]=e.decode(t,o);c.push(a),o=l;}return [c,o]}}}function K(e={}){let n=e.size??"variable",r=typeof n=="object"?n.description:`${n}`,t=e.description??`bytes(${r})`,o={description:t,encode:i=>i,fixedSize:null,maxSize:null};return n==="variable"?o:typeof n=="number"?U(o,n,t):{...o,encode:i=>{let s=o.encode(i),c=n.encode(s.length);return k([c,s])}}}function j(e={}){let n=e.size??"variable",r=typeof n=="object"?n.description:`${n}`,t=e.description??`bytes(${r})`,o={decode:(i,s=0)=>{let c=i.slice(s);return [c,s+c.length]},description:t,fixedSize:null,maxSize:null};return n==="variable"?o:typeof n=="number"?O(o,n,t):{...o,decode:(i,s=0)=>{N("bytes",i,s);let[c,u]=n.decode(i,s),a=Number(c);s=u;let l=i.slice(s,s+a);w("bytes",a,l);let[p,zn]=o.decode(l);return s+=zn,[p,s]}}}function Ne(e,n){let r=e.map(([t,o])=>`${String(t)}: ${o.description}`).join(", ");return {description:n??`struct(${r})`,fixedSize:H(e.map(([,t])=>t.fixedSize)),maxSize:H(e.map(([,t])=>t.maxSize))}}function b(e,n={}){return {...Ne(e,n.description),encode:r=>{let t=e.map(([o,i])=>i.encode(r[o]));return k(t)}}}function E(e,n={}){return {...Ne(e,n.description),decode:(r,t=0)=>{let o={};return e.forEach(([i,s])=>{let[c,u]=s.decode(r,t);t=u,o[i]=c;}),[o,t]}}}function ke(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}async function _e(){if(ke(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function Le(){if(ke(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}var ee,ne;function Re(){return ee||(ee=I()),ee}function Hn(){return ne||(ne=_()),ne}function Y(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=Re().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(n){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:n})}}function Kn(e){return Y(e),e}function q(e){return B(P({description:e?.description??"Base58EncodedAddress",encoding:Re(),size:32}),n=>Kn(n))}function R(e){return V({description:e?.description??"Base58EncodedAddress",encoding:Hn(),size:32})}function M(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}async function Me(e){if(await _e(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let n=await crypto.subtle.exportKey("raw",e),[r]=R().decode(new Uint8Array(n));return r}function Ue(e,n,r){e[n]=r(e[n]??{role:g.READONLY});}var f=Symbol("AddressMapTypeProperty");function Oe(e,n){let r={[e]:{[f]:0,role:g.WRITABLE_SIGNER}},t=new Set;for(let o of n){Ue(r,o.programAddress,s=>{if(t.add(o.programAddress),f in s){if(v(s.role))switch(s[f]){case 0:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`);default:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`)}if(s[f]===2)return s}return {[f]:2,role:g.READONLY}});let i;if(o.accounts)for(let s of o.accounts)Ue(r,s.address,c=>{let{address:u,...a}=s;if(f in c)switch(c[f]){case 0:return c;case 1:{let l=Q(c.role,a.role);if("lookupTableAddress"in a){if(c.lookupTableAddress!==a.lookupTableAddress&&(i||(i=M()))(a.lookupTableAddress,c.lookupTableAddress)<0)return {[f]:1,...a,role:l}}else if(A(a.role))return {[f]:2,role:l};return c.role!==l?{...c,role:l}:c}case 2:{let l=Q(c.role,a.role);if(t.has(s.address)){if(v(a.role))throw new Error(`This transaction includes an address (\`${s.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`);return c.role!==l?{...c,role:l}:c}else return "lookupTableAddress"in a&&!A(c.role)?{...a,[f]:1,role:l}:c.role!==l?{...c,role:l}:c}}return "lookupTableAddress"in a?{...a,[f]:1}:{...a,[f]:2}});}return r}function $e(e){let n;return Object.entries(e).sort(([t,o],[i,s])=>{if(o[f]!==s[f]){if(o[f]===0)return -1;if(s[f]===0)return 1;if(o[f]===2)return -1;if(s[f]===2)return 1}let c=A(o.role);if(c!==A(s.role))return c?-1:1;let u=v(o.role);return u!==v(s.role)?u?-1:1:(n||(n=M()),o[f]===1&&s[f]===1&&o.lookupTableAddress!==s.lookupTableAddress?n(o.lookupTableAddress,s.lookupTableAddress):n(t,i))}).map(([t,o])=>({address:t,...o}))}function We(e){var r;let n={};for(let t of e){if(!("lookupTableAddress"in t))continue;let o=n[r=t.lookupTableAddress]||(n[r]={readableIndices:[],writableIndices:[]});t.role===g.WRITABLE?o.writableIndices.push(t.addressIndex):o.readableIndices.push(t.addressIndex);}return Object.keys(n).sort(M()).map(t=>({lookupTableAddress:t,...n[t]}))}function Pe(e){let n=0,r=0,t=0;for(let o of e){if("lookupTableAddress"in o)break;let i=v(o.role);A(o.role)?(t++,i||r++):i||n++;}return {numReadonlyNonSignerAccounts:n,numReadonlySignerAccounts:r,numSignerAccounts:t}}function jn(e){let n={};for(let[r,t]of e.entries())n[t.address]=r;return n}function Ve(e,n){let r=jn(n);return e.map(({accounts:t,data:o,programAddress:i})=>({programAddressIndex:r[i],...t?{accountIndices:t.map(({address:s})=>r[s])}:null,...o?{data:o}:null}))}function Fe(e){return "nonce"in e?e.nonce:e.blockhash}function He(e){let n=e.findIndex(t=>"lookupTableAddress"in t);return (n===-1?e:e.slice(0,n)).map(({address:t})=>t)}function G(e){let n=Oe(e.feePayer,e.instructions),r=$e(n);return {...e.version!=="legacy"?{addressTableLookups:We(r)}:null,header:Pe(r),instructions:Ve(e.instructions,r),lifetimeToken:Fe(e.lifetimeConstraint),staticAccounts:He(r),version:e.version}}function Ke(e){let n=G(e),r;if("signatures"in e){r=[];for(let t=0;t<n.header.numSignerAccounts;t++)r[t]=e.signatures[n.staticAccounts[t]]??new Uint8Array(Array(64).fill(0));}else r=Array(n.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));return {compiledMessage:n,signatures:r}}function je(e,...n){return n.reduce((r,t)=>t(r),e)}function Yn(e){let{header:n}=e,r=n.numSignerAccounts-n.numReadonlySignerAccounts,t=e.staticAccounts.length-n.numSignerAccounts-n.numReadonlyNonSignerAccounts,o=[],i=0;for(let s=0;s<r;s++)o.push({address:e.staticAccounts[i],role:g.WRITABLE_SIGNER}),i++;for(let s=0;s<n.numReadonlySignerAccounts;s++)o.push({address:e.staticAccounts[i],role:g.READONLY_SIGNER}),i++;for(let s=0;s<t;s++)o.push({address:e.staticAccounts[i],role:g.WRITABLE}),i++;for(let s=0;s<n.numReadonlyNonSignerAccounts;s++)o.push({address:e.staticAccounts[i],role:g.READONLY}),i++;return o}function qn(e,n){let r=n[e.programAddressIndex]?.address;if(!r)throw new Error(`Could not find program address at index ${e.programAddressIndex}`);let t=e.accountIndices?.map(i=>n[i]),{data:o}=e;return {programAddress:r,...t&&t.length?{accounts:t}:{},...o&&o.length?{data:o}:{}}}function Gn(e,n,r){if(!n||!F(n))return {blockhash:e,lastValidBlockHeight:r??2n**64n-1n};{let t=n.accounts[0].address;Y(t);let o=n.accounts[2].address;return Y(o),{nonce:e,nonceAccountAddress:t,nonceAuthorityAddress:o}}}function Xn(e){let{compiledMessage:{staticAccounts:n},signatures:r}=e;return r.reduce((t,o,i)=>{if(o.every(u=>u===0))return t;let c=n[i];return {...t,[c]:o}},{})}function Ye(e,n){let{compiledMessage:r}=e;if("addressTableLookups"in r&&r.addressTableLookups.length>0)throw new Error("Cannot convert transaction with addressTableLookups");let t=r.staticAccounts[0];if(!t)throw new Error("No fee payer set in CompiledTransaction");let o=Yn(r),i=r.instructions.map(a=>qn(a,o)),s=i[0],c=Gn(r.lifetimeToken,s,n),u=Xn(e);return je(Ee({version:r.version}),a=>Be(t,a),a=>i.reduce((l,p)=>we(p,l),a),a=>"blockhash"in c?be(c,a):ze(c,a),a=>e.signatures.length?{...a,signatures:u}:a)}var qe="lookupTableAddress",Ge="writableIndices",Xe="readableIndices",Ze="addressTableLookup",re;function Je(){return re||(re=b([["lookupTableAddress",q({description:qe})],["writableIndices",y(S(),{description:Ge,size:m()})],["readableIndices",y(S(),{description:Xe,size:m()})]],{description:Ze})),re}var te;function Qe(){return te||(te=E([["lookupTableAddress",R({description:qe})],["writableIndices",h(x(),{description:Ge,size:T()})],["readableIndices",h(x(),{description:Xe,size:T()})]],{description:Ze})),te}var oe;function Zn(){return oe||(oe=S()),oe}function ie(e){let n=Zn();return {...n,description:e??n.description}}var se;function Jn(){return se||(se=x()),se}function ce(e){let n=Jn();return {...n,description:e??n.description}}var en=void 0,nn=void 0,rn=void 0,tn=void 0;function on(){return b([["numSignerAccounts",ie(en)],["numReadonlySignerAccounts",ie(nn)],["numReadonlyNonSignerAccounts",ie(rn)]],{description:tn})}function sn(){return E([["numSignerAccounts",ce(en)],["numReadonlySignerAccounts",ce(nn)],["numReadonlyNonSignerAccounts",ce(rn)]],{description:tn})}var cn="programAddressIndex",an=void 0,dn="accountIndices",un="data",ae;function ln(){return ae||(ae=B(b([["programAddressIndex",S({description:cn})],["accountIndices",y(S({description:an}),{description:dn,size:m()})],["data",K({description:un,size:m()})]]),e=>e.accountIndices!==void 0&&e.data!==void 0?e:{...e,accountIndices:e.accountIndices??[],data:e.data??new Uint8Array(0)})),ae}var de;function fn(){return de||(de=D(E([["programAddressIndex",x({description:cn})],["accountIndices",h(x({description:an}),{description:dn,size:T()})],["data",j({description:un,size:T()})]]),e=>{if(e.accountIndices.length&&e.data.byteLength)return e;let{accountIndices:n,data:r,...t}=e;return {...t,...n.length?{accountIndices:n}:null,...r.byteLength?{data:r}:null}})),de}var ue=128,gn={description:"",fixedSize:null,maxSize:1};function Qn(e,n=0){let r=e[n];return r&ue?[r^ue,n+1]:["legacy",n]}function er(e){if(e==="legacy")return new Uint8Array;if(e<0||e>127)throw new Error(`Transaction version must be in the range [0, 127]. \`${e}\` given.`);return new Uint8Array([e|ue])}function pn(){return {...gn,decode:Qn}}function mn(){return {...gn,encode:er}}var Tn="staticAccounts",An="lifetimeToken",yn="instructions",hn="addressTableLookups";function nr(){return b(bn())}function rr(){return B(b([...bn(),["addressTableLookups",or()]]),e=>e.version==="legacy"?e:{...e,addressTableLookups:e.addressTableLookups??[]})}function bn(){return [["version",mn()],["header",on()],["staticAccounts",y(q(),{description:Tn,size:m()})],["lifetimeToken",P({description:An,encoding:I(),size:32})],["instructions",y(ln(),{description:yn,size:m()})]]}function tr(){return [["version",pn()],["header",sn()],["staticAccounts",h(R(),{description:Tn,size:T()})],["lifetimeToken",V({description:An,encoding:_(),size:32})],["instructions",h(fn(),{description:yn,size:T()})],["addressTableLookups",ir()]]}function or(){return y(Je(),{description:hn,size:m()})}function ir(){return h(Qe(),{description:hn,size:T()})}var En="message";function X(){return {description:En,encode:e=>e.version==="legacy"?nr().encode(e):rr().encode(e),fixedSize:null,maxSize:null}}function Sn(){return D(E(tr(),{description:En}),({addressTableLookups:e,...n})=>n.version==="legacy"||!e?.length?n:{...n,addressTableLookups:e})}var xn="signatures",In="transaction";function sr(){return b([["signatures",y(K({size:64}),{description:xn,size:m()})],["compiledMessage",X()]],{description:In})}function cr(){return D(j({size:64}),e=>e)}function ar(){return E([["signatures",h(cr(),{description:xn,size:T()})],["compiledMessage",Sn()]],{description:In})}function le(){return B(sr(),Ke)}function dr(e){return D(ar(),n=>Ye(n,e))}function ci(e){return z(le(),dr(e))}async function Cn(e,n){await Le();let r=await crypto.subtle.sign("Ed25519",e,n);return new Uint8Array(r)}var L,fe;function ur(e){L||(L=I());try{if(e.length<64||e.length>88)throw new Error("Expected input string to decode to a byte array of length 64.");let r=L.encode(e).byteLength;if(r!==64)throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${r}`)}catch(n){throw new Error(`\`${e}\` is not a transaction signature`,{cause:n})}}function xi(e){return L||(L=I()),!(e.length<64||e.length>88||L.encode(e).byteLength!==64)}function Ii(e){fe||(fe=_());let n=e.signatures[e.feePayer];if(!n)throw new Error("Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.");return fe.decode(n)[0]}async function Ci(e,n){let r=G(n),t="signatures"in n?{...n.signatures}:{},o=X().encode(r),i=await Promise.all(e.map(c=>Promise.all([Me(c.publicKey),Cn(c.privateKey,o)])));for(let[c,u]of i)t[c]=u;let s={...n,signatures:t};return Object.freeze(s),s}function zi(e){return ur(e),e}function Bi(e){let n=e.instructions.flatMap(t=>t.accounts?.filter(o=>A(o.role))??[]).map(t=>t.address);new Set([e.feePayer,...n]).forEach(t=>{if(!e.signatures[t])throw new Error(`Transaction is missing signature for address \`${t}\``)});}function Ni(e){let n=le().encode(e);return btoa(String.fromCharCode(...n))}
|
|
6
6
|
|
|
7
7
|
exports.appendTransactionInstruction = we;
|
|
8
8
|
exports.assertIsBlockhash = Cr;
|
|
9
|
-
exports.assertIsDurableNonceTransaction =
|
|
9
|
+
exports.assertIsDurableNonceTransaction = Pr;
|
|
10
10
|
exports.assertIsTransactionSignature = ur;
|
|
11
|
-
exports.assertTransactionIsFullySigned =
|
|
11
|
+
exports.assertTransactionIsFullySigned = Bi;
|
|
12
12
|
exports.createTransaction = Ee;
|
|
13
|
-
exports.getBase64EncodedWireTransaction =
|
|
14
|
-
exports.getSignatureFromTransaction =
|
|
15
|
-
exports.getTransactionCodec =
|
|
13
|
+
exports.getBase64EncodedWireTransaction = Ni;
|
|
14
|
+
exports.getSignatureFromTransaction = Ii;
|
|
15
|
+
exports.getTransactionCodec = ci;
|
|
16
16
|
exports.getTransactionDecoder = dr;
|
|
17
17
|
exports.getTransactionEncoder = le;
|
|
18
18
|
exports.isAdvanceNonceAccountInstruction = F;
|
|
19
|
-
exports.isTransactionSignature =
|
|
19
|
+
exports.isTransactionSignature = xi;
|
|
20
20
|
exports.prependTransactionInstruction = qr;
|
|
21
21
|
exports.setTransactionFeePayer = Be;
|
|
22
22
|
exports.setTransactionLifetimeUsingBlockhash = be;
|
|
23
23
|
exports.setTransactionLifetimeUsingDurableNonce = ze;
|
|
24
|
-
exports.signTransaction =
|
|
25
|
-
exports.transactionSignature =
|
|
24
|
+
exports.signTransaction = Ci;
|
|
25
|
+
exports.transactionSignature = zi;
|
|
26
26
|
|
|
27
27
|
return exports;
|
|
28
28
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ITransactionWithBlockhashLifetime } from './blockhash';
|
|
2
|
+
import { IDurableNonceTransaction } from './durable-nonce';
|
|
3
|
+
import { ITransactionWithFeePayer } from './fee-payer';
|
|
4
|
+
import { BaseTransaction } from './types';
|
|
5
|
+
export type CompilableTransaction = BaseTransaction & ITransactionWithFeePayer & (ITransactionWithBlockhashLifetime | IDurableNonceTransaction);
|
|
6
|
+
//# sourceMappingURL=compilable-transaction.d.ts.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Ed25519Signature } from '@solana/keys';
|
|
2
|
-
import {
|
|
2
|
+
import { CompilableTransaction } from './compilable-transaction';
|
|
3
|
+
import { CompiledMessage } from './message';
|
|
3
4
|
import { ITransactionWithSignatures } from './signatures';
|
|
4
|
-
type CompiledTransaction = Readonly<{
|
|
5
|
+
export type CompiledTransaction = Readonly<{
|
|
5
6
|
compiledMessage: CompiledMessage;
|
|
6
7
|
signatures: Ed25519Signature[];
|
|
7
8
|
}>;
|
|
8
|
-
type CompilableTransaction = Parameters<typeof compileMessage>[0];
|
|
9
9
|
export declare function getCompiledTransaction(transaction: CompilableTransaction | (CompilableTransaction & ITransactionWithSignatures)): CompiledTransaction;
|
|
10
|
-
export {};
|
|
11
10
|
//# sourceMappingURL=compile-transaction.d.ts.map
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompilableTransaction } from './compilable-transaction';
|
|
2
|
+
import { CompiledTransaction } from './compile-transaction';
|
|
2
3
|
import { ITransactionWithSignatures } from './signatures';
|
|
3
|
-
type CompiledTransaction = ReturnType<typeof getCompiledTransaction>;
|
|
4
|
-
type CompilableTransaction = Parameters<typeof getCompiledTransaction>[0];
|
|
5
4
|
export declare function decompileTransaction(compiledTransaction: CompiledTransaction, lastValidBlockHeight?: bigint): CompilableTransaction | (CompilableTransaction & ITransactionWithSignatures);
|
|
6
|
-
export {};
|
|
7
5
|
//# sourceMappingURL=decompile-transaction.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/message.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompilableTransaction } from './compilable-transaction';
|
|
2
2
|
import { getCompiledAddressTableLookups } from './compile-address-table-lookups';
|
|
3
3
|
import { getCompiledMessageHeader } from './compile-header';
|
|
4
4
|
import { getCompiledInstructions } from './compile-instructions';
|
|
5
5
|
import { getCompiledLifetimeToken } from './compile-lifetime-token';
|
|
6
6
|
import { getCompiledStaticAccounts } from './compile-static-accounts';
|
|
7
|
-
import { IDurableNonceTransaction } from './durable-nonce';
|
|
8
|
-
import { ITransactionWithFeePayer } from './fee-payer';
|
|
9
|
-
import { BaseTransaction } from './types';
|
|
10
7
|
type BaseCompiledMessage = Readonly<{
|
|
11
8
|
header: ReturnType<typeof getCompiledMessageHeader>;
|
|
12
9
|
instructions: ReturnType<typeof getCompiledInstructions>;
|
|
13
10
|
lifetimeToken: ReturnType<typeof getCompiledLifetimeToken>;
|
|
14
11
|
staticAccounts: ReturnType<typeof getCompiledStaticAccounts>;
|
|
15
12
|
}>;
|
|
16
|
-
type CompilableTransaction = BaseTransaction & ITransactionWithFeePayer & (ITransactionWithBlockhashLifetime | IDurableNonceTransaction);
|
|
17
13
|
export type CompiledMessage = LegacyCompiledMessage | VersionedCompiledMessage;
|
|
18
14
|
type LegacyCompiledMessage = BaseCompiledMessage & Readonly<{
|
|
19
15
|
version: 'legacy';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
-
import {
|
|
2
|
+
import { CompilableTransaction } from '../compilable-transaction';
|
|
3
3
|
import { ITransactionWithSignatures } from '../signatures';
|
|
4
|
-
type CompilableTransaction = Parameters<typeof compileMessage>[0];
|
|
5
4
|
export declare function getTransactionEncoder(): Encoder<CompilableTransaction | (CompilableTransaction & ITransactionWithSignatures)>;
|
|
6
5
|
export declare function getTransactionDecoder(lastValidBlockHeight?: bigint): Decoder<CompilableTransaction | (CompilableTransaction & ITransactionWithSignatures)>;
|
|
7
6
|
export declare function getTransactionCodec(lastValidBlockHeight?: bigint): Codec<CompilableTransaction | (CompilableTransaction & ITransactionWithSignatures)>;
|
|
8
|
-
export {};
|
|
9
7
|
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Base58EncodedAddress } from '@solana/addresses';
|
|
2
2
|
import { Ed25519Signature } from '@solana/keys';
|
|
3
|
+
import { CompilableTransaction } from './compilable-transaction';
|
|
3
4
|
import { ITransactionWithFeePayer } from './fee-payer';
|
|
4
|
-
import { compileMessage } from './message';
|
|
5
5
|
export interface IFullySignedTransaction extends ITransactionWithSignatures {
|
|
6
6
|
readonly __brand: unique symbol;
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ export type TransactionSignature = string & {
|
|
|
14
14
|
export declare function assertIsTransactionSignature(putativeTransactionSignature: string): asserts putativeTransactionSignature is TransactionSignature;
|
|
15
15
|
export declare function isTransactionSignature(putativeTransactionSignature: string): putativeTransactionSignature is TransactionSignature;
|
|
16
16
|
export declare function getSignatureFromTransaction(transaction: ITransactionWithFeePayer & ITransactionWithSignatures): TransactionSignature;
|
|
17
|
-
export declare function signTransaction<TTransaction extends
|
|
17
|
+
export declare function signTransaction<TTransaction extends CompilableTransaction>(keyPairs: CryptoKeyPair[], transaction: TTransaction | (TTransaction & ITransactionWithSignatures)): Promise<TTransaction & ITransactionWithSignatures>;
|
|
18
18
|
export declare function transactionSignature(putativeTransactionSignature: string): TransactionSignature;
|
|
19
|
-
export declare function assertTransactionIsFullySigned<TTransaction extends
|
|
19
|
+
export declare function assertTransactionIsFullySigned<TTransaction extends CompilableTransaction>(transaction: TTransaction & ITransactionWithSignatures): asserts transaction is TTransaction & IFullySignedTransaction;
|
|
20
20
|
//# sourceMappingURL=signatures.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/transactions",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.ffeddf6",
|
|
4
4
|
"description": "Helpers for creating and serializing transactions",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"maintained node versions"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@solana/addresses": "2.0.0-experimental.
|
|
50
|
-
"@solana/codecs-core": "2.0.0-experimental.
|
|
51
|
-
"@solana/codecs-data-structures": "2.0.0-experimental.
|
|
52
|
-
"@solana/codecs-numbers": "2.0.0-experimental.
|
|
53
|
-
"@solana/codecs-strings": "2.0.0-experimental.
|
|
54
|
-
"@solana/functional": "2.0.0-experimental.
|
|
55
|
-
"@solana/keys": "2.0.0-experimental.
|
|
49
|
+
"@solana/addresses": "2.0.0-experimental.ffeddf6",
|
|
50
|
+
"@solana/codecs-core": "2.0.0-experimental.ffeddf6",
|
|
51
|
+
"@solana/codecs-data-structures": "2.0.0-experimental.ffeddf6",
|
|
52
|
+
"@solana/codecs-numbers": "2.0.0-experimental.ffeddf6",
|
|
53
|
+
"@solana/codecs-strings": "2.0.0-experimental.ffeddf6",
|
|
54
|
+
"@solana/functional": "2.0.0-experimental.ffeddf6",
|
|
55
|
+
"@solana/keys": "2.0.0-experimental.ffeddf6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@solana/eslint-config-solana": "^1.0.2",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"tsup": "7.2.0",
|
|
72
72
|
"typescript": "^5.2.2",
|
|
73
73
|
"version-from-git": "^1.1.1",
|
|
74
|
-
"@solana/instructions": "2.0.0-experimental.
|
|
74
|
+
"@solana/instructions": "2.0.0-experimental.ffeddf6",
|
|
75
75
|
"build-scripts": "0.0.0",
|
|
76
76
|
"test-config": "0.0.0",
|
|
77
77
|
"test-matchers": "0.0.0",
|