From bc3d2a0b0cc912cd6b3d80d4c0221270f3ac4e39 Mon Sep 17 00:00:00 2001 From: Lucas Santos Date: Tue, 5 Nov 2024 19:06:26 -0300 Subject: [PATCH] chore: remove all read/write spt methods --- .../src/transactions/syscoin.ts | 597 +----------------- packages/sysweb3-keyring/src/types.ts | 30 +- packages/sysweb3-keyring/test/sys.spec.ts | 94 +-- packages/sysweb3-utils/src/syscoints/index.ts | 217 +------ 4 files changed, 13 insertions(+), 925 deletions(-) diff --git a/packages/sysweb3-keyring/src/transactions/syscoin.ts b/packages/sysweb3-keyring/src/transactions/syscoin.ts index 11f7fd66..ac8327ef 100644 --- a/packages/sysweb3-keyring/src/transactions/syscoin.ts +++ b/packages/sysweb3-keyring/src/transactions/syscoin.ts @@ -14,11 +14,9 @@ import { import { INetwork } from '@pollum-io/sysweb3-network'; import { sys, - INewNFT, isBase64, repairBase64, ITokenSend, - ITokenUpdate, ITxid, txUtils, getAsset, @@ -35,7 +33,7 @@ type EstimateFeeParams = { export class SyscoinTransactions implements ISyscoinTransactions { //TODO: test and validate for general UTXO chains which will be the working methods, for now we just allow contentScripts for syscoin Chains - private getNetwork: () => INetwork; + public getNetwork: () => INetwork; private getSigner: () => { hd: SyscoinHDSigner; main: any; @@ -58,6 +56,7 @@ export class SyscoinTransactions implements ISyscoinTransactions { isChangeAddress: boolean, index: number ) => Promise; + constructor( getNetwork: () => INetwork, getSyscoinSigner: () => { @@ -185,555 +184,6 @@ export class SyscoinTransactions implements ISyscoinTransactions { }; }; - public createMintedToken = async ({ - txid, - guid, - initialSupply, - precision, - receivingAddress, - fee, - }: { - txid: string; - guid: string; - initialSupply: number; - precision: number; - receivingAddress: string; - fee: number; - }) => { - const network = this.getNetwork(); - - const { hd, main } = this.getSigner(); - - return await new Promise((resolve: any, reject: any) => { - const interval = setInterval(async () => { - const { getRawTransaction, getFeeRate, getTokenMap } = - this.txUtilsFunctions(); - const createdTokenTransaction = await getRawTransaction( - network.url, - txid - ); - - if ( - createdTokenTransaction && - createdTokenTransaction.confirmations > 1 - ) { - const changeAddress = await hd.getNewChangeAddress(true, 84); - - try { - const tokenMap = getTokenMap({ - guid, - changeAddress, - amount: new sys.utils.BN(initialSupply * 10 ** precision) as any, - receivingAddress, - }); - const txOptions = { rbf: true }; - - const pendingTransaction = await main.assetSend( - txOptions, - tokenMap, - receivingAddress, - getFeeRate(fee) - ); - - if (!pendingTransaction) { - throw new Error( - 'Bad Request: Could not create transaction. Invalid or incorrect data provided.' - ); - } - - const txid = pendingTransaction.extractTransaction().getId(); - - resolve({ - createdTokenTransaction, - txid, - confirmations: createdTokenTransaction.confirmations, - guid, - }); - } catch (error) { - clearInterval(interval); - - reject(error); - } - } - }, 16000); - }); - }; - - public transferAssetOwnership = async (transaction: any): Promise => { - const { hd, main } = this.getSigner(); - const { fee, assetGuid, newOwner } = transaction; - - const feeRate = new sys.utils.BN(fee * 1e8); - const txOpts = { rbf: true }; - const assetOpts = {}; - - const assetMap = new Map([ - [ - assetGuid, - { - changeAddress: await hd.getNewChangeAddress(true, 84), - outputs: [ - { - value: new sys.utils.BN(0), - address: newOwner, - }, - ], - }, - ], - ]); - - const pendingTx = await main.assetUpdate( - assetGuid, - assetOpts, - txOpts, - assetMap, - null, - feeRate - ); - - if (!pendingTx) { - console.error('Could not create transaction, not enough funds?'); - } - - const txid = pendingTx.extractTransaction().getId(); - - return { txid }; - }; - - // todo: create temp tx type new token - public getTokenUpdateOptions = (temporaryTransaction: any) => { - const { main } = this.getSigner(); - - const { - capabilityflags, - contract, - description, - notarydetails, - auxfeedetails, - notaryAddress, - payoutAddress, - } = temporaryTransaction; - - let tokenOptions = { - description, - updatecapabilityflags: capabilityflags ? String(capabilityflags) : '127', - notarydetails, - auxfeedetails, - notarykeyid: Buffer.from('', 'hex'), - contract: contract ? Buffer.from(contract, 'hex') : null, - }; - - if (notaryAddress) { - const notaryPayment = sys.utils.bitcoinjs.payments.p2wpkh({ - address: notaryAddress, - network: main.network, - }) as any; - - tokenOptions = { - ...tokenOptions, - notarydetails: { - ...notarydetails, - endpoint: Buffer.from( - syscointx.utils.encodeToBase64(notarydetails.endpoint) - ), - }, - notarykeyid: Buffer.from(notaryPayment.hash.toString('hex'), 'hex'), - }; - } - - if (payoutAddress) { - const payment = sys.utils.bitcoinjs.payments.p2wpkh({ - address: payoutAddress, - network: main.network, - }) as any; - - const auxFeeKeyID = Buffer.from(payment.hash.toString('hex'), 'hex'); - - tokenOptions = { - ...tokenOptions, - auxfeedetails: { - ...tokenOptions.auxfeedetails, - auxfeekeyid: auxFeeKeyID, - }, - }; - } - - return tokenOptions; - }; - - // todo: create temp tx type new token - public getTokenCreationOptions = (temporaryTransaction: any) => { - const { main } = this.getSigner(); - - const { - capabilityflags, - notarydetails, - auxfeedetails, - precision, - symbol, - description, - maxsupply, - notaryAddress, - payoutAddress, - } = temporaryTransaction; - - const newMaxSupply = maxsupply * 10 ** precision; - - let tokenOptions = { - precision, - symbol, - description, - maxsupply: new sys.utils.BN(newMaxSupply), - updatecapabilityflags: capabilityflags ? String(capabilityflags) : '127', - notarydetails, - auxfeedetails, - notarykeyid: Buffer.from('', 'hex'), - }; - - if (notaryAddress) { - const notaryPayment = sys.utils.bitcoinjs.payments.p2wpkh({ - address: notaryAddress, - network: main.network, - }) as any; - - tokenOptions = { - ...tokenOptions, - notarydetails: { - ...notarydetails, - endpoint: Buffer.from( - syscointx.utils.encodeToBase64(notarydetails.endpoint) - ), - }, - notarykeyid: Buffer.from(notaryPayment.hash.toString('hex'), 'hex'), - }; - } - - if (payoutAddress) { - const payment = sys.utils.bitcoinjs.payments.p2wpkh({ - address: payoutAddress, - network: main.network, - }) as any; - - const auxFeeKeyID = Buffer.from(payment.hash.toString('hex'), 'hex'); - - tokenOptions = { - ...tokenOptions, - auxfeedetails: { - ...tokenOptions.auxfeedetails, - auxfeekeyid: auxFeeKeyID, - }, - }; - } - - return tokenOptions; - }; - confirmTokenCreation = async ( - // todo: type - temporaryTransaction: any - ): Promise<{ - transactionData: any; - txid: string; - confirmations: number; - guid: string; - }> => { - const { hd, main } = this.getSigner(); - const { getRawTransaction } = this.txUtilsFunctions(); - - const { precision, initialSupply, maxsupply, fee, receiver } = - temporaryTransaction; - - const amount = maxsupply * 10 ** precision; - - const tokenOptions = this.getTokenCreationOptions(temporaryTransaction); - const txOptions = { rbf: true }; - - const newChangeAddress = await hd.getNewChangeAddress(true, 84); - const newFee = new sys.utils.BN(fee * 1e8); - - const pendingTransaction = await main.assetNew( - tokenOptions, - txOptions, - newChangeAddress, - receiver, - newFee - ); - - const txid = pendingTransaction.extractTransaction().getId(); - const transactionData = await getRawTransaction(main.blockbookURL, txid); - const assets = syscointx.getAssetsFromTx( - pendingTransaction.extractTransaction() - ); - const createdTokenGuid = assets.keys().next().value; - - if (initialSupply && initialSupply < amount) { - this.createMintedToken({ - txid, - guid: createdTokenGuid, - initialSupply, - precision, - receivingAddress: receiver, - fee, - }); - } - - return { - transactionData, - txid, - confirmations: transactionData.confirmations, - guid: createdTokenGuid, - }; - }; - - public confirmTokenMint = async (temporaryTransaction: any): Promise => { - const { getTokenMap } = this.txUtilsFunctions(); - const { main } = this.getSigner(); - - const { fee, assetGuid, amount, receivingAddress } = temporaryTransaction; - - const feeRate = new sys.utils.BN(fee * 1e8); - - const token = await getAsset(main.blockbookURL, assetGuid); - - if (!token) - throw new Error( - 'Bad Request: Could not create transaction. Token not found.' - ); - - const txOptions = { rbf: true }; - - const tokenMap = getTokenMap({ - guid: assetGuid, - changeAddress: '', - amount: new sys.utils.BN(amount * 10 ** token.decimals) as any, - receivingAddress, - }); - - try { - const pendingTransaction = await main.assetSend( - txOptions, - tokenMap, - null, - feeRate - ); - - if (!pendingTransaction) { - throw new Error( - 'Bad Request: Could not create transaction. Invalid or incorrect data provided.' - ); - } - - const txid = pendingTransaction.extractTransaction().getId(); - - return { txid }; - } catch (error) { - throw new Error('Bad Request: Could not create transaction.'); - } - }; - - public createParentToken = async ({ - tokenOptions, - feeRate, - }: { - tokenOptions: { - precision: number; - symbol: string; - maxsupply: number; - description: string; - }; - feeRate: number; - }) => { - const { hd, main } = this.getSigner(); - - const tokenChangeAddress = await hd.getNewChangeAddress(true, 84); - const txOptions = { rbf: true }; - - const pendingTransaction = await main.assetNew( - tokenOptions, - txOptions, - tokenChangeAddress, - tokenChangeAddress, - feeRate - ); - - if (!pendingTransaction) { - throw new Error( - 'Bad Request: Could not create transaction. Invalid or incorrect data provided.' - ); - } - - const tokensFromTransaction = syscointx.getAssetsFromTx( - pendingTransaction.extractTransaction() - ); - const txid = pendingTransaction.extractTransaction().getId(); - - return { - guid: tokensFromTransaction.keys().next().value, - txid, - }; - }; - - public nftCreationStep3 = async ( - tx: INewNFT, - guid: string - ): Promise => { - const { main } = this.getSigner(); - const { getRawTransaction, getTokenMap } = this.txUtilsFunctions(); - - const { receivingAddress } = tx; - - const feeRate = new sys.utils.BN(10); - const tokenOptions = { updatecapabilityflags: '0' }; - const txOptions = { rbf: true }; - - const tokenMap = getTokenMap({ - guid, - changeAddress: '', - amount: new sys.utils.BN(0) as any, - receivingAddress, - }); - - const pendingTransaction = await main.assetUpdate( - guid, - tokenOptions, - txOptions, - tokenMap, - receivingAddress, - feeRate - ); - - if (!pendingTransaction) { - throw new Error( - 'Bad Request: Could not update minted token. Invalid or incorrect data provided.' - ); - } - - const txid = pendingTransaction.extractTransaction().getId(); - - return await new Promise((resolve, reject) => { - const interval = setInterval(async () => { - try { - const updateTx = await getRawTransaction(main.blockbookURL, txid); - - if (updateTx.confirmations <= 0) return; - - clearInterval(interval); - - return resolve({ txid }); - } catch (error) { - reject(error); - } - }, 16000); - }); - }; - - public nftCreationStep2 = async ( - tx: INewNFT, - guid: string - ): Promise => { - const { main } = this.getSigner(); - const { getRawTransaction, getTokenMap } = this.txUtilsFunctions(); - - const { receivingAddress, precision, fee } = tx; - - const feeRate = new sys.utils.BN(fee * 1e8); - - const tokenMap = getTokenMap({ - guid, - changeAddress: '', - amount: new sys.utils.BN(1 * 10 ** precision) as any, - receivingAddress, - }); - - const txOptions = { rbf: true }; - const pendingTransaction = await main.assetSend( - txOptions, - tokenMap, - null, - feeRate - ); - - if (!pendingTransaction) { - throw new Error( - `Bad Request: Could not mint token ${guid}. Invalid or incorrect data provided.` - ); - } - - const txid = pendingTransaction.extractTransaction().getId(); - - return await new Promise((resolve, reject) => { - const interval = setInterval(async () => { - try { - const mintTx = await getRawTransaction(main.blockbookURL, txid); - - if (mintTx.confirmations <= 0) return; - - clearInterval(interval); - - return resolve({ txid }); - } catch (error) { - reject(error); - } - }, 16000); - }); - }; - - public nftCreationStep1 = async ( - tx: INewNFT - ): Promise<{ parent: { guid: string; txid: string } }> => { - const { main } = this.getSigner(); - const { getRawTransaction } = this.txUtilsFunctions(); - - const { fee, symbol, description, precision } = tx; - - const feeRate = new sys.utils.BN(fee * 1e8) as any; - - const tokenOptions = { - precision, - symbol, - maxsupply: new sys.utils.BN(1 * 10 ** precision), - description, - } as any; - - const parentToken = await this.createParentToken({ tokenOptions, feeRate }); - - return await new Promise((resolve, reject) => { - const interval = setInterval(async () => { - try { - const creationTx = await getRawTransaction( - main.blockbookURL, - parentToken.txid - ); - - if (creationTx.confirmations <= 0) return; - - clearInterval(interval); - - return resolve({ parent: parentToken }); - } catch (error) { - reject(error); - } - }, 16000); - }); - }; - - confirmNftCreation = (tx: any) => { - if (tx) { - // create token - this.nftCreationStep1(tx).then((createRes) => { - const { - parent: { guid }, - } = createRes; - // mint token - this.nftCreationStep2(tx, guid).then(() => { - // update token - this.nftCreationStep3(tx, guid); - }); - }); - return { success: true }; - } - return { success: false }; - }; - public signPSBT = async ({ psbt, signer, @@ -810,49 +260,6 @@ export class SyscoinTransactions implements ISyscoinTransactions { } }; - public confirmUpdateToken = async ( - temporaryTransaction: ITokenUpdate - ): Promise => { - const { hd, main } = this.getSigner(); //TODO: remove hd as its defined inside main - const { getTokenMap } = this.txUtilsFunctions(); - - const { fee, assetGuid, assetWhiteList } = temporaryTransaction; - - const txOptions = { rbf: true, assetWhiteList }; - - try { - const tokenMap = getTokenMap({ - guid: assetGuid, - changeAddress: await hd.getNewChangeAddress(true, 84), - amount: new sys.utils.BN(0) as any, - receivingAddress: await hd.getNewReceivingAddress(true, 84), - }); - - const tokenOptions = this.getTokenUpdateOptions(temporaryTransaction); - - const pendingTransaction = await main.assetUpdate( - assetGuid, - tokenOptions, - txOptions, - tokenMap, - null, - new sys.utils.BN(fee * 1e8) - ); - - const txid = pendingTransaction.extractTransaction().getId(); - - if (!pendingTransaction || !txid) { - throw new Error( - 'Bad Request: Could not create transaction. Invalid or incorrect data provided.' - ); - } - - return { txid }; - } catch (error) { - throw new Error('Bad Request: Could not create transaction.'); - } - }; - public confirmCustomTokenSend = async ( temporaryTransaction: ITokenSend ): Promise => { diff --git a/packages/sysweb3-keyring/src/types.ts b/packages/sysweb3-keyring/src/types.ts index 7683337b..68145963 100644 --- a/packages/sysweb3-keyring/src/types.ts +++ b/packages/sysweb3-keyring/src/types.ts @@ -12,16 +12,7 @@ import { import { LedgerKeyring } from './ledger'; import { TrezorKeyring } from './trezor'; import { INetwork, INetworkType } from '@pollum-io/sysweb3-network'; -import { - ITokenMint, - ITokenSend, - ITokenUpdate, - ITxid, -} from '@pollum-io/sysweb3-utils'; - -export interface ITrezorWallet { - createHardwareWallet: () => Promise; -} +import { ITokenSend, ITxid } from '@pollum-io/sysweb3-utils'; export interface ISendTransaction { sender: string; @@ -31,6 +22,7 @@ export interface ISendTransaction { gasPrice?: number; token?: any; } + export type SimpleTransactionRequest = { to: string; from: string; @@ -154,16 +146,6 @@ export interface ISyscoinTransactions { amount: number; receivingAddress: string; }) => Promise; - confirmNftCreation: (tx: any) => { success: boolean }; - confirmTokenMint: (transaction: ITokenMint) => Promise; - confirmTokenCreation: (transaction: any) => Promise<{ - transactionData: any; - txid: string; - confirmations: number; - guid: string; - }>; - transferAssetOwnership: (transaction: any) => Promise; - confirmUpdateToken: (transaction: ITokenUpdate) => Promise; getRecommendedFee: (explorerUrl: string) => Promise; sendTransaction: ( transaction: ITokenSend, @@ -187,11 +169,13 @@ export interface IKeyringManager { ) => Omit; getAccountXpub: () => string; getEncryptedXprv: () => string; + importTrezorAccount( coin: string, slip44: string, index: string ): Promise; + getNetwork: () => INetwork; getPrivateKeyByAccountId: ( id: number, @@ -254,12 +238,6 @@ export enum KeyringAccountType { Ledger = 'Ledger', } -export type IKeyringDApp = { - id: number; - url: string; - active: boolean; -}; - export type accountType = { [id: number]: IKeyringAccountState; }; diff --git a/packages/sysweb3-keyring/test/sys.spec.ts b/packages/sysweb3-keyring/test/sys.spec.ts index e1c049e7..212d7b55 100644 --- a/packages/sysweb3-keyring/test/sys.spec.ts +++ b/packages/sysweb3-keyring/test/sys.spec.ts @@ -1,5 +1,3 @@ -import { KeyringManager } from '../src/keyring-manager'; -import { KeyringAccountType } from '../src/types'; import { CREATE_TOKEN_PARAMS, DATA, @@ -7,6 +5,8 @@ import { PEACE_SEED_PHRASE, SYS_TANENBAUM_UTXO_NETWORK, } from './constants'; +import { KeyringManager } from '../src/keyring-manager'; +import { KeyringAccountType } from '../src/types'; const sjs = require('syscoinjs-lib'); @@ -60,14 +60,6 @@ describe('testing functions for the new-sys txs', () => { expect(wrong).toBe(false); }); - it('should overwrite current seed', () => { - keyringManager.isSeedValid(String(PEACE_SEED_PHRASE)); - const seed = keyringManager.getSeed(FAKE_PASSWORD) as string; - // expect to have 12 words - expect(seed).toBeDefined(); - expect(seed.split(' ').length).toBe(12); - }); - //* createKeyringVault it('should create the keyring vault', async () => { const account = await keyringManager.createKeyringVault(); @@ -76,71 +68,11 @@ describe('testing functions for the new-sys txs', () => { expect(account).toBeDefined(); }); - /* addNewAccount */ - it('should add a new account', async () => { - const account2 = await keyringManager.addNewAccount(undefined); - expect(account2.label).toBe('Account 2'); - - const wallet = keyringManager.getState(); - expect(wallet.activeAccountId).toBe(1); - }); - //--------------------------------------------------------SyscoinTransactions Tests---------------------------------------------------- - it('should create SPT tx', async () => { - // Initializing wallet and setting seed, password and vault. - await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, - 'syscoin' - ); - const wallet = keyringManager.getState(); - expect(wallet.activeAccountId).toBe(1); - const activeUTXOAccount = keyringManager.getActiveUTXOAccountState(); - address = activeUTXOAccount.address; - - const { txid } = - await keyringManager.syscoinTransaction.confirmTokenCreation({ - ...CREATE_TOKEN_PARAMS, - receiver: address, - }); - - // This test only run individually. - - expect(typeof txid).toBe('string'); - }, 180000); - - it('should create NFT token', async () => { - await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, - 'syscoin' - ); - - const tx = { ...DATA['createNft'], issuer: address }; - - const { success } = - keyringManager.syscoinTransaction.confirmNftCreation(tx); - - expect(success).toBeTruthy(); - }, 180000); - - it('should send native token', async () => { - await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, - 'syscoin' - ); - - const tx = { ...DATA['send'], receivingAddress: address, sender: address }; - const { txid } = await keyringManager.syscoinTransaction.sendTransaction( - tx - ); - - // This test only run individually. - - expect(txid).toBeDefined(); - }, 180000); it('should generate signPSBT json', async () => { await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, + SYS_TANENBAUM_UTXO_NETWORK as any, 'syscoin' ); const res = await keyringManager.syscoinTransaction.signTransaction( @@ -153,7 +85,7 @@ describe('testing functions for the new-sys txs', () => { it('should sign and send tx', async () => { await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, + SYS_TANENBAUM_UTXO_NETWORK as any, 'syscoin' ); const feeRate = new sjs.utils.BN(10); @@ -187,24 +119,6 @@ describe('testing functions for the new-sys txs', () => { expect(res).toBeDefined(); }, 180000); - it('should confirm update token', async () => { - await keyringManager.setSignerNetwork( - SYS_TANENBAUM_UTXO_NETWORK, - 'syscoin' - ); - keyringManager.setActiveAccount(0, KeyringAccountType.HDAccount); - const activeUTXOAccount = keyringManager.getActiveUTXOAccountState(); - address = activeUTXOAccount.address; - const tx = { ...DATA['updateToken'], receiver: address }; - const { txid } = await keyringManager.syscoinTransaction.confirmUpdateToken( - tx - ); - - // If the asset isn't minted, the test will fail. - - expect(txid).toBeDefined(); - }, 180000); - it('should get recommended fee', async () => { const { explorer } = SYS_TANENBAUM_UTXO_NETWORK; const fee = await keyringManager.syscoinTransaction.getRecommendedFee( diff --git a/packages/sysweb3-utils/src/syscoints/index.ts b/packages/sysweb3-utils/src/syscoints/index.ts index 9f1c5460..ff2b85e3 100644 --- a/packages/sysweb3-utils/src/syscoints/index.ts +++ b/packages/sysweb3-utils/src/syscoints/index.ts @@ -7,6 +7,7 @@ export class Syscoin { public Signer; public blockbookURL; public network; + constructor(SignerIn: any, blockbookURL: string, network: any) { this.blockbookURL = blockbookURL; if (SignerIn) { @@ -19,6 +20,7 @@ export class Syscoin { this.network = network || utils.syscoinNetworks.mainnet; } } + // proxy to signAndSend public signAndSendWithSigner = async ( psbt: any, @@ -455,220 +457,6 @@ export class Syscoin { ); }; - /* assetNew - Purpose: Create new Syscoin SPT. - Param assetOpts: Required. Asset details. Fields described below: - Field precision. Required. Digits precision for this asset. Range is 0 to 8 - Field symbol. Required. Symbol up to 8 characters in length in ASCII. - Field maxsupply. Required. Maximum satoshis for supply. Range is 1 to 1 quintillion (10^18) - Field description. Optional. Description in ASCII describing token. The description will be encoded via JSON in the pubdata field for the asset and will be in the 'desc' field of the JSON object. - Field contract. Optional. ERC20 address of the contract connected to this SPT for use in the SysEthereum bridge. - Field notarykeyid. Optional. Notary KeyID, the hash160 of the address used for notarization. Should be P2WPKH. - Field notarydetails. Optional. Notary Details, Fields described below: - Field endpoint. Required. Fully qualified URL of the notary endpoint. The endpoint will be sent a POST request with transaction hex and some other details in a JSON object and requires a signature signing the transaction following notarization protocol. - Field instanttransfers. Optional. Default is 0 (false). Instant transfers by blocking double-spends from inputs. Since notarization is happening via API the API can block any double-spend attempts thereby allowing for instant transactions. - Field hdrequired. Optional. Default is 0 (false). If HD account XPUB and HD path information is required by the notary to verify change addresses belong to the sender account. - Field auxfeedetails. Optional. Enforce auxiliary fees to every transaction on this asset. Fields described below: - Field auxfeekeyid. Required. AuxFee KeyID, the hash160 of the address used where fees are paid out to. Should be P2WPKH. - Field auxfees. Required. Array of AuxFee amounts based on total value being sent. Fields described below: - Field bound. Required. The amount threshold (in satoshi) where if total output value for this asset is at or above this amount apply a percentage fee. - Field percent. Required. Percent of total output value applied as a fee. Multiplied by 1000 to avoid floating point precision. For example 1% would be entered as 1000. 0.5% would be entered as 500. 0.001% would be entered as 1 (tenth of a basis point). - Field updatecapabilityflags. Optional. Defaults to 127 or ALL capabilities. Update capabilities on this asset. Fields are masks which are described below: - Mask 0 (No flags enabled) - Mask 1 (ASSET_UPDATE_DATA, can you update public data field?) - Mask 2 (ASSET_UPDATE_CONTRACT, can you update smart contract field?) - Mask 4 (ASSET_UPDATE_SUPPLY, can you issue or distribute supply via assetsend?) - Mask 8 (ASSET_UPDATE_NOTARY_KEY, can you update notary address?) - Mask 16 (ASSET_UPDATE_NOTARY_DETAILS, can you update notary details?) - Mask 32 (ASSET_UPDATE_AUXFEE, can you update aux fees?) - Mask 64 (ASSET_UPDATE_CAPABILITYFLAGS, can you update capability flags?) - Mask 127 (ASSET_CAPABILITY_ALL, All flags enabled) - Param txOpts: Optional. Transaction options. Fields are described below: - Field rbf. Optional. True by default. Replace-by-fee functionality allowing one to bump transaction by increasing fee for UTXOs used. Will be overrided to False, cannot be set to True for new asset transactions. - Field assetWhiteList. Optional. null by default. Allows UTXO's to be added from assets in the whitelist or the asset being sent - Param sysChangeAddress: Optional. Change address if defined is where Syscoin only change outputs are sent to. If not defined and Signer is defined then a new change address will be automatically created using the next available change address index in the HD path - Param sysReceivingAddress: Optional. Address which will hold the new asset. If not defined and Signer is defined then a new receiving address will be automatically created using the next available receiving address index in the HD path - Param feeRate: Optional. Defaults to 10 satoshi per byte. How many satoshi per byte the network fee should be paid out as. - Param sysFromXpubOrAddress: Optional. If wanting to fund from a specific XPUB or address specify this field should be set - Param utxos: Optional. Pass in specific utxos to fund a transaction. - Param redeemOrWitnessScript: Optional. redeemScript for P2SH and witnessScript for P2WSH spending conditions. - Returns: PSBT if if Signer is set or result object which is used to create PSBT and sign/send if xpub/address are passed in to fund transaction - */ - public assetNew = async ( - assetOpts: any, - txOpts: any, - sysChangeAddress: any, - sysReceivingAddress: any, - feeRate: any, - sysFromXpubOrAddress: any, - utxos: any, - redeemOrWitnessScript: any - ) => { - if (this.Signer) { - if (!sysChangeAddress) { - sysChangeAddress = await this.Signer.getNewChangeAddress(); - } - if (!sysReceivingAddress) { - sysReceivingAddress = await this.Signer.getNewReceivingAddress(); - } - } - // create dummy map where GUID will be replaced by deterministic one based on first input txid, we need this so fees will be accurately determined on first place of coinselect - const assetMap = new Map([ - [ - '0', - { - changeAddress: sysChangeAddress, - outputs: [{ value: new BN(0), address: sysReceivingAddress }], - }, - ], - ]); - // true last param for filtering out 0 conf UTXO, new/update/send asset transactions must use confirmed inputs only as per Syscoin Core mempool policy - utxos = await this.fetchAndSanitizeUTXOs( - utxos, - sysFromXpubOrAddress, - txOpts, - assetMap, - true - ); - const res = syscointx.assetNew( - assetOpts, - txOpts, - utxos, - assetMap, - sysChangeAddress, - feeRate - ); - const psbt = await this.createPSBTFromRes(res, redeemOrWitnessScript); - if (sysFromXpubOrAddress || !this.Signer) { - return { - psbt: psbt, - res: psbt, - assets: utils.getAssetsRequiringNotarization(psbt, utxos.assets), - }; - } - return await this.signAndSend( - psbt, - utils.getAssetsRequiringNotarization(psbt, utxos.assets), - undefined, - undefined - ); - }; - - /* assetUpdate - Purpose: Update existing Syscoin SPT. - Param assetGuid: Required. Asset GUID to update. - Param assetMap: Required. Description of Map: - Index assetGuid. Required. Numeric Asset GUID you are sending to - Value is described below: - Field changeAddress. Optional. Where asset change outputs will be sent to. If it is not there or null a new change address will be created. If Signer is not set, it will send asset change outputs to sysChangeAddress - Field outputs. Required. Array of objects described below: - Field value. Required. Big Number representing satoshi's to send. Should be 0 if doing an update. - Field address. Optional. Destination address for asset. - Example: - const assetMap = new Map([ - [assetGuid, { outputs: [{ value: new BN(0), address: 'tsys1qdflre2yd37qtpqe2ykuhwandlhq04r2td2t9ae' }] }] - ]) - Would update assetGuid asset and send it as change back to 'tsys1qdflre2yd37qtpqe2ykuhwandlhq04r2td2t9ae'. Change is the 0-value UTXO for asset ownership. - Param assetOpts: Required. Asset details. Fields described below: - Field description. Optional. Description in ASCII describing token. The description will be encoded via JSON in the pubdata field for the asset and will be in the 'desc' field of the JSON object. - Field contract. Optional. ERC20 address of the contract connected to this SPT for use in the SysEthereum bridge. - Field notarykeyid. Optional. Notary KeyID, the hash160 of the address used for notarization. Should be P2WPKH. - Field notarydetails. Optional. Notary Details, Fields described below: - Field endpoint. Required. Fully qualified URL of the notary endpoint. The endpoint will be sent a POST request with transaction hex and some other details in a JSON object and requires a signature signing the transaction following notarization protocol. - Field instanttransfers. Optional. Default is 0 (false). Instant transfers by blocking double-spends from inputs. Since notarization is happening via API the API can block any double-spend attempts thereby allowing for instant transactions. - Field hdrequired. Optional. Default is 0 (false). If HD account XPUB and HD path information is required by the notary to verify change addresses belong to the sender account. - Field auxfeedetails. Optional. Enforce auxiliary fees to every transaction on this asset. Fields described below: - Field auxfeekeyid. Required. AuxFee KeyID, the hash160 of the address used where fees are paid out to. Should be P2WPKH. - Field auxfees. Required. Array of AuxFee amounts based on total value being sent. Fields described below: - Field bound. Required. The amount threshold (in satoshi) where if total output value for this asset is at or above this amount apply a percentage fee. - Field percent. Required. Percent of total output value applied as a fee. Multiplied by 1000 to avoid floating point precision. For example 1% would be entered as 1000. 0.5% would be entered as 500. 0.001% would be entered as 1 (tenth of a basis point). - Field updatecapabilityflags. Optional. Defaults to 127 or ALL capabilities. Update capabilities on this asset. Fields are masks which are described below: - Mask 0 (No flags enabled) - Mask 1 (ASSET_UPDATE_DATA, can you update public data field?) - Mask 2 (ASSET_UPDATE_CONTRACT, can you update smart contract field?) - Mask 4 (ASSET_UPDATE_SUPPLY, can you issue or distribute supply via assetsend?) - Mask 8 (ASSET_UPDATE_NOTARY_KEY, can you update notary address?) - Mask 16 (ASSET_UPDATE_NOTARY_DETAILS, can you update notary details?) - Mask 32 (ASSET_UPDATE_AUXFEE, can you update aux fees?) - Mask 64 (ASSET_UPDATE_CAPABILITYFLAGS, can you update capability flags?) - Mask 127 (ASSET_CAPABILITY_ALL, All flags enabled) - Param txOpts: Optional. Transaction options. Fields are described below: - Field rbf. Optional. True by default. Replace-by-fee functionality allowing one to bump transaction by increasing fee for UTXOs used. - Field assetWhiteList. Optional. null by default. Allows UTXO's to be added from assets in the whitelist or the asset being sent - Param sysChangeAddress: Optional. Change address if defined is where Syscoin only change outputs are sent to. Does not apply to asset change outputs which are definable in the assetOpts object. If not defined and Signer is defined then a new change address will be automatically created using the next available change address index in the HD path - Param feeRate: Optional. Defaults to 10 satoshi per byte. How many satoshi per byte the network fee should be paid out as. - Param sysFromXpubOrAddress: Optional. If wanting to fund from a specific XPUB or address specify this field should be set - Param utxos: Optional. Pass in specific utxos to fund a transaction. - Param redeemOrWitnessScript: Optional. redeemScript for P2SH and witnessScript for P2WSH spending conditions. - Returns: PSBT if if Signer is set or result object which is used to create PSBT and sign/send if xpub/address are passed in to fund transaction - */ - public assetUpdate = async ( - assetGuid: any, - assetOpts: any, - txOpts: any, - assetMap: any, - sysChangeAddress: any, - feeRate: any, - sysFromXpubOrAddress: any, - utxos: any, - redeemOrWitnessScript: any - ) => { - if (!utxos) { - if (sysFromXpubOrAddress || !this.Signer) { - utxos = await utils.fetchBackendUTXOS( - this.blockbookURL, - sysFromXpubOrAddress - ); - } else if (this.Signer) { - utxos = await utils.fetchBackendUTXOS( - this.blockbookURL, - this.Signer.getAccountXpub() - ); - } - } - if (this.Signer) { - for (const valueAssetObj of assetMap.values()) { - if (!valueAssetObj.changeAddress) { - valueAssetObj.changeAddress = await this.Signer.getNewChangeAddress(); - } - } - if (!sysChangeAddress) { - sysChangeAddress = await this.Signer.getNewChangeAddress(); - } - } - // true last param for filtering out 0 conf UTXO, new/update/send asset transactions must use confirmed inputs only as per Syscoin Core mempool policy - utxos = await this.fetchAndSanitizeUTXOs( - utxos, - sysFromXpubOrAddress, - txOpts, - assetMap, - true - ); - const res = syscointx.assetUpdate( - assetGuid, - assetOpts, - txOpts, - utxos, - assetMap, - sysChangeAddress, - feeRate - ); - const psbt = await this.createPSBTFromRes(res, redeemOrWitnessScript); - if (sysFromXpubOrAddress || !this.Signer) { - return { - psbt: psbt, - res: psbt, - assets: utils.getAssetsRequiringNotarization(psbt, utxos.assets), - }; - } - return await this.signAndSend( - psbt, - utils.getAssetsRequiringNotarization(psbt, utxos.assets), - undefined, - undefined - ); - }; - /* assetSend Purpose: Issue supply by sending it from asset to an address holding an allocation of the asset. Param txOpts: Optional. Transaction options. Fields are described below: @@ -1126,6 +914,7 @@ export class Syscoin { ); }; } + const SyscoinJSLib = Syscoin; const syscoin = Syscoin;