let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;
let wasm;
const { TextDecoder } = require(String.raw`util`);
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
const heap = new Array(32).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function getObject(idx) { return heap[idx]; }
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let WASM_VECTOR_LEN = 0;
let cachegetNodeBufferMemory0 = null;
function getNodeBufferMemory0() {
if (cachegetNodeBufferMemory0 === null || cachegetNodeBufferMemory0.buffer !== wasm.memory.buffer) {
cachegetNodeBufferMemory0 = Buffer.from(wasm.memory.buffer);
}
return cachegetNodeBufferMemory0;
}
function passStringToWasm0(arg, malloc) {
const len = Buffer.byteLength(arg);
const ptr = malloc(len);
getNodeBufferMemory0().write(arg, ptr, len);
WASM_VECTOR_LEN = len;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
const u32CvtShim = new Uint32Array(2);
const uint64CvtShim = new BigUint64Array(u32CvtShim.buffer);
let stack_pointer = 32;
function addBorrowedObject(obj) {
if (stack_pointer == 1) throw new Error('out of js stack');
heap[--stack_pointer] = obj;
return stack_pointer;
}
function _assertClass(instance, klass) {
if (!(instance instanceof klass)) {
throw new Error(`expected instance of ${klass.name}`);
}
return instance.ptr;
}
/**
* Returns the git commit hash and commit date of the commit this library was built against.
* @returns {string}
*/
module.exports.build_id = function() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.build_id(retptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Generates random Base64 encoded asset type as a Base64 string. Used in asset definitions.
* @see {@link
* module:Findora-Wasm~TransactionBuilder#add_operation_create_asset|add_operation_create_asset}
* for instructions on how to define an asset with a new
* asset type
* @returns {string}
*/
module.exports.random_asset_type = function() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.random_asset_type(retptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Generates asset type as a Base64 string from a JSON-serialized JavaScript value.
* @returns {string}
*/
module.exports.asset_type_from_jsvalue = function(val) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.asset_type_from_jsvalue(retptr, addBorrowedObject(val));
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
heap[stack_pointer++] = undefined;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Given a serialized state commitment and transaction, returns true if the transaction correctly
* hashes up to the state commitment and false otherwise.
* @param {string} state_commitment - String representing the state commitment.
* @param {string} authenticated_txn - String representing the transaction.
* @see {@link module:Network~Network#getTxn|Network.getTxn} for instructions on fetching a transaction from the ledger.
* @see {@link module:Network~Network#getStateCommitment|Network.getStateCommitment}
* for instructions on fetching a ledger state commitment.
* @throws Will throw an error if the state commitment or the transaction fails to deserialize.
* @returns {boolean}
*/
module.exports.verify_authenticated_txn = function(state_commitment, authenticated_txn) {
var ptr0 = passStringToWasm0(state_commitment, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(authenticated_txn, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.verify_authenticated_txn(ptr0, len0, ptr1, len1);
return ret !== 0;
};
/**
* Given a serialized state commitment and an authenticated custom data result, returns true if the custom data result correctly
* hashes up to the state commitment and false otherwise.
* @param {string} state_commitment - String representing the state commitment.
* @param {JsValue} authenticated_txn - JSON-encoded value representing the authenticated custom
* data result.
* @throws Will throw an error if the state commitment or the authenticated result fail to deserialize.
* @returns {boolean}
*/
module.exports.verify_authenticated_custom_data_result = function(state_commitment, authenticated_res) {
var ptr0 = passStringToWasm0(state_commitment, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.verify_authenticated_custom_data_result(ptr0, len0, addHeapObject(authenticated_res));
return ret !== 0;
};
/**
* Performs a simple loan repayment fee calculation.
*
* The returned fee is a fraction of the `outstanding_balance`
* where the interest rate is expressed as a fraction `ir_numerator` / `ir_denominator`.
*
* This function is specific to the Lending Demo.
* @param {BigInt} ir_numerator - Interest rate numerator.
* @param {BigInt} ir_denominator - Interest rate denominator.
* @param {BigInt} outstanding_balance - Amount of outstanding debt.
* @ignore
* @returns {BigInt}
*/
module.exports.calculate_fee = function(ir_numerator, ir_denominator, outstanding_balance) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
uint64CvtShim[0] = ir_numerator;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
uint64CvtShim[0] = ir_denominator;
const low1 = u32CvtShim[0];
const high1 = u32CvtShim[1];
uint64CvtShim[0] = outstanding_balance;
const low2 = u32CvtShim[0];
const high2 = u32CvtShim[1];
wasm.calculate_fee(retptr, low0, high0, low1, high1, low2, high2);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
u32CvtShim[0] = r0;
u32CvtShim[1] = r1;
const n3 = uint64CvtShim[0];
return n3;
} finally {
wasm.__wbindgen_export_2.value += 16;
}
};
/**
* Returns an address to use for cancelling debt tokens in a debt swap.
* @ignore
* @returns {XfrPublicKey}
*/
module.exports.get_null_pk = function() {
var ret = wasm.get_null_pk();
return XfrPublicKey.__wrap(ret);
};
/**
* @ignore
* @returns {string}
*/
module.exports.create_default_policy_info = function() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.create_default_policy_info(retptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Create policy information needed for debt token asset types.
* This data will be parsed by the policy evalautor to ensure
* that all payment and fee amounts are correct.
* # Arguments
*
* * `ir_numerator` - interest rate numerator
* * `ir_denominator`- interest rate denominator
* * `fiat_code` - Base64 string representing asset type used to pay off the loan
* * `amount` - loan amount
* @ignore
* @returns {string}
*/
module.exports.create_debt_policy_info = function(ir_numerator, ir_denominator, fiat_code, loan_amount) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
uint64CvtShim[0] = ir_numerator;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
uint64CvtShim[0] = ir_denominator;
const low1 = u32CvtShim[0];
const high1 = u32CvtShim[1];
var ptr2 = passStringToWasm0(fiat_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
uint64CvtShim[0] = loan_amount;
const low3 = u32CvtShim[0];
const high3 = u32CvtShim[1];
wasm.create_debt_policy_info(retptr, low0, high0, low1, high1, ptr2, len2, low3, high3);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Creates the memo needed for debt token asset types. The memo will be parsed by the policy evaluator to ensure
* that all payment and fee amounts are correct.
* @param {BigInt} ir_numerator - Interest rate numerator.
* @param {BigInt} ir_denominator - Interest rate denominator.
* @param {string} fiat_code - Base64 string representing asset type used to pay off the loan.
* @param {BigInt} loan_amount - Loan amount.
* @throws Will throw an error if `fiat_code` fails to deserialize.
* @ignore
* @returns {string}
*/
module.exports.create_debt_memo = function(ir_numerator, ir_denominator, fiat_code, loan_amount) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
uint64CvtShim[0] = ir_numerator;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
uint64CvtShim[0] = ir_denominator;
const low1 = u32CvtShim[0];
const high1 = u32CvtShim[1];
var ptr2 = passStringToWasm0(fiat_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
uint64CvtShim[0] = loan_amount;
const low3 = u32CvtShim[0];
const high3 = u32CvtShim[1];
wasm.create_debt_memo(retptr, low0, high0, low1, high1, ptr2, len2, low3, high3);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
function isLikeNone(x) {
return x === undefined || x === null;
}
/**
* Returns a JavaScript object containing decrypted owner record information,
* where `amount` is the decrypted asset amount, and `asset_type` is the decrypted asset type code.
*
* @param {ClientAssetRecord} record - Owner record.
* @param {OwnerMemo} owner_memo - Owner memo of the associated record.
* @param {XfrKeyPair} keypair - Keypair of asset owner.
* @see {@link module:Findora-Wasm~ClientAssetRecord#from_json_record|ClientAssetRecord.from_json_record} for information about how to construct an asset record object
* from a JSON result returned from the ledger server.
* @param {OwnerMemo | undefined} owner_memo
* @returns {any}
*/
module.exports.open_client_asset_record = function(record, owner_memo, keypair) {
_assertClass(record, ClientAssetRecord);
let ptr0 = 0;
if (!isLikeNone(owner_memo)) {
_assertClass(owner_memo, OwnerMemo);
ptr0 = owner_memo.ptr;
owner_memo.ptr = 0;
}
_assertClass(keypair, XfrKeyPair);
var ret = wasm.open_client_asset_record(record.ptr, ptr0, keypair.ptr);
return takeObject(ret);
};
/**
* Extracts the public key as a string from a transfer key pair.
* @returns {string}
*/
module.exports.get_pub_key_str = function(key_pair) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
_assertClass(key_pair, XfrKeyPair);
wasm.get_pub_key_str(retptr, key_pair.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Extracts the private key as a string from a transfer key pair.
* @returns {string}
*/
module.exports.get_priv_key_str = function(key_pair) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
_assertClass(key_pair, XfrKeyPair);
wasm.get_priv_key_str(retptr, key_pair.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Creates a new transfer key pair.
* @returns {XfrKeyPair}
*/
module.exports.new_keypair = function() {
var ret = wasm.new_keypair();
return XfrKeyPair.__wrap(ret);
};
/**
* Generates a new keypair deterministically from a seed string and an optional name.
* @param {string | undefined} name
* @returns {XfrKeyPair}
*/
module.exports.new_keypair_from_seed = function(seed_str, name) {
var ptr0 = passStringToWasm0(seed_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.new_keypair_from_seed(ptr0, len0, ptr1, len1);
return XfrKeyPair.__wrap(ret);
};
/**
* Returns base64 encoded representation of an XfrPublicKey.
* @returns {string}
*/
module.exports.public_key_to_base64 = function(key) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
_assertClass(key, XfrPublicKey);
wasm.public_key_to_base64(retptr, key.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Converts a base64 encoded public key string to a public key.
* @returns {XfrPublicKey}
*/
module.exports.public_key_from_base64 = function(key_pair) {
var ptr0 = passStringToWasm0(key_pair, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.public_key_from_base64(ptr0, len0);
return XfrPublicKey.__wrap(ret);
};
/**
* Expresses a transfer key pair as a hex-encoded string.
* To decode the string, use `keypair_from_str` function.
* @returns {string}
*/
module.exports.keypair_to_str = function(key_pair) {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
_assertClass(key_pair, XfrKeyPair);
wasm.keypair_to_str(retptr, key_pair.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
};
/**
* Constructs a transfer key pair from a hex-encoded string.
* The encode a key pair, use `keypair_to_str` function.
* @returns {XfrKeyPair}
*/
module.exports.keypair_from_str = function(str) {
var ptr0 = passStringToWasm0(str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.keypair_from_str(ptr0, len0);
return XfrKeyPair.__wrap(ret);
};
/**
* Generates a new credential issuer key.
* @param {JsValue} attributes - Array of attribute types of the form `[{name: "credit_score",
* size: 3}]`. The size refers to byte-size of the credential. In this case, the "credit_score"
* attribute is represented as a 3 byte string "760". `attributes` is the list of attribute types
* that the issuer can sign off on.
* @returns {CredentialIssuerKeyPair}
*/
module.exports.wasm_credential_issuer_key_gen = function(attributes) {
var ret = wasm.wasm_credential_issuer_key_gen(addHeapObject(attributes));
return CredentialIssuerKeyPair.__wrap(ret);
};
/**
* Verifies a credential commitment. Used to confirm that a credential is tied to a ledger
* address.
* @param {CredIssuerPublicKey} issuer_pub_key - The credential issuer that has attested to the
* credentials that have been committed to.
* @param {CredentialCommitment} Credential commitment
* @param {CredPoK} Proof of knowledge of the underlying commitment
* @param {XfrPublicKey} Ledger address linked to this credential commitment.
* @throws Will throw an error during verification failure (i.e. the supplied ledger address is
* incorrect, the commitment is tied to a different credential issuer, or the proof of knowledge is
* invalid, etc.)
*/
module.exports.wasm_credential_verify_commitment = function(issuer_pub_key, commitment, pok, xfr_pk) {
_assertClass(issuer_pub_key, CredIssuerPublicKey);
_assertClass(commitment, CredentialCommitment);
_assertClass(pok, CredentialPoK);
_assertClass(xfr_pk, XfrPublicKey);
wasm.wasm_credential_verify_commitment(issuer_pub_key.ptr, commitment.ptr, pok.ptr, xfr_pk.ptr);
};
/**
* Generates a new reveal proof from a credential commitment key.
* @param {CredUserSecretKey} user_secret_key - Secret key of the credential user who owns
* the credentials.
* @param {Credential} credential - Credential whose attributes will be revealed.
* @param {JsValue} reveal_fields - Array of strings representing attribute fields to reveal.
* @throws Will throw an error if a reveal proof cannot be generated from the credential
* or ```reveal_fields``` fails to deserialize.
* @returns {CredentialPoK}
*/
module.exports.wasm_credential_open_commitment = function(user_secret_key, credential, key, reveal_fields) {
_assertClass(user_secret_key, CredUserSecretKey);
_assertClass(credential, Credential);
_assertClass(key, CredentialCommitmentKey);
var ret = wasm.wasm_credential_open_commitment(user_secret_key.ptr, credential.ptr, key.ptr, addHeapObject(reveal_fields));
return CredentialPoK.__wrap(ret);
};
/**
* Generates a new credential user key.
* @param {CredIssuerPublicKey} issuer_pub_key - The credential issuer that can sign off on this
* user's attributes.
* @returns {CredentialUserKeyPair}
*/
module.exports.wasm_credential_user_key_gen = function(issuer_pub_key) {
_assertClass(issuer_pub_key, CredIssuerPublicKey);
var ret = wasm.wasm_credential_user_key_gen(issuer_pub_key.ptr);
return CredentialUserKeyPair.__wrap(ret);
};
/**
* Generates a signature on user attributes that can be used to create a credential.
* @param {CredIssuerSecretKey} issuer_secret_key - Secret key of credential issuer.
* @param {CredUserPublicKey} user_public_key - Public key of credential user.
* @param {JsValue} attributes - Array of attribute assignments of the form `[{name: "credit_score",
* val: "760"}]`.
* @throws Will throw an error if the signature cannot be generated.
* @returns {CredentialSignature}
*/
module.exports.wasm_credential_sign = function(issuer_secret_key, user_public_key, attributes) {
_assertClass(issuer_secret_key, CredIssuerSecretKey);
_assertClass(user_public_key, CredUserPublicKey);
var ret = wasm.wasm_credential_sign(issuer_secret_key.ptr, user_public_key.ptr, addHeapObject(attributes));
return CredentialSignature.__wrap(ret);
};
/**
* Generates a signature on user attributes that can be used to create a credential.
* @param {CredIssuerPublicKey} issuer_public_key - Public key of credential issuer.
* @param {CredentialSignature} signature - Credential issuer signature on attributes.
* @param {JsValue} attributes - Array of attribute assignments of the form `[{name: "credit_score",
* val: "760"}]'.
* @returns {Credential}
*/
module.exports.create_credential = function(issuer_public_key, signature, attributes) {
try {
_assertClass(issuer_public_key, CredIssuerPublicKey);
_assertClass(signature, CredentialSignature);
var ret = wasm.create_credential(issuer_public_key.ptr, signature.ptr, addBorrowedObject(attributes));
return Credential.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
};
/**
* Generates a credential commitment. A credential commitment can be used to selectively reveal
* attribute assignments.
* @param {CredUserSecretKey} user_secret_key - Secret key of credential user.
* @param {XfrPublicKey} user_public_key - Ledger signing key to link this credential to.
* @param {Credential} credential - Credential object.
* @returns {CredentialCommitmentData}
*/
module.exports.wasm_credential_commit = function(user_secret_key, user_public_key, credential) {
_assertClass(user_secret_key, CredUserSecretKey);
_assertClass(user_public_key, XfrPublicKey);
_assertClass(credential, Credential);
var ret = wasm.wasm_credential_commit(user_secret_key.ptr, user_public_key.ptr, credential.ptr);
return CredentialCommitmentData.__wrap(ret);
};
/**
* Selectively reveals attributes committed to in a credential commitment
* @param {CredUserSecretKey} user_sk - Secret key of credential user.
* @param {Credential} credential - Credential object.
* @param {JsValue} reveal_fields - Array of string names representing credentials to reveal (i.e.
* `["credit_score"]`).
* @returns {CredentialRevealSig}
*/
module.exports.wasm_credential_reveal = function(user_sk, credential, reveal_fields) {
_assertClass(user_sk, CredUserSecretKey);
_assertClass(credential, Credential);
var ret = wasm.wasm_credential_reveal(user_sk.ptr, credential.ptr, addHeapObject(reveal_fields));
return CredentialRevealSig.__wrap(ret);
};
/**
* Verifies revealed attributes from a commitment.
* @param {CredIssuerPublicKey} issuer_pub_key - Public key of credential issuer.
* @param {JsValue} attributes - Array of attribute assignments to check of the form `[{name: "credit_score",
* val: "760"}]`.
* @param {CredentialCommitment} commitment - Commitment to the credential.
* @param {CredentialPoK} pok - Proof that the credential commitment is valid and commits
* to the attribute values being revealed.
*/
module.exports.wasm_credential_verify = function(issuer_pub_key, attributes, commitment, pok) {
_assertClass(issuer_pub_key, CredIssuerPublicKey);
_assertClass(commitment, CredentialCommitment);
_assertClass(pok, CredentialPoK);
wasm.wasm_credential_verify(issuer_pub_key.ptr, addHeapObject(attributes), commitment.ptr, pok.ptr);
};
/**
* Returns information about traceable assets for a given transfer.
* @param {JsValue} xfr_body - JSON of a transfer note from a transfer operation.
* @param {AssetTracerKeyPair} tracer_keypair - Asset tracer keypair.
* @param {JsValue} candidate_assets - List of asset types traced by the tracer keypair.
* @returns {any}
*/
module.exports.trace_assets = function(xfr_body, tracer_keypair, candidate_assets) {
_assertClass(tracer_keypair, AssetTracerKeyPair);
var ret = wasm.trace_assets(addHeapObject(xfr_body), tracer_keypair.ptr, addHeapObject(candidate_assets));
return takeObject(ret);
};
function handleError(f) {
return function () {
try {
return f.apply(this, arguments);
} catch (e) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
};
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* When an asset is defined, several options governing the assets must be
* specified:
* 1. **Traceable**: Records and identities of traceable assets can be decrypted by a provided tracking key. By defaults, assets do not have
* any tracing policies.
* 2. **Transferable**: Non-transferable assets can only be transferred once from the issuer to another user. By default, assets are transferable.
* 3. **Updatable**: Whether the asset memo can be updated. By default, assets are not updatable.
* 4. **Transfer signature rules**: Signature weights and threshold for a valid transfer. By
* default, there are no special signature requirements.
* 5. **Max units**: Optional limit on the total number of units of this asset that can be issued.
* By default, assets do not have issuance caps.
* @see {@link module:Findora-Wasm~TracingPolicies|TracingPolicies} for more information about tracing policies.
* @see {@link module:Findora-Wasm~TransactionBuilder#add_operation_update_memo|add_operation_update_memo} for more information about how to add
* a memo update operation to a transaction.
* @see {@link module:Findora-Wasm~SignatureRules|SignatureRules} for more information about co-signatures.
* @see {@link
* module:Findora-Wasm~TransactionBuilder#add_operation_create_asset|add_operation_create_asset}
* for information about how to add asset rules to an asset definition.
*/
class AssetRules {
static __wrap(ptr) {
const obj = Object.create(AssetRules.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_assetrules_free(ptr);
}
/**
* Create a default set of asset rules. See class description for defaults.
* @returns {AssetRules}
*/
static new() {
var ret = wasm.assetrules_new();
return AssetRules.__wrap(ret);
}
/**
* Adds an asset tracing policy.
* @param {TracingPolicy} policy - Tracing policy for the new asset.
* @returns {AssetRules}
*/
add_tracing_policy(policy) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(policy, TracingPolicy);
var ret = wasm.assetrules_add_tracing_policy(ptr, policy.ptr);
return AssetRules.__wrap(ret);
}
/**
* Set a cap on the number of units of this asset that can be issued.
* @param {BigInt} max_units - Maximum number of units that can be issued.
* @returns {AssetRules}
*/
set_max_units(max_units) {
var ptr = this.ptr;
this.ptr = 0;
uint64CvtShim[0] = max_units;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.assetrules_set_max_units(ptr, low0, high0);
return AssetRules.__wrap(ret);
}
/**
* Transferability toggle. Assets that are not transferable can only be transferred by the asset
* issuer.
* @param {boolean} transferable - Boolean indicating whether asset can be transferred.
* @returns {AssetRules}
*/
set_transferable(transferable) {
var ptr = this.ptr;
this.ptr = 0;
var ret = wasm.assetrules_set_transferable(ptr, transferable);
return AssetRules.__wrap(ret);
}
/**
* The updatable flag determines whether the asset memo can be updated after issuance.
* @param {boolean} updatable - Boolean indicating whether asset memo can be updated.
* @see {@link module:Findora-Wasm~TransactionBuilder#add_operation_update_memo|add_operation_update_memo} for more information about how to add
* a memo update operation to a transaction.
* @returns {AssetRules}
*/
set_updatable(updatable) {
var ptr = this.ptr;
this.ptr = 0;
var ret = wasm.assetrules_set_updatable(ptr, updatable);
return AssetRules.__wrap(ret);
}
/**
* Co-signature rules. Assets with co-signatue rules require additional weighted signatures to
* be transferred.
* @param {SignatureRules} multisig_rules - Co-signature restrictions.
* @returns {AssetRules}
*/
set_transfer_multisig_rules(multisig_rules) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(multisig_rules, SignatureRules);
var ptr0 = multisig_rules.ptr;
multisig_rules.ptr = 0;
var ret = wasm.assetrules_set_transfer_multisig_rules(ptr, ptr0);
return AssetRules.__wrap(ret);
}
}
module.exports.AssetRules = AssetRules;
/**
* Key pair used by asset tracers to decrypt asset amounts, types, and identity
* commitments associated with traceable asset transfers.
* @see {@link module:Findora-Wasm.TracingPolicy|TracingPolicy} for information about tracing policies.
* @see {@link module:Findora-Wasm~AssetRules#add_tracing_policy|add_tracing_policy} for information about how to add a tracing policy to
* an asset definition.
*/
class AssetTracerKeyPair {
static __wrap(ptr) {
const obj = Object.create(AssetTracerKeyPair.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_assettracerkeypair_free(ptr);
}
/**
* Creates a new tracer key pair.
* @returns {AssetTracerKeyPair}
*/
static new() {
var ret = wasm.assettracerkeypair_new();
return AssetTracerKeyPair.__wrap(ret);
}
}
module.exports.AssetTracerKeyPair = AssetTracerKeyPair;
/**
* Object representing an asset definition. Used to fetch tracing policies and any other
* information that may be required to construct a valid transfer or issuance.
*/
class AssetType {
static __wrap(ptr) {
const obj = Object.create(AssetType.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_assettype_free(ptr);
}
/**
* Builds an asset type from a JSON-encoded JavaScript value.
* @param {JsValue} val - JSON-encoded asset type fetched from ledger server with the `asset_token/{code}` route.
* Note: The first field of an asset type is `properties`. See the example below.
*
* @example
* "properties":{
* "code":{
* "val":[151,8,106,38,126,101,250,236,134,77,83,180,43,152,47,57,83,30,60,8,132,218,48,52,167,167,190,244,34,45,78,80]
* },
* "issuer":{"key":“iFW4jY_DQVSGED05kTseBBn0BllPB9Q9escOJUpf4DY=”},
* "memo":“test memo”,
* "asset_rules":{
* "transferable":true,
* "updatable":false,
* "transfer_multisig_rules":null,
* "max_units":5000
* }
* }
*
* @see {@link module:Findora-Network~Network#getAssetProperties|Network.getAsset} for information about how to
* fetch an asset type from the ledger server.
* @returns {AssetType}
*/
static from_json(json) {
try {
var ret = wasm.assettype_from_json(addBorrowedObject(json));
return AssetType.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
/**
* Fetch the tracing policies associated with this asset type.
* @returns {TracingPolicies}
*/
get_tracing_policies() {
var ret = wasm.assettype_get_tracing_policies(this.ptr);
return TracingPolicies.__wrap(ret);
}
}
module.exports.AssetType = AssetType;
/**
* Authenticated address identity registry value. Contains a proof that the AIR result is stored
* on the ledger.
*/
class AuthenticatedAIRResult {
static __wrap(ptr) {
const obj = Object.create(AuthenticatedAIRResult.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_authenticatedairresult_free(ptr);
}
/**
* Construct an AIRResult from the JSON-encoded value returned by the ledger.
* @see {@link module:Findora-Network~Network#getAIRResult|Network.getAIRResult} for information about how to fetch a
* value from the address identity registry.
* @returns {AuthenticatedAIRResult}
*/
static from_json(json) {
try {
var ret = wasm.authenticatedairresult_from_json(addBorrowedObject(json));
return AuthenticatedAIRResult.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
/**
* Returns true if the authenticated AIR result proofs verify succesfully. If the proofs are
* valid, the identity commitment contained in the AIR result is a valid part of the ledger.
* @param {string} state_commitment - String representing the ledger state commitment.
* @returns {boolean}
*/
is_valid(state_commitment) {
var ptr0 = passStringToWasm0(state_commitment, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.authenticatedairresult_is_valid(this.ptr, ptr0, len0);
return ret !== 0;
}
/**
* Returns the underlying credential commitment of the AIR result.
* @returns {CredentialCommitment | undefined}
*/
get_commitment() {
var ret = wasm.authenticatedairresult_get_commitment(this.ptr);
return ret === 0 ? undefined : CredentialCommitment.__wrap(ret);
}
}
module.exports.AuthenticatedAIRResult = AuthenticatedAIRResult;
/**
* Object representing an authenticable asset record. Clients can validate authentication proofs
* against a ledger state commitment.
*/
class AuthenticatedAssetRecord {
static __wrap(ptr) {
const obj = Object.create(AuthenticatedAssetRecord.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_authenticatedassetrecord_free(ptr);
}
/**
* Given a serialized state commitment, returns true if the
* authenticated UTXO proofs validate correctly and false otherwise. If the proofs validate, the
* asset record contained in this structure exists on the ledger and is unspent.
* @param {string} state_commitment - String representing the state commitment.
* @see {@link module:Findora-Network~Network#getStateCommitment|getStateCommitment} for instructions on fetching a ledger state commitment.
* @throws Will throw an error if the state commitment fails to deserialize.
* @returns {boolean}
*/
is_valid(state_commitment) {
var ptr0 = passStringToWasm0(state_commitment, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.authenticatedassetrecord_is_valid(this.ptr, ptr0, len0);
return ret !== 0;
}
/**
* Builds an AuthenticatedAssetRecord from a JSON-encoded asset record returned from the ledger
* server.
* @param {JsValue} val - JSON-encoded asset record fetched from ledger server.
* @see {@link module:Findora-Network~Network#getUtxo|Network.getUtxo} for information about how to
* fetch an asset record from the ledger server.
* @returns {AuthenticatedAssetRecord}
*/
static from_json_record(record) {
try {
var ret = wasm.authenticatedassetrecord_from_json_record(addBorrowedObject(record));
return AuthenticatedAssetRecord.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.AuthenticatedAssetRecord = AuthenticatedAssetRecord;
/**
* This object represents an asset record owned by a ledger key pair.
* @see {@link module:Findora-Wasm.open_client_asset_record|open_client_asset_record} for information about how to decrypt an encrypted asset
* record.
*/
class ClientAssetRecord {
static __wrap(ptr) {
const obj = Object.create(ClientAssetRecord.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_clientassetrecord_free(ptr);
}
/**
* Builds a client record from a JSON-encoded JavaScript value.
*
* @param {JsValue} val - JSON-encoded autehtnicated asset record fetched from ledger server with the `utxo_sid/{sid}` route,
* where `sid` can be fetched from the query server with the `get_owned_utxos/{address}` route.
* Note: The first field of an asset record is `utxo`. See the example below.
*
* @example
* "utxo":{
* "amount":{
* "NonConfidential":5
* },
* "asset_type":{
* "NonConfidential":[113,168,158,149,55,64,18,189,88,156,133,204,156,46,106,46,232,62,69,233,157,112,240,132,164,120,4,110,14,247,109,127]
* },
* "public_key":"Glf8dKF6jAPYHzR_PYYYfzaWqpYcMvnrIcazxsilmlA="
* }
*
* @see {@link module:Findora-Network~Network#getUtxo|Network.getUtxo} for information about how to
* fetch an asset record from the ledger server.
* @returns {ClientAssetRecord}
*/
static from_json(val) {
try {
var ret = wasm.clientassetrecord_from_json(addBorrowedObject(val));
return ClientAssetRecord.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.ClientAssetRecord = ClientAssetRecord;
/**
* Public key of a credential issuer.
*/
class CredIssuerPublicKey {
static __wrap(ptr) {
const obj = Object.create(CredIssuerPublicKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credissuerpublickey_free(ptr);
}
}
module.exports.CredIssuerPublicKey = CredIssuerPublicKey;
/**
* Secret key of a credential issuer.
*/
class CredIssuerSecretKey {
static __wrap(ptr) {
const obj = Object.create(CredIssuerSecretKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credissuersecretkey_free(ptr);
}
}
module.exports.CredIssuerSecretKey = CredIssuerSecretKey;
/**
* Public key of a credential user.
*/
class CredUserPublicKey {
static __wrap(ptr) {
const obj = Object.create(CredUserPublicKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_creduserpublickey_free(ptr);
}
}
module.exports.CredUserPublicKey = CredUserPublicKey;
/**
* Secret key of a credential user.
*/
class CredUserSecretKey {
static __wrap(ptr) {
const obj = Object.create(CredUserSecretKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credusersecretkey_free(ptr);
}
}
module.exports.CredUserSecretKey = CredUserSecretKey;
/**
* A user credential that can be used to selectively reveal credential attributes.
* @see {@link module:Findora-Wasm.wasm_credential_commit|wasm_credential_commit} for information about how to commit to a credential.
* @see {@link module:Findora-Wasm.wasm_credential_reveal|wasm_credential_reveal} for information about how to selectively reveal credential
* attributes.
*/
class Credential {
static __wrap(ptr) {
const obj = Object.create(Credential.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credential_free(ptr);
}
}
module.exports.Credential = Credential;
/**
* Commitment to a credential record.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
*/
class CredentialCommitment {
static __wrap(ptr) {
const obj = Object.create(CredentialCommitment.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialcommitment_free(ptr);
}
}
module.exports.CredentialCommitment = CredentialCommitment;
/**
* Commitment to a credential record, proof that the commitment is valid, and credential key that can be used
* to open a commitment.
*/
class CredentialCommitmentData {
static __wrap(ptr) {
const obj = Object.create(CredentialCommitmentData.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialcommitmentdata_free(ptr);
}
/**
* Returns the underlying credential commitment.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
* @returns {CredentialCommitment}
*/
get_commitment() {
var ret = wasm.credentialcommitmentdata_get_commitment(this.ptr);
return CredentialCommitment.__wrap(ret);
}
/**
* Returns the underlying proof of knowledge that the credential is valid.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
* @returns {CredentialPoK}
*/
get_pok() {
var ret = wasm.credentialcommitmentdata_get_pok(this.ptr);
return CredentialPoK.__wrap(ret);
}
/**
* Returns the key used to generate the commitment.
* @see {@link module:Findora-Wasm.wasm_credential_open_commitment|wasm_credential_open_commitment} for information about how to open a
* credential commitment.
* @returns {CredentialCommitmentKey}
*/
get_commit_key() {
var ret = wasm.credentialcommitmentdata_get_commit_key(this.ptr);
return CredentialCommitmentKey.__wrap(ret);
}
}
module.exports.CredentialCommitmentData = CredentialCommitmentData;
/**
* Key used to generate a credential commitment.
* @see {@link module:Findora-Wasm.wasm_credential_open_commitment|wasm_credential_open_commitment} for information about how to
* open a credential commitment.
*/
class CredentialCommitmentKey {
static __wrap(ptr) {
const obj = Object.create(CredentialCommitmentKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialcommitmentkey_free(ptr);
}
}
module.exports.CredentialCommitmentKey = CredentialCommitmentKey;
/**
* Key pair of a credential issuer.
*/
class CredentialIssuerKeyPair {
static __wrap(ptr) {
const obj = Object.create(CredentialIssuerKeyPair.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialissuerkeypair_free(ptr);
}
/**
* Returns the credential issuer's public key.
* @returns {CredIssuerPublicKey}
*/
get_pk() {
var ret = wasm.credentialissuerkeypair_get_pk(this.ptr);
return CredIssuerPublicKey.__wrap(ret);
}
/**
* Returns the credential issuer's secret key.
* @returns {CredIssuerSecretKey}
*/
get_sk() {
var ret = wasm.credentialissuerkeypair_get_sk(this.ptr);
return CredIssuerSecretKey.__wrap(ret);
}
/**
* Convert the key pair to a serialized value that can be used in the browser.
* @returns {any}
*/
to_json() {
var ret = wasm.credentialissuerkeypair_to_json(this.ptr);
return takeObject(ret);
}
/**
* Generate a key pair from a JSON-serialized JavaScript value.
* @returns {CredentialIssuerKeyPair}
*/
static from_json(val) {
try {
var ret = wasm.credentialissuerkeypair_from_json(addBorrowedObject(val));
return CredentialIssuerKeyPair.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.CredentialIssuerKeyPair = CredentialIssuerKeyPair;
/**
* Proof that a credential is a valid re-randomization of a credential signed by a certain asset
* issuer.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
*/
class CredentialPoK {
static __wrap(ptr) {
const obj = Object.create(CredentialPoK.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialpok_free(ptr);
}
}
module.exports.CredentialPoK = CredentialPoK;
/**
* Reveal signature of a credential record.
*/
class CredentialRevealSig {
static __wrap(ptr) {
const obj = Object.create(CredentialRevealSig.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialrevealsig_free(ptr);
}
/**
* Returns the underlying credential commitment.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
* @returns {CredentialCommitment}
*/
get_commitment() {
var ret = wasm.credentialcommitmentdata_get_commitment(this.ptr);
return CredentialCommitment.__wrap(ret);
}
/**
* Returns the underlying proof of knowledge that the credential is valid.
* @see {@link module:Findora-Wasm.wasm_credential_verify_commitment|wasm_credential_verify_commitment} for information about how to verify a
* credential commitment.
* @returns {CredentialPoK}
*/
get_pok() {
var ret = wasm.credentialrevealsig_get_pok(this.ptr);
return CredentialPoK.__wrap(ret);
}
}
module.exports.CredentialRevealSig = CredentialRevealSig;
/**
* Signature of a credential record.
*/
class CredentialSignature {
static __wrap(ptr) {
const obj = Object.create(CredentialSignature.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialsignature_free(ptr);
}
}
module.exports.CredentialSignature = CredentialSignature;
/**
* Key pair of a credential user.
*/
class CredentialUserKeyPair {
static __wrap(ptr) {
const obj = Object.create(CredentialUserKeyPair.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_credentialuserkeypair_free(ptr);
}
/**
* Returns the credential issuer's public key.
* @returns {CredUserPublicKey}
*/
get_pk() {
var ret = wasm.credentialuserkeypair_get_pk(this.ptr);
return CredUserPublicKey.__wrap(ret);
}
/**
* Returns the credential issuer's secret key.
* @returns {CredUserSecretKey}
*/
get_sk() {
var ret = wasm.credentialuserkeypair_get_sk(this.ptr);
return CredUserSecretKey.__wrap(ret);
}
/**
* Convert the key pair to a serialized value that can be used in the browser.
* @returns {any}
*/
to_json() {
var ret = wasm.credentialuserkeypair_to_json(this.ptr);
return takeObject(ret);
}
/**
* Generate a key pair from a JSON-serialized JavaScript value.
* @returns {CredentialUserKeyPair}
*/
static from_json(val) {
try {
var ret = wasm.credentialuserkeypair_from_json(addBorrowedObject(val));
return CredentialUserKeyPair.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.CredentialUserKeyPair = CredentialUserKeyPair;
/**
* Blinding factor for a custom data operation. A blinding factor adds a random value to the
* custom data being hashed to make the hash hiding.
*/
class KVBlind {
static __wrap(ptr) {
const obj = Object.create(KVBlind.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_kvblind_free(ptr);
}
/**
* Generate a random blinding factor.
* @returns {KVBlind}
*/
static gen_random() {
var ret = wasm.kvblind_gen_random();
return KVBlind.__wrap(ret);
}
/**
* Convert the key pair to a JSON-encoded value that can be used in the browser.
* @returns {any}
*/
to_json() {
var ret = wasm.kvblind_to_json(this.ptr);
return takeObject(ret);
}
/**
* Create a KVBlind from a JSON-encoded value.
* @returns {KVBlind}
*/
static from_json(val) {
try {
var ret = wasm.kvblind_from_json(addBorrowedObject(val));
return KVBlind.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.KVBlind = KVBlind;
/**
* Hash that can be stored in the ledger's custom data store.
*/
class KVHash {
static __wrap(ptr) {
const obj = Object.create(KVHash.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_kvhash_free(ptr);
}
/**
* Generate a new custom data hash without a blinding factor.
* @param {JsValue} data - Data to hash. Must be an array of bytes.
* @returns {KVHash}
*/
static new_no_blind(data) {
try {
var ret = wasm.kvhash_new_no_blind(addBorrowedObject(data));
return KVHash.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
/**
* Generate a new custom data hash with a blinding factor.
* @param {JsValue} data - Data to hash. Must be an array of bytes.
* @param {KVBlind} kv_blind - Optional blinding factor.
* @returns {KVHash}
*/
static new_with_blind(data, kv_blind) {
try {
_assertClass(kv_blind, KVBlind);
var ret = wasm.kvhash_new_with_blind(addBorrowedObject(data), kv_blind.ptr);
return KVHash.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
}
module.exports.KVHash = KVHash;
/**
* Key for hashes in the ledger's custom data store.
*/
class Key {
static __wrap(ptr) {
const obj = Object.create(Key.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_key_free(ptr);
}
/**
* Generate a random key.
* Figure out how to store prng ref in browser: https://bugtracker.findora.org/issues/63
* @returns {Key}
*/
static gen_random() {
var ret = wasm.key_gen_random();
return Key.__wrap(ret);
}
/**
* Returns a base64 encoded version of the Key.
* @returns {string}
*/
to_base64() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.key_to_base64(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Generates a Key from a base64-encoded String.
* @returns {Key}
*/
static from_base64(string) {
var ptr0 = passStringToWasm0(string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.key_from_base64(ptr0, len0);
return Key.__wrap(ret);
}
}
module.exports.Key = Key;
/**
* Asset owner memo. Contains information needed to decrypt an asset record.
* @see {@link module:Findora-Wasm.ClientAssetRecord|ClientAssetRecord} for more details about asset records.
*/
class OwnerMemo {
static __wrap(ptr) {
const obj = Object.create(OwnerMemo.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_ownermemo_free(ptr);
}
/**
* Builds an owner memo from a JSON-serialized JavaScript value.
* @param {JsValue} val - JSON owner memo fetched from query server with the `get_owner_memo/{sid}` route,
* where `sid` can be fetched from the query server with the `get_owned_utxos/{address}` route. See the example below.
*
* @example
* {
* "blind_share":[91,251,44,28,7,221,67,155,175,213,25,183,70,90,119,232,212,238,226,142,159,200,54,19,60,115,38,221,248,202,74,248],
* "lock":{"ciphertext":[119,54,117,136,125,133,112,193],"encoded_rand":"8KDql2JphPB5WLd7-aYE1bxTQAcweFSmrqymLvPDntM="}
* }
* @returns {OwnerMemo}
*/
static from_json(val) {
try {
var ret = wasm.ownermemo_from_json(addBorrowedObject(val));
return OwnerMemo.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
/**
* Creates a clone of the owner memo.
* @returns {OwnerMemo}
*/
clone() {
var ret = wasm.ownermemo_clone(this.ptr);
return OwnerMemo.__wrap(ret);
}
}
module.exports.OwnerMemo = OwnerMemo;
/**
* Public parameters necessary for generating asset records. Generating this is expensive and
* should be done as infrequently as possible.
* @see {@link module:Findora-Wasm~TransactionBuilder#add_basic_issue_asset|add_basic_issue_asset}
* for information using public parameters to create issuance asset records.
*/
class PublicParams {
static __wrap(ptr) {
const obj = Object.create(PublicParams.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_publicparams_free(ptr);
}
/**
* Generates a new set of parameters.
* @returns {PublicParams}
*/
static new() {
var ret = wasm.publicparams_new();
return PublicParams.__wrap(ret);
}
}
module.exports.PublicParams = PublicParams;
/**
* Stores threshold and weights for a multisignature requirement.
*/
class SignatureRules {
static __wrap(ptr) {
const obj = Object.create(SignatureRules.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_signaturerules_free(ptr);
}
/**
* Creates a new set of co-signature rules.
*
* @param {BigInt} threshold - Minimum sum of signature weights that is required for an asset
* transfer.
* @param {JsValue} weights - Array of public key weights of the form `[["kAb...", BigInt(5)]]', where the
* first element of each tuple is a base64 encoded public key and the second is the key's
* associated weight.
* @returns {SignatureRules}
*/
static new(threshold, weights) {
uint64CvtShim[0] = threshold;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.signaturerules_new(low0, high0, addHeapObject(weights));
return SignatureRules.__wrap(ret);
}
}
module.exports.SignatureRules = SignatureRules;
/**
* A collection of tracing policies. Use this object when constructing asset transfers to generate
* the correct tracing proofs for traceable assets.
*/
class TracingPolicies {
static __wrap(ptr) {
const obj = Object.create(TracingPolicies.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_tracingpolicies_free(ptr);
}
}
module.exports.TracingPolicies = TracingPolicies;
/**
* Tracing policy for asset transfers. Can be configured to track credentials, the asset type and
* amount, or both.
*/
class TracingPolicy {
static __wrap(ptr) {
const obj = Object.create(TracingPolicy.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_tracingpolicy_free(ptr);
}
/**
* @returns {TracingPolicy}
*/
static new_with_tracking(tracing_key) {
_assertClass(tracing_key, AssetTracerKeyPair);
var ret = wasm.tracingpolicy_new_with_tracking(tracing_key.ptr);
return TracingPolicy.__wrap(ret);
}
/**
* @returns {TracingPolicy}
*/
static new_with_identity_tracking(tracing_key, cred_issuer_key, reveal_map, tracking) {
_assertClass(tracing_key, AssetTracerKeyPair);
_assertClass(cred_issuer_key, CredIssuerPublicKey);
var ret = wasm.tracingpolicy_new_with_identity_tracking(tracing_key.ptr, cred_issuer_key.ptr, addHeapObject(reveal_map), tracking);
return TracingPolicy.__wrap(ret);
}
}
module.exports.TracingPolicy = TracingPolicy;
/**
* Structure that allows users to construct arbitrary transactions.
*/
class TransactionBuilder {
static __wrap(ptr) {
const obj = Object.create(TransactionBuilder.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_transactionbuilder_free(ptr);
}
/**
* Create a new transaction builder.
* @param {BigInt} seq_id - Unique sequence ID to prevent replay attacks.
* @returns {TransactionBuilder}
*/
static new(seq_id) {
uint64CvtShim[0] = seq_id;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.transactionbuilder_new(low0, high0);
return TransactionBuilder.__wrap(ret);
}
/**
* Wraps around TransactionBuilder to add an asset definition operation to a transaction builder instance.
* @example <caption> Error handling </caption>
* try {
* await wasm.add_operation_create_asset(wasm.new_keypair(), "test_memo", wasm.random_asset_type(), wasm.AssetRules.default());
* } catch (err) {
* console.log(err)
* }
*
* @param {XfrKeyPair} key_pair - Issuer XfrKeyPair.
* @param {string} memo - Text field for asset definition.
* @param {string} token_code - Optional Base64 string representing the token code of the asset to be issued.
* If empty, a token code will be chosen at random.
* @param {AssetRules} asset_rules - Asset rules object specifying which simple policies apply
* to the asset.
* @returns {TransactionBuilder}
*/
add_operation_create_asset(key_pair, memo, token_code, asset_rules) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(key_pair, XfrKeyPair);
var ptr0 = passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(token_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
_assertClass(asset_rules, AssetRules);
var ptr2 = asset_rules.ptr;
asset_rules.ptr = 0;
var ret = wasm.transactionbuilder_add_operation_create_asset(ptr, key_pair.ptr, ptr0, len0, ptr1, len1, ptr2);
return TransactionBuilder.__wrap(ret);
}
/**
* @ignore
* @returns {TransactionBuilder}
*/
add_operation_create_asset_with_policy(key_pair, memo, token_code, policy_choice, asset_rules) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(key_pair, XfrKeyPair);
var ptr0 = passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(token_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ptr2 = passStringToWasm0(policy_choice, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
_assertClass(asset_rules, AssetRules);
var ptr3 = asset_rules.ptr;
asset_rules.ptr = 0;
var ret = wasm.transactionbuilder_add_operation_create_asset_with_policy(ptr, key_pair.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3);
return TransactionBuilder.__wrap(ret);
}
/**
* @ignore
* @returns {TransactionBuilder}
*/
add_policy_option(token_code, which_check) {
var ptr = this.ptr;
this.ptr = 0;
var ptr0 = passStringToWasm0(token_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(which_check, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.transactionbuilder_add_policy_option(ptr, ptr0, len0, ptr1, len1);
return TransactionBuilder.__wrap(ret);
}
/**
* Wraps around TransactionBuilder to add an asset issuance to a transaction builder instance.
*
* Use this function for simple one-shot issuances.
*
* @param {XfrKeyPair} key_pair - Issuer XfrKeyPair.
* and types of traced assets.
* @param {string} code - base64 string representing the token code of the asset to be issued.
* @param {BigInt} seq_num - Issuance sequence number. Every subsequent issuance of a given asset type must have a higher sequence number than before.
* @param {BigInt} amount - Amount to be issued.
* @param {boolean} conf_amount - `true` means the asset amount is confidential, and `false` means it's nonconfidential.
* @param {PublicParams} zei_params - Public parameters necessary to generate asset records.
* @returns {TransactionBuilder}
*/
add_basic_issue_asset(key_pair, code, seq_num, amount, conf_amount, zei_params) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(key_pair, XfrKeyPair);
var ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
uint64CvtShim[0] = seq_num;
const low1 = u32CvtShim[0];
const high1 = u32CvtShim[1];
uint64CvtShim[0] = amount;
const low2 = u32CvtShim[0];
const high2 = u32CvtShim[1];
_assertClass(zei_params, PublicParams);
var ret = wasm.transactionbuilder_add_basic_issue_asset(ptr, key_pair.ptr, ptr0, len0, low1, high1, low2, high2, conf_amount, zei_params.ptr);
return TransactionBuilder.__wrap(ret);
}
/**
* Adds an operation to the transaction builder that appends a credential commitment to the address
* identity registry.
* @param {XfrKeyPair} key_pair - Ledger key that is tied to the credential.
* @param {CredUserPublicKey} user_public_key - Public key of the credential user.
* @param {CredIssuerPublicKey} issuer_public_key - Public key of the credential issuer.
* @param {CredentialCommitment} commitment - Credential commitment to add to the address identity registry.
* @param {CredPoK} pok- Proof that the credential commitment is valid.
* @see {@link module:Findora-Wasm.wasm_credential_commit|wasm_credential_commit} for information about how to generate a credential
* commitment.
* @returns {TransactionBuilder}
*/
add_operation_air_assign(key_pair, user_public_key, issuer_public_key, commitment, pok) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(key_pair, XfrKeyPair);
_assertClass(user_public_key, CredUserPublicKey);
_assertClass(issuer_public_key, CredIssuerPublicKey);
_assertClass(commitment, CredentialCommitment);
_assertClass(pok, CredentialPoK);
var ret = wasm.transactionbuilder_add_operation_air_assign(ptr, key_pair.ptr, user_public_key.ptr, issuer_public_key.ptr, commitment.ptr, pok.ptr);
return TransactionBuilder.__wrap(ret);
}
/**
* Adds an operation to the transaction builder that removes a hash from ledger's custom data
* store.
* @param {XfrKeyPair} auth_key_pair - Key pair that is authorized to delete the hash at the
* provided key.
* @param {Key} key - The key of the custom data store whose value will be cleared if the
* transaction validates.
* @param {BigInt} seq_num - Nonce to prevent replays.
* @returns {TransactionBuilder}
*/
add_operation_kv_update_no_hash(auth_key_pair, key, seq_num) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(auth_key_pair, XfrKeyPair);
_assertClass(key, Key);
uint64CvtShim[0] = seq_num;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.transactionbuilder_add_operation_kv_update_no_hash(ptr, auth_key_pair.ptr, key.ptr, low0, high0);
return TransactionBuilder.__wrap(ret);
}
/**
* Adds an operation to the transaction builder that adds a hash to the ledger's custom data
* store.
* @param {XfrKeyPair} auth_key_pair - Key pair that is authorized to add the hash at the
* provided key.
* @param {Key} key - The key of the custom data store the value will be added to if the
* transaction validates.
* @param {KVHash} hash - The hash to add to the custom data store.
* @param {BigInt} seq_num - Nonce to prevent replays.
* @returns {TransactionBuilder}
*/
add_operation_kv_update_with_hash(auth_key_pair, key, seq_num, kv_hash) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(auth_key_pair, XfrKeyPair);
_assertClass(key, Key);
uint64CvtShim[0] = seq_num;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
_assertClass(kv_hash, KVHash);
var ret = wasm.transactionbuilder_add_operation_kv_update_with_hash(ptr, auth_key_pair.ptr, key.ptr, low0, high0, kv_hash.ptr);
return TransactionBuilder.__wrap(ret);
}
/**
* Adds an operation to the transaction builder that adds a hash to the ledger's custom data
* store.
* @param {XfrKeyPair} auth_key_pair - Asset creator key pair.
* @param {String} code - base64 string representing token code of the asset whose memo will be updated.
* transaction validates.
* @param {String} new_memo - The new asset memo.
* @see {@link module:Findora-Wasm~AssetRules#set_updatable|AssetRules.set_updatable} for more information about how
* to define an updatable asset.
* @returns {TransactionBuilder}
*/
add_operation_update_memo(auth_key_pair, code, new_memo) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(auth_key_pair, XfrKeyPair);
var ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(new_memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.transactionbuilder_add_operation_update_memo(ptr, auth_key_pair.ptr, ptr0, len0, ptr1, len1);
return TransactionBuilder.__wrap(ret);
}
/**
* Adds a serialized transfer asset operation to a transaction builder instance.
* @param {string} op - a JSON-serialized transfer operation.
* @see {@link module:Findora-Wasm~TransferOperationBuilder} for details on constructing a transfer operation.
* @throws Will throw an error if `op` fails to deserialize.
* @returns {TransactionBuilder}
*/
add_transfer_operation(op) {
var ptr = this.ptr;
this.ptr = 0;
var ptr0 = passStringToWasm0(op, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.transactionbuilder_add_transfer_operation(ptr, ptr0, len0);
return TransactionBuilder.__wrap(ret);
}
/**
* @returns {TransactionBuilder}
*/
sign(kp) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(kp, XfrKeyPair);
var ret = wasm.transactionbuilder_sign(ptr, kp.ptr);
return TransactionBuilder.__wrap(ret);
}
/**
* Extracts the serialized form of a transaction.
* @returns {string}
*/
transaction() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.transactionbuilder_transaction(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Fetches a client record from a transaction.
* @param {number} idx - Record to fetch. Records are added to the transaction builder sequentially.
* @returns {ClientAssetRecord}
*/
get_owner_record(idx) {
var ret = wasm.transactionbuilder_get_owner_record(this.ptr, idx);
return ClientAssetRecord.__wrap(ret);
}
/**
* Fetches an owner memo from a transaction
* @param {number} idx - Owner memo to fetch. Owner memos are added to the transaction builder sequentially.
* @returns {OwnerMemo | undefined}
*/
get_owner_memo(idx) {
var ret = wasm.transactionbuilder_get_owner_memo(this.ptr, idx);
return ret === 0 ? undefined : OwnerMemo.__wrap(ret);
}
}
module.exports.TransactionBuilder = TransactionBuilder;
/**
* Structure that enables clients to construct complex transfers.
*/
class TransferOperationBuilder {
static __wrap(ptr) {
const obj = Object.create(TransferOperationBuilder.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_transferoperationbuilder_free(ptr);
}
/**
* Create a new transfer operation builder.
* @returns {TransferOperationBuilder}
*/
static new() {
var ret = wasm.transferoperationbuilder_new();
return TransferOperationBuilder.__wrap(ret);
}
/**
* @ignore
* @returns {string}
*/
debug() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.transferoperationbuilder_debug(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Wraps around TransferOperationBuilder to add an input to a transfer operation builder.
* @param {TxoRef} txo_ref - Absolute or relative utxo reference
* @param {string} asset_record - Serialized client asset record to serve as transfer input. This record must exist on the
* ledger for the transfer to be valid.
* @param {OwnerMemo} owner_memo - Opening parameters.
* @param tracing_key {AssetTracerKeyPair} - Tracing key, must be added to traceable
* assets.
* @param {XfrKeyPair} key - Key pair associated with the input.
* @param {BigInt} amount - Amount of input record to transfer.
* @see {@link module:Findora-Wasm~TxoRef#create_absolute_txo_ref|TxoRef.create_absolute_txo_ref}
* or {@link module:Findora-Wasm~TxoRef#create_relative_txo_ref|TxoRef.create_relative_txo_ref} for details on txo
* references.
* @see {@link module:Findora-Network~Network#getUtxo|Network.getUtxo} for details on fetching blind asset records.
* @throws Will throw an error if `oar` or `txo_ref` fail to deserialize.
* @param {OwnerMemo | undefined} owner_memo
* @returns {TransferOperationBuilder}
*/
add_input_with_tracking(txo_ref, asset_record, owner_memo, tracing_policies, key, amount) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(txo_ref, TxoRef);
var ptr0 = txo_ref.ptr;
txo_ref.ptr = 0;
_assertClass(asset_record, ClientAssetRecord);
var ptr1 = asset_record.ptr;
asset_record.ptr = 0;
let ptr2 = 0;
if (!isLikeNone(owner_memo)) {
_assertClass(owner_memo, OwnerMemo);
ptr2 = owner_memo.ptr;
owner_memo.ptr = 0;
}
_assertClass(tracing_policies, TracingPolicies);
_assertClass(key, XfrKeyPair);
uint64CvtShim[0] = amount;
const low3 = u32CvtShim[0];
const high3 = u32CvtShim[1];
var ret = wasm.transferoperationbuilder_add_input_with_tracking(ptr, ptr0, ptr1, ptr2, tracing_policies.ptr, key.ptr, low3, high3);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to add an input to a transfer operation builder.
* @param {TxoRef} txo_ref - Absolute or relative utxo reference
* @param {string} asset_record - Serialized client asset record to serve as transfer input. This record must exist on the
* ledger for the transfer to be valid
* @param {OwnerMemo} owner_memo - Opening parameters.
* @param {XfrKeyPair} key - Key pair associated with the input.
* @param {BigInt} amount - Amount of input record to transfer
* or {@link module:Findora-Wasm~TxoRef#create_relative_txo_ref|TxoRef.create_relative_txo_ref} for details on txo
* references.
* @see {@link module:Findora-Network~Network#getUtxo|Network.getUtxo} for details on fetching blind asset records.
* @throws Will throw an error if `oar` or `txo_ref` fail to deserialize.
* @param {OwnerMemo | undefined} owner_memo
* @returns {TransferOperationBuilder}
*/
add_input_no_tracking(txo_ref, asset_record, owner_memo, key, amount) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(txo_ref, TxoRef);
var ptr0 = txo_ref.ptr;
txo_ref.ptr = 0;
_assertClass(asset_record, ClientAssetRecord);
var ptr1 = asset_record.ptr;
asset_record.ptr = 0;
let ptr2 = 0;
if (!isLikeNone(owner_memo)) {
_assertClass(owner_memo, OwnerMemo);
ptr2 = owner_memo.ptr;
owner_memo.ptr = 0;
}
_assertClass(key, XfrKeyPair);
uint64CvtShim[0] = amount;
const low3 = u32CvtShim[0];
const high3 = u32CvtShim[1];
var ret = wasm.transferoperationbuilder_add_input_no_tracking(ptr, ptr0, ptr1, ptr2, key.ptr, low3, high3);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to add an output to a transfer operation builder.
*
* @param {BigInt} amount - amount to transfer to the recipient.
* @param {XfrPublicKey} recipient - public key of the recipient.
* @param tracing_key {AssetTracerKeyPair} - Optional tracing key, must be added to traced
* assets.
* @param code {string} - String representation of the asset token code.
* @param conf_amount {boolean} - `true` means the output's asset amount is confidential, and `false` means it's nonconfidential.
* @param conf_type {boolean} - `true` means the output's asset type is confidential, and `false` means it's nonconfidential.
* @throws Will throw an error if `code` fails to deserialize.
* @returns {TransferOperationBuilder}
*/
add_output_with_tracking(amount, recipient, tracing_policies, code, conf_amount, conf_type) {
var ptr = this.ptr;
this.ptr = 0;
uint64CvtShim[0] = amount;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
_assertClass(recipient, XfrPublicKey);
_assertClass(tracing_policies, TracingPolicies);
var ptr1 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.transferoperationbuilder_add_output_with_tracking(ptr, low0, high0, recipient.ptr, tracing_policies.ptr, ptr1, len1, conf_amount, conf_type);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to add an output to a transfer operation builder.
*
* @param {BigInt} amount - amount to transfer to the recipient
* @param {XfrPublicKey} recipient - public key of the recipient
* @param code {string} - String representaiton of the asset token code
* @param conf_amount {boolean} - `true` means the output's asset amount is confidential, and `false` means it's nonconfidential.
* @param conf_type {boolean} - `true` means the output's asset type is confidential, and `false` means it's nonconfidential.
* @throws Will throw an error if `code` fails to deserialize.
* @returns {TransferOperationBuilder}
*/
add_output_no_tracking(amount, recipient, code, conf_amount, conf_type) {
var ptr = this.ptr;
this.ptr = 0;
uint64CvtShim[0] = amount;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
_assertClass(recipient, XfrPublicKey);
var ptr1 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.transferoperationbuilder_add_output_no_tracking(ptr, low0, high0, recipient.ptr, ptr1, len1, conf_amount, conf_type);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to ensure the transfer inputs and outputs are balanced.
* This function will add change outputs for all unspent portions of input records.
* @throws Will throw an error if the transaction cannot be balanced.
* @returns {TransferOperationBuilder}
*/
balance() {
var ptr = this.ptr;
this.ptr = 0;
var ret = wasm.transferoperationbuilder_balance(ptr);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to finalize the transaction.
*
* @throws Will throw an error if input and output amounts do not add up.
* @throws Will throw an error if not all record owners have signed the transaction.
* @returns {TransferOperationBuilder}
*/
create() {
var ptr = this.ptr;
this.ptr = 0;
var ret = wasm.transferoperationbuilder_create(ptr);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Wraps around TransferOperationBuilder to add a signature to the operation.
*
* All input owners must sign.
*
* @param {XfrKeyPair} kp - key pair of one of the input owners.
* @returns {TransferOperationBuilder}
*/
sign(kp) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(kp, XfrKeyPair);
var ret = wasm.transferoperationbuilder_sign(ptr, kp.ptr);
return TransferOperationBuilder.__wrap(ret);
}
/**
* Co-sign an input index
* @param {XfrKeyPair} kp - Co-signature key.
* @params {Number} input_idx - Input index to apply co-signature to.
* @returns {TransferOperationBuilder}
*/
add_cosignature(kp, input_idx) {
var ptr = this.ptr;
this.ptr = 0;
_assertClass(kp, XfrKeyPair);
var ret = wasm.transferoperationbuilder_add_cosignature(ptr, kp.ptr, input_idx);
return TransferOperationBuilder.__wrap(ret);
}
/**
* @returns {string}
*/
builder() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.transferoperationbuilder_builder(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Wraps around TransferOperationBuilder to extract an operation expression as JSON.
* @returns {string}
*/
transaction() {
try {
const retptr = wasm.__wbindgen_export_2.value - 16;
wasm.__wbindgen_export_2.value = retptr;
wasm.transferoperationbuilder_transaction(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_export_2.value += 16;
wasm.__wbindgen_free(r0, r1);
}
}
}
module.exports.TransferOperationBuilder = TransferOperationBuilder;
/**
* Indicates whether the TXO ref is an absolute or relative value.
*/
class TxoRef {
static __wrap(ptr) {
const obj = Object.create(TxoRef.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_txoref_free(ptr);
}
/**
* Creates a relative txo reference as a JSON string. Relative txo references are offset
* backwards from the operation they appear in -- 0 is the most recent, (n-1) is the first output
* of the transaction.
*
* Use relative txo indexing when referring to outputs of intermediate operations (e.g. a
* transaction containing both an issuance and a transfer).
*
* # Arguments
* @param {BigInt} idx - Relative TXO (transaction output) SID.
* @returns {TxoRef}
*/
static relative(idx) {
uint64CvtShim[0] = idx;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.txoref_relative(low0, high0);
return TxoRef.__wrap(ret);
}
/**
* Creates an absolute transaction reference as a JSON string.
*
* Use absolute txo indexing when referring to an output that has been assigned a utxo index (i.e.
* when the utxo has been committed to the ledger in an earlier transaction).
*
* # Arguments
* @param {BigInt} idx - Txo (transaction output) SID.
* @returns {TxoRef}
*/
static absolute(idx) {
uint64CvtShim[0] = idx;
const low0 = u32CvtShim[0];
const high0 = u32CvtShim[1];
var ret = wasm.txoref_absolute(low0, high0);
return TxoRef.__wrap(ret);
}
}
module.exports.TxoRef = TxoRef;
/**
*/
class XfrKeyPair {
static __wrap(ptr) {
const obj = Object.create(XfrKeyPair.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_xfrkeypair_free(ptr);
}
/**
* @returns {XfrPublicKey}
*/
get_pk() {
var ret = wasm.xfrkeypair_get_pk(this.ptr);
return XfrPublicKey.__wrap(ret);
}
}
module.exports.XfrKeyPair = XfrKeyPair;
/**
*/
class XfrPublicKey {
static __wrap(ptr) {
const obj = Object.create(XfrPublicKey.prototype);
obj.ptr = ptr;
return obj;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
wasm.__wbg_xfrpublickey_free(ptr);
}
}
module.exports.XfrPublicKey = XfrPublicKey;
module.exports.__wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
module.exports.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
module.exports.__wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
module.exports.__wbindgen_json_serialize = function(arg0, arg1) {
const obj = getObject(arg1);
var ret = JSON.stringify(obj === undefined ? null : obj);
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
module.exports.__wbg_getRandomValues_3ac1b33c90b52596 = function(arg0, arg1, arg2) {
getObject(arg0).getRandomValues(getArrayU8FromWasm0(arg1, arg2));
};
module.exports.__wbg_randomFillSync_6f956029658662ec = function(arg0, arg1, arg2) {
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
};
module.exports.__wbg_self_1c83eb4471d9eb9b = handleError(function() {
var ret = self.self;
return addHeapObject(ret);
});
module.exports.__wbg_static_accessor_MODULE_abf5ae284bffdf45 = function() {
var ret = module;
return addHeapObject(ret);
};
module.exports.__wbg_require_5b2b5b594d809d9f = function(arg0, arg1, arg2) {
var ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
module.exports.__wbg_crypto_c12f14e810edcaa2 = function(arg0) {
var ret = getObject(arg0).crypto;
return addHeapObject(ret);
};
module.exports.__wbg_msCrypto_679be765111ba775 = function(arg0) {
var ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};
module.exports.__wbindgen_is_undefined = function(arg0) {
var ret = getObject(arg0) === undefined;
return ret;
};
module.exports.__wbg_getRandomValues_05a60bf171bfc2be = function(arg0) {
var ret = getObject(arg0).getRandomValues;
return addHeapObject(ret);
};
module.exports.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
const path = require('path').join(__dirname, 'wasm_bg.wasm');
const bytes = require('fs').readFileSync(path);
const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
wasm = wasmInstance.exports;
module.exports.__wasm = wasm;
Source