UNPKG

ndwallet-core

Version:

Core cryptographic library for NDWallet browser environments

1,539 lines (1,398 loc) 47.9 kB
let wasm; export function __wbg_set_wasm(val) { wasm = val; } function addToExternrefTable0(obj) { const idx = wasm.__externref_table_alloc(); wasm.__wbindgen_export_2.set(idx, obj); return idx; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { const idx = addToExternrefTable0(e); wasm.__wbindgen_exn_store(idx); } } const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); } let WASM_VECTOR_LEN = 0; const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; let cachedTextEncoder = new lTextEncoder('utf-8'); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8ArrayMemory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } function isLikeNone(x) { return x === undefined || x === null; } function debugString(val) { // primitive types const type = typeof val; if (type == 'number' || type == 'boolean' || val == null) { return `${val}`; } if (type == 'string') { return `"${val}"`; } if (type == 'symbol') { const description = val.description; if (description == null) { return 'Symbol'; } else { return `Symbol(${description})`; } } if (type == 'function') { const name = val.name; if (typeof name == 'string' && name.length > 0) { return `Function(${name})`; } else { return 'Function'; } } // objects if (Array.isArray(val)) { const length = val.length; let debug = '['; if (length > 0) { debug += debugString(val[0]); } for(let i = 1; i < length; i++) { debug += ', ' + debugString(val[i]); } debug += ']'; return debug; } // Test for built-in const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); let className; if (builtInMatches && builtInMatches.length > 1) { className = builtInMatches[1]; } else { // Failed to match the standard '[object ClassName]' return toString.call(val); } if (className == 'Object') { // we're a user defined class or Object // JSON.stringify avoids problems with cycles, and is generally much // easier than looping through ownProperties of `val`. try { return 'Object(' + JSON.stringify(val) + ')'; } catch (_) { return 'Object'; } } // errors if (val instanceof Error) { return `${val.name}: ${val.message}\n${val.stack}`; } // TODO we could test for more things here, like `Set`s and `Map`s. return className; } export function init_panic_hook() { wasm.init_panic_hook(); } function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8ArrayMemory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } function takeFromExternrefTable0(idx) { const value = wasm.__wbindgen_export_2.get(idx); wasm.__externref_table_dealloc(idx); return value; } /** * @returns {string} */ export function generate_seed_phrase() { let deferred2_0; let deferred2_1; try { const ret = wasm.generate_seed_phrase(); var ptr1 = ret[0]; var len1 = ret[1]; if (ret[3]) { ptr1 = 0; len1 = 0; throw takeFromExternrefTable0(ret[2]); } deferred2_0 = ptr1; deferred2_1 = len1; return getStringFromWasm0(ptr1, len1); } finally { wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); } } /** * @param {string} seed_phrase * @returns {boolean} */ export function validate_seed_phrase(seed_phrase) { const ptr0 = passStringToWasm0(seed_phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.validate_seed_phrase(ptr0, len0); return ret !== 0; } /** * @param {string} seed_phrase * @returns {Uint8Array} */ export function seed_phrase_to_seed(seed_phrase) { const ptr0 = passStringToWasm0(seed_phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.seed_phrase_to_seed(ptr0, len0); if (ret[3]) { throw takeFromExternrefTable0(ret[2]); } var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v2; } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getDataViewMemory0(); const result = []; for (let i = ptr; i < ptr + 4 * len; i += 4) { result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true))); } wasm.__externref_drop_slice(ptr, len); return result; } /** * @param {string} secret * @param {number} threshold * @param {number} shares * @returns {string[]} */ export function split_secret(secret, threshold, shares) { const ptr0 = passStringToWasm0(secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.split_secret(ptr0, len0, threshold, shares); if (ret[3]) { throw takeFromExternrefTable0(ret[2]); } var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 4, 4); return v2; } function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; for (let i = 0; i < array.length; i++) { const add = addToExternrefTable0(array[i]); getDataViewMemory0().setUint32(ptr + 4 * i, add, true); } WASM_VECTOR_LEN = array.length; return ptr; } /** * @param {string[]} shares * @returns {string} */ export function combine_shares(shares) { let deferred3_0; let deferred3_1; try { const ptr0 = passArrayJsValueToWasm0(shares, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.combine_shares(ptr0, len0); var ptr2 = ret[0]; var len2 = ret[1]; if (ret[3]) { ptr2 = 0; len2 = 0; throw takeFromExternrefTable0(ret[2]); } deferred3_0 = ptr2; deferred3_1 = len2; return getStringFromWasm0(ptr2, len2); } finally { wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); } } /** * Derive a cryptocurrency address from a seed * * This function takes a seed, network name, and account index and returns * a properly formatted address for the specified network. * @param {Uint8Array} seed * @param {string} network * @param {number} account_index * @returns {string} */ export function derive_address(seed, network, account_index) { let deferred4_0; let deferred4_1; try { const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(network, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.derive_address(ptr0, len0, ptr1, len1, account_index); var ptr3 = ret[0]; var len3 = ret[1]; if (ret[3]) { ptr3 = 0; len3 = 0; throw takeFromExternrefTable0(ret[2]); } deferred4_0 = ptr3; deferred4_1 = len3; return getStringFromWasm0(ptr3, len3); } finally { wasm.__wbindgen_free(deferred4_0, deferred4_1, 1); } } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } /** * Initialize Javascript logging and panic handler */ export function init() { wasm.init(); } const EncryptedDataFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_encrypteddata_free(ptr >>> 0, 1)); export class EncryptedData { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; EncryptedDataFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_encrypteddata_free(ptr, 0); } /** * @param {Uint8Array} iv * @param {Uint8Array} data */ constructor(iv, data) { const ptr0 = passArray8ToWasm0(iv, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.encrypteddata_new(ptr0, len0, ptr1, len1); this.__wbg_ptr = ret >>> 0; EncryptedDataFinalization.register(this, this.__wbg_ptr, this); return this; } /** * @returns {Uint8Array} */ get iv() { const ret = wasm.encrypteddata_iv(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * @returns {Uint8Array} */ get data() { const ret = wasm.encrypteddata_data(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } } const HashFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_hash_free(ptr >>> 0, 1)); export class Hash { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Hash.prototype); obj.__wbg_ptr = ptr; HashFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; HashFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_hash_free(ptr, 0); } /** * Create a new Hash object * * * `value` - optional hash as a base58 encoded string, `Uint8Array`, `[number]` * @param {any} value */ constructor(value) { const ret = wasm.hash_constructor(value); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; HashFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Return the base58 string representation of the hash * @returns {string} */ toString() { let deferred1_0; let deferred1_1; try { const ret = wasm.hash_toString(this.__wbg_ptr); deferred1_0 = ret[0]; deferred1_1 = ret[1]; return getStringFromWasm0(ret[0], ret[1]); } finally { wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); } } /** * Checks if two `Hash`s are equal * @param {Hash} other * @returns {boolean} */ equals(other) { _assertClass(other, Hash); const ret = wasm.hash_equals(this.__wbg_ptr, other.__wbg_ptr); return ret !== 0; } /** * Return the `Uint8Array` representation of the hash * @returns {Uint8Array} */ toBytes() { const ret = wasm.hash_toBytes(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } } const InstructionFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_instruction_free(ptr >>> 0, 1)); /** * A directive for a single invocation of a Solana program. * * An instruction specifies which program it is calling, which accounts it may * read or modify, and additional data that serves as input to the program. One * or more instructions are included in transactions submitted by Solana * clients. Instructions are also used to describe [cross-program * invocations][cpi]. * * [cpi]: https://docs.solana.com/developing/programming-model/calling-between-programs * * During execution, a program will receive a list of account data as one of * its arguments, in the same order as specified during `Instruction` * construction. * * While Solana is agnostic to the format of the instruction data, it has * built-in support for serialization via [`borsh`] and [`bincode`]. * * [`borsh`]: https://docs.rs/borsh/latest/borsh/ * [`bincode`]: https://docs.rs/bincode/latest/bincode/ * * # Specifying account metadata * * When constructing an [`Instruction`], a list of all accounts that may be * read or written during the execution of that instruction must be supplied as * [`AccountMeta`] values. * * Any account whose data may be mutated by the program during execution must * be specified as writable. During execution, writing to an account that was * not specified as writable will cause the transaction to fail. Writing to an * account that is not owned by the program will cause the transaction to fail. * * Any account whose lamport balance may be mutated by the program during * execution must be specified as writable. During execution, mutating the * lamports of an account that was not specified as writable will cause the * transaction to fail. While _subtracting_ lamports from an account not owned * by the program will cause the transaction to fail, _adding_ lamports to any * account is allowed, as long is it is mutable. * * Accounts that are not read or written by the program may still be specified * in an `Instruction`'s account list. These will affect scheduling of program * execution by the runtime, but will otherwise be ignored. * * When building a transaction, the Solana runtime coalesces all accounts used * by all instructions in that transaction, along with accounts and permissions * required by the runtime, into a single account list. Some accounts and * account permissions required by the runtime to process a transaction are * _not_ required to be included in an `Instruction`s account list. These * include: * * - The program ID &mdash; it is a separate field of `Instruction` * - The transaction's fee-paying account &mdash; it is added during [`Message`] * construction. A program may still require the fee payer as part of the * account list if it directly references it. * * [`Message`]: crate::message::Message * * Programs may require signatures from some accounts, in which case they * should be specified as signers during `Instruction` construction. The * program must still validate during execution that the account is a signer. */ export class Instruction { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Instruction.prototype); obj.__wbg_ptr = ptr; InstructionFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; InstructionFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_instruction_free(ptr, 0); } } const InstructionsFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_instructions_free(ptr >>> 0, 1)); export class Instructions { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; InstructionsFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_instructions_free(ptr, 0); } constructor() { const ret = wasm.instructions_constructor(); this.__wbg_ptr = ret >>> 0; InstructionsFinalization.register(this, this.__wbg_ptr, this); return this; } /** * @param {Instruction} instruction */ push(instruction) { _assertClass(instruction, Instruction); var ptr0 = instruction.__destroy_into_raw(); wasm.instructions_push(this.__wbg_ptr, ptr0); } } const KeypairFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_keypair_free(ptr >>> 0, 1)); /** * A vanilla Ed25519 key pair */ export class Keypair { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Keypair.prototype); obj.__wbg_ptr = ptr; KeypairFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; KeypairFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_keypair_free(ptr, 0); } /** * Create a new `Keypair ` */ constructor() { const ret = wasm.keypair_constructor(); this.__wbg_ptr = ret >>> 0; KeypairFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Convert a `Keypair` to a `Uint8Array` * @returns {Uint8Array} */ toBytes() { const ret = wasm.keypair_toBytes(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * Recover a `Keypair` from a `Uint8Array` * @param {Uint8Array} bytes * @returns {Keypair} */ static fromBytes(bytes) { const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.keypair_fromBytes(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return Keypair.__wrap(ret[0]); } /** * Return the `Pubkey` for this `Keypair` * @returns {Pubkey} */ pubkey() { const ret = wasm.keypair_pubkey(this.__wbg_ptr); return Pubkey.__wrap(ret); } } const MessageFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_message_free(ptr >>> 0, 1)); /** * A Solana transaction message (legacy). * * See the [`message`] module documentation for further description. * * [`message`]: crate::message * * Some constructors accept an optional `payer`, the account responsible for * paying the cost of executing a transaction. In most cases, callers should * specify the payer explicitly in these constructors. In some cases though, * the caller is not _required_ to specify the payer, but is still allowed to: * in the `Message` structure, the first account is always the fee-payer, so if * the caller has knowledge that the first account of the constructed * transaction's `Message` is both a signer and the expected fee-payer, then * redundantly specifying the fee-payer is not strictly required. */ export class Message { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Message.prototype); obj.__wbg_ptr = ptr; MessageFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; MessageFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_message_free(ptr, 0); } /** * The id of a recent ledger entry. * @returns {Hash} */ get recent_blockhash() { const ret = wasm.__wbg_get_message_recent_blockhash(this.__wbg_ptr); return Hash.__wrap(ret); } /** * The id of a recent ledger entry. * @param {Hash} arg0 */ set recent_blockhash(arg0) { _assertClass(arg0, Hash); var ptr0 = arg0.__destroy_into_raw(); wasm.__wbg_set_message_recent_blockhash(this.__wbg_ptr, ptr0); } } const PubkeyFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_pubkey_free(ptr >>> 0, 1)); export class Pubkey { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Pubkey.prototype); obj.__wbg_ptr = ptr; PubkeyFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; PubkeyFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_pubkey_free(ptr, 0); } /** * Create a new Pubkey object * * * `value` - optional public key as a base58 encoded string, `Uint8Array`, `[number]` * @param {any} value */ constructor(value) { const ret = wasm.pubkey_constructor(value); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; PubkeyFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Return the base58 string representation of the public key * @returns {string} */ toString() { let deferred1_0; let deferred1_1; try { const ret = wasm.pubkey_toString(this.__wbg_ptr); deferred1_0 = ret[0]; deferred1_1 = ret[1]; return getStringFromWasm0(ret[0], ret[1]); } finally { wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); } } /** * Check if a `Pubkey` is on the ed25519 curve. * @returns {boolean} */ isOnCurve() { const ret = wasm.pubkey_isOnCurve(this.__wbg_ptr); return ret !== 0; } /** * Checks if two `Pubkey`s are equal * @param {Pubkey} other * @returns {boolean} */ equals(other) { _assertClass(other, Pubkey); const ret = wasm.pubkey_equals(this.__wbg_ptr, other.__wbg_ptr); return ret !== 0; } /** * Return the `Uint8Array` representation of the public key * @returns {Uint8Array} */ toBytes() { const ret = wasm.pubkey_toBytes(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * Derive a Pubkey from another Pubkey, string seed, and a program id * @param {Pubkey} base * @param {string} seed * @param {Pubkey} owner * @returns {Pubkey} */ static createWithSeed(base, seed, owner) { _assertClass(base, Pubkey); const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(owner, Pubkey); const ret = wasm.pubkey_createWithSeed(base.__wbg_ptr, ptr0, len0, owner.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return Pubkey.__wrap(ret[0]); } /** * Derive a program address from seeds and a program id * @param {any[]} seeds * @param {Pubkey} program_id * @returns {Pubkey} */ static createProgramAddress(seeds, program_id) { const ptr0 = passArrayJsValueToWasm0(seeds, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; _assertClass(program_id, Pubkey); const ret = wasm.pubkey_createProgramAddress(ptr0, len0, program_id.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return Pubkey.__wrap(ret[0]); } /** * Find a valid program address * * Returns: * * `[PubKey, number]` - the program address and bump seed * @param {any[]} seeds * @param {Pubkey} program_id * @returns {any} */ static findProgramAddress(seeds, program_id) { const ptr0 = passArrayJsValueToWasm0(seeds, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; _assertClass(program_id, Pubkey); const ret = wasm.pubkey_findProgramAddress(ptr0, len0, program_id.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return takeFromExternrefTable0(ret[0]); } } const SystemInstructionFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_systeminstruction_free(ptr >>> 0, 1)); export class SystemInstruction { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; SystemInstructionFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_systeminstruction_free(ptr, 0); } /** * @param {Pubkey} from_pubkey * @param {Pubkey} to_pubkey * @param {bigint} lamports * @param {bigint} space * @param {Pubkey} owner * @returns {Instruction} */ static createAccount(from_pubkey, to_pubkey, lamports, space, owner) { _assertClass(from_pubkey, Pubkey); _assertClass(to_pubkey, Pubkey); _assertClass(owner, Pubkey); const ret = wasm.systeminstruction_createAccount(from_pubkey.__wbg_ptr, to_pubkey.__wbg_ptr, lamports, space, owner.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} from_pubkey * @param {Pubkey} to_pubkey * @param {Pubkey} base * @param {string} seed * @param {bigint} lamports * @param {bigint} space * @param {Pubkey} owner * @returns {Instruction} */ static createAccountWithSeed(from_pubkey, to_pubkey, base, seed, lamports, space, owner) { _assertClass(from_pubkey, Pubkey); _assertClass(to_pubkey, Pubkey); _assertClass(base, Pubkey); const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(owner, Pubkey); const ret = wasm.systeminstruction_createAccountWithSeed(from_pubkey.__wbg_ptr, to_pubkey.__wbg_ptr, base.__wbg_ptr, ptr0, len0, lamports, space, owner.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} pubkey * @param {Pubkey} owner * @returns {Instruction} */ static assign(pubkey, owner) { _assertClass(pubkey, Pubkey); _assertClass(owner, Pubkey); const ret = wasm.systeminstruction_assign(pubkey.__wbg_ptr, owner.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} pubkey * @param {Pubkey} base * @param {string} seed * @param {Pubkey} owner * @returns {Instruction} */ static assignWithSeed(pubkey, base, seed, owner) { _assertClass(pubkey, Pubkey); _assertClass(base, Pubkey); const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(owner, Pubkey); const ret = wasm.systeminstruction_assignWithSeed(pubkey.__wbg_ptr, base.__wbg_ptr, ptr0, len0, owner.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} from_pubkey * @param {Pubkey} to_pubkey * @param {bigint} lamports * @returns {Instruction} */ static transfer(from_pubkey, to_pubkey, lamports) { _assertClass(from_pubkey, Pubkey); _assertClass(to_pubkey, Pubkey); const ret = wasm.systeminstruction_transfer(from_pubkey.__wbg_ptr, to_pubkey.__wbg_ptr, lamports); return Instruction.__wrap(ret); } /** * @param {Pubkey} from_pubkey * @param {Pubkey} from_base * @param {string} from_seed * @param {Pubkey} from_owner * @param {Pubkey} to_pubkey * @param {bigint} lamports * @returns {Instruction} */ static transferWithSeed(from_pubkey, from_base, from_seed, from_owner, to_pubkey, lamports) { _assertClass(from_pubkey, Pubkey); _assertClass(from_base, Pubkey); const ptr0 = passStringToWasm0(from_seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(from_owner, Pubkey); _assertClass(to_pubkey, Pubkey); const ret = wasm.systeminstruction_transferWithSeed(from_pubkey.__wbg_ptr, from_base.__wbg_ptr, ptr0, len0, from_owner.__wbg_ptr, to_pubkey.__wbg_ptr, lamports); return Instruction.__wrap(ret); } /** * @param {Pubkey} pubkey * @param {bigint} space * @returns {Instruction} */ static allocate(pubkey, space) { _assertClass(pubkey, Pubkey); const ret = wasm.systeminstruction_allocate(pubkey.__wbg_ptr, space); return Instruction.__wrap(ret); } /** * @param {Pubkey} address * @param {Pubkey} base * @param {string} seed * @param {bigint} space * @param {Pubkey} owner * @returns {Instruction} */ static allocateWithSeed(address, base, seed, space, owner) { _assertClass(address, Pubkey); _assertClass(base, Pubkey); const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(owner, Pubkey); const ret = wasm.systeminstruction_allocateWithSeed(address.__wbg_ptr, base.__wbg_ptr, ptr0, len0, space, owner.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} from_pubkey * @param {Pubkey} nonce_pubkey * @param {Pubkey} authority * @param {bigint} lamports * @returns {Array<any>} */ static createNonceAccount(from_pubkey, nonce_pubkey, authority, lamports) { _assertClass(from_pubkey, Pubkey); _assertClass(nonce_pubkey, Pubkey); _assertClass(authority, Pubkey); const ret = wasm.systeminstruction_createNonceAccount(from_pubkey.__wbg_ptr, nonce_pubkey.__wbg_ptr, authority.__wbg_ptr, lamports); return ret; } /** * @param {Pubkey} nonce_pubkey * @param {Pubkey} authorized_pubkey * @returns {Instruction} */ static advanceNonceAccount(nonce_pubkey, authorized_pubkey) { _assertClass(nonce_pubkey, Pubkey); _assertClass(authorized_pubkey, Pubkey); const ret = wasm.systeminstruction_advanceNonceAccount(nonce_pubkey.__wbg_ptr, authorized_pubkey.__wbg_ptr); return Instruction.__wrap(ret); } /** * @param {Pubkey} nonce_pubkey * @param {Pubkey} authorized_pubkey * @param {Pubkey} to_pubkey * @param {bigint} lamports * @returns {Instruction} */ static withdrawNonceAccount(nonce_pubkey, authorized_pubkey, to_pubkey, lamports) { _assertClass(nonce_pubkey, Pubkey); _assertClass(authorized_pubkey, Pubkey); _assertClass(to_pubkey, Pubkey); const ret = wasm.systeminstruction_withdrawNonceAccount(nonce_pubkey.__wbg_ptr, authorized_pubkey.__wbg_ptr, to_pubkey.__wbg_ptr, lamports); return Instruction.__wrap(ret); } /** * @param {Pubkey} nonce_pubkey * @param {Pubkey} authorized_pubkey * @param {Pubkey} new_authority * @returns {Instruction} */ static authorizeNonceAccount(nonce_pubkey, authorized_pubkey, new_authority) { _assertClass(nonce_pubkey, Pubkey); _assertClass(authorized_pubkey, Pubkey); _assertClass(new_authority, Pubkey); const ret = wasm.systeminstruction_authorizeNonceAccount(nonce_pubkey.__wbg_ptr, authorized_pubkey.__wbg_ptr, new_authority.__wbg_ptr); return Instruction.__wrap(ret); } } const TransactionFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_transaction_free(ptr >>> 0, 1)); /** * An atomically-commited sequence of instructions. * * While [`Instruction`]s are the basic unit of computation in Solana, * they are submitted by clients in [`Transaction`]s containing one or * more instructions, and signed by one or more [`Signer`]s. * * [`Signer`]: crate::signer::Signer * * See the [module documentation] for more details about transactions. * * [module documentation]: self * * Some constructors accept an optional `payer`, the account responsible for * paying the cost of executing a transaction. In most cases, callers should * specify the payer explicitly in these constructors. In some cases though, * the caller is not _required_ to specify the payer, but is still allowed to: * in the [`Message`] structure, the first account is always the fee-payer, so * if the caller has knowledge that the first account of the constructed * transaction's `Message` is both a signer and the expected fee-payer, then * redundantly specifying the fee-payer is not strictly required. */ export class Transaction { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Transaction.prototype); obj.__wbg_ptr = ptr; TransactionFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; TransactionFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_transaction_free(ptr, 0); } /** * Create a new `Transaction` * @param {Instructions} instructions * @param {Pubkey | null} [payer] */ constructor(instructions, payer) { _assertClass(instructions, Instructions); var ptr0 = instructions.__destroy_into_raw(); let ptr1 = 0; if (!isLikeNone(payer)) { _assertClass(payer, Pubkey); ptr1 = payer.__destroy_into_raw(); } const ret = wasm.transaction_constructor(ptr0, ptr1); this.__wbg_ptr = ret >>> 0; TransactionFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Return a message containing all data that should be signed. * @returns {Message} */ message() { const ret = wasm.transaction_message(this.__wbg_ptr); return Message.__wrap(ret); } /** * Return the serialized message data to sign. * @returns {Uint8Array} */ messageData() { const ret = wasm.transaction_messageData(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * Verify the transaction */ verify() { const ret = wasm.transaction_verify(this.__wbg_ptr); if (ret[1]) { throw takeFromExternrefTable0(ret[0]); } } /** * @param {Keypair} keypair * @param {Hash} recent_blockhash */ partialSign(keypair, recent_blockhash) { _assertClass(keypair, Keypair); _assertClass(recent_blockhash, Hash); wasm.transaction_partialSign(this.__wbg_ptr, keypair.__wbg_ptr, recent_blockhash.__wbg_ptr); } /** * @returns {boolean} */ isSigned() { const ret = wasm.transaction_isSigned(this.__wbg_ptr); return ret !== 0; } /** * @returns {Uint8Array} */ toBytes() { const ret = wasm.transaction_toBytes(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * @param {Uint8Array} bytes * @returns {Transaction} */ static fromBytes(bytes) { const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.transaction_fromBytes(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return Transaction.__wrap(ret[0]); } } export function __wbg_buffer_609cc3eee51ed158(arg0) { const ret = arg0.buffer; return ret; }; export function __wbg_call_672a4d21634d4a24() { return handleError(function (arg0, arg1) { const ret = arg0.call(arg1); return ret; }, arguments) }; export function __wbg_call_7cccdd69e0791ae2() { return handleError(function (arg0, arg1, arg2) { const ret = arg0.call(arg1, arg2); return ret; }, arguments) }; export function __wbg_crypto_038798f665f985e2(arg0) { const ret = arg0.crypto; return ret; }; export function __wbg_crypto_ed58b8e10a292839(arg0) { const ret = arg0.crypto; return ret; }; export function __wbg_debug_3cb59063b29f58c1(arg0) { console.debug(arg0); }; export function __wbg_done_769e5ede4b31c67b(arg0) { const ret = arg0.done; return ret; }; export function __wbg_error_524f506f44df1645(arg0) { console.error(arg0); }; export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) { let deferred0_0; let deferred0_1; try { deferred0_0 = arg0; deferred0_1 = arg1; console.error(getStringFromWasm0(arg0, arg1)); } finally { wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); } }; export function __wbg_getRandomValues_371e7ade8bd92088(arg0, arg1) { arg0.getRandomValues(arg1); }; export function __wbg_getRandomValues_7dfe5bd1b67c9ca1(arg0) { const ret = arg0.getRandomValues; return ret; }; export function __wbg_getRandomValues_bcb4912f16000dc4() { return handleError(function (arg0, arg1) { arg0.getRandomValues(arg1); }, arguments) }; export function __wbg_get_67b2ba62fc30de12() { return handleError(function (arg0, arg1) { const ret = Reflect.get(arg0, arg1); return ret; }, arguments) }; export function __wbg_info_3daf2e093e091b66(arg0) { console.info(arg0); }; export function __wbg_instanceof_Uint8Array_17156bcf118086a9(arg0) { let result; try { result = arg0 instanceof Uint8Array; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_instruction_new(arg0) { const ret = Instruction.__wrap(arg0); return ret; }; export function __wbg_isArray_a1eab7e0d067391b(arg0) { const ret = Array.isArray(arg0); return ret; }; export function __wbg_iterator_9a24c88df860dc65() { const ret = Symbol.iterator; return ret; }; export function __wbg_length_a446193dc22c12f8(arg0) { const ret = arg0.length; return ret; }; export function __wbg_log_c222819a41e063d3(arg0) { console.log(arg0); }; export function __wbg_msCrypto_0a36e2ec3a343d26(arg0) { const ret = arg0.msCrypto; return ret; }; export function __wbg_msCrypto_ff35fce085fab2a3(arg0) { const ret = arg0.msCrypto; return ret; }; export function __wbg_new_78feb108b6472713() { const ret = new Array(); return ret; }; export function __wbg_new_8a6f238a6ece86ea() { const ret = new Error(); return ret; }; export function __wbg_new_a12002a7f91c75be(arg0) { const ret = new Uint8Array(arg0); return ret; }; export function __wbg_newnoargs_105ed471475aaf50(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return ret; }; export function __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a(arg0, arg1, arg2) { const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0); return ret; }; export function __wbg_newwithlength_a381634e90c276d4(arg0) { const ret = new Uint8Array(arg0 >>> 0); return ret; }; export function __wbg_newwithlength_c4c419ef0bc8a1f8(arg0) { const ret = new Array(arg0 >>> 0); return ret; }; export function __wbg_next_25feadfc0913fea9(arg0) { const ret = arg0.next; return ret; }; export function __wbg_next_6574e1a8a62d1055() { return handleError(function (arg0) { const ret = arg0.next(); return ret; }, arguments) }; export function __wbg_node_02999533c4ea02e3(arg0) { const ret = arg0.node; return ret; }; export function __wbg_process_5c1d670bc53614b8(arg0) { const ret = arg0.process; return ret; }; export function __wbg_pubkey_new(arg0) { const ret = Pubkey.__wrap(arg0); return ret; }; export function __wbg_push_737cfc8c1432c2c6(arg0, arg1) { const ret = arg0.push(arg1); return ret; }; export function __wbg_randomFillSync_994ac6d9ade7a695(arg0, arg1, arg2) { arg0.randomFillSync(getArrayU8FromWasm0(arg1, arg2)); }; export function __wbg_randomFillSync_ab2cfe79ebbf2740() { return handleError(function (arg0, arg1) { arg0.randomFillSync(arg1); }, arguments) }; export function __wbg_require_0d6aeaec3c042c88(arg0, arg1, arg2) { const ret = arg0.require(getStringFromWasm0(arg1, arg2)); return ret; }; export function __wbg_require_79b1e9274cde3c87() { return handleError(function () { const ret = module.require; return ret; }, arguments) }; export function __wbg_self_25aabeb5a7b41685() { return handleError(function () { const ret = self.self; return ret; }, arguments) }; export function __wbg_set_37837023f3d740e8(arg0, arg1, arg2) { arg0[arg1 >>> 0] = arg2; }; export function __wbg_set_65595bdd868b3009(arg0, arg1, arg2) { arg0.set(arg1, arg2 >>> 0); }; export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) { const ret = arg1.stack; const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbg_static_accessor_GLOBAL_88a902d13a557d07() { const ret = typeof global === 'undefined' ? null : global; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0() { const ret = typeof globalThis === 'undefined' ? null : globalThis; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_MODULE_ef3aa2eb251158a5() { const ret = module; return ret; }; export function __wbg_static_accessor_SELF_37c5d418e4bf5819() { const ret = typeof self === 'undefined' ? null : self; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_WINDOW_5de37043a91a9c40() { const ret = typeof window === 'undefined' ? null : window; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_subarray_aa9065fa9dc5df96(arg0, arg1, arg2) { const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0); return ret; }; export function __wbg_value_cd1ffa7b1ab794f1(arg0) { const ret = arg0.value; return ret; }; export function __wbg_values_99f7a68c7f313d66(arg0) { const ret = arg0.values(); return ret; }; export function __wbg_versions_c71aa1626a93e0a1(arg0) { const ret = arg0.versions; return ret; }; export function __wbg_warn_4ca3906c248c47c4(arg0) { console.warn(arg0); }; export function __wbindgen_debug_string(arg0, arg1) { const ret = debugString(arg1); const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_init_externref_table() { const table = wasm.__wbindgen_export_2; const offset = table.grow(4); table.set(0, undefined); table.set(offset + 0, undefined); table.set(offset + 1, null); table.set(offset + 2, true); table.set(offset + 3, false); ; }; export function __wbindgen_is_function(arg0) { const ret = typeof(arg0) === 'function'; return ret; }; export function __wbindgen_is_object(arg0) { const val = arg0; const ret = typeof(val) === 'object' && val !== null; return ret; }; export function __wbindgen_is_string(arg0) { const ret = typeof(arg0) === 'string'; return ret; }; export function __wbindgen_is_undefined(arg0) { const ret = arg0 === undefined; return ret; }; export function __wbindgen_memory() { const ret = wasm.memory; return ret; }; export function __wbindgen_number_get(arg0, arg1) { const obj = arg1; const ret = typeof(obj) === 'number' ? obj : undefined; getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); }; export function __wbindgen_number_new(arg0) { const ret = arg0; return ret; }; export function __wbindgen_string_get(arg0, arg1) { const obj = arg1; const ret = typeof(obj) === 'string' ? obj : undefined; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_string_new(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); return ret; }; export function __wbindgen_throw(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); };