UNPKG

@venly/venly-core-sdk

Version:

Javascrip/Typescript SDK for Venly's Web3 Services

193 lines 9.92 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VyWalletAPI = void 0; const VyTransactionHelper_1 = require("../helpers/VyTransactionHelper"); const wallet = __importStar(require("../models/wallet/index")); const VyWalletAPI_generated_1 = require("./VyWalletAPI.generated"); class VyWalletAPI extends VyWalletAPI_generated_1.VyWalletAPI_Gen { constructor(apiBase) { super(apiBase); } /** * This endpoint is used to create and execute any type of transaction. You need to provide the pincode in request body or the signing method in the header. You can execute any transaction such as NFT transfer, native transfer, ERC 20, etc. * @param {VyBuildContractExecutionTransactionRequest} reqParams - Request data for the operation * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyTransactionResultDto} */ executeContract(reqParams, signingMethod) { var req = new wallet.VyBuildAndExecuteTransactionDto(); req.transactionRequest = reqParams; return this.executeTransaction(req, signingMethod); } /** * This endpoint is used to create and execute any type of transaction. You need to provide the pincode in request body or the signing method in the header. You can execute any transaction such as NFT transfer, native transfer, ERC 20, etc. * @param {VyBuildTransferTransactionRequest} reqParams - Request data for the operation * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyTransactionResultDto} */ transferNativeToken(reqParams, signingMethod) { var req = new wallet.VyBuildAndExecuteTransactionDto(); req.transactionRequest = reqParams; return this.executeTransaction(req, signingMethod); } /** * This endpoint is used to create and execute any type of transaction. You need to provide the pincode in request body or the signing method in the header. You can execute any transaction such as NFT transfer, native transfer, ERC 20, etc. * @param {VyBuildTokenTransferTransactionRequest} reqParams - Request data for the operation * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyTransactionResultDto} */ transferErc20Token(reqParams, signingMethod) { var req = new wallet.VyBuildAndExecuteTransactionDto(); req.transactionRequest = reqParams; return this.executeTransaction(req, signingMethod); } /** * This endpoint is used to create and execute any type of transaction. You need to provide the pincode in request body or the signing method in the header. You can execute any transaction such as NFT transfer, native transfer, ERC 20, etc. * @param {VyBuildNftTransferTransactionRequest} reqParams - Request data for the operation * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyTransactionResultDto} */ transferNonFungibleToken(reqParams, signingMethod) { var req = new wallet.VyBuildAndExecuteTransactionDto(); req.transactionRequest = reqParams; return this.executeTransaction(req, signingMethod); } /** * Archive a wallet * @param {string} id - The id of the wallet * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyWalletDto} Updated Wallet */ archiveWallet(id) { var reqParams = new wallet.VyUpdateWalletDto(); reqParams.archived = true; return this.updateWallet(id, reqParams); } /** * Unarchive a wallet * @param {string} id - The id of the wallet * @param {VyUserAuth} signingMethod - This operation requires a valid Signing-Method from the corresponding user * @returns {VyWalletDto} Updated Wallet */ unarchiveWallet(id) { var reqParams = new wallet.VyUpdateWalletDto(); reqParams.archived = false; return this.updateWallet(id, reqParams); } //META TRANSACTIONS transferNonFungibleToken_MetaTransaction(reqParams) { return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { try { //1. Get Nonce var getNonceRequest = new wallet.VyReadContractDto({ chain: reqParams.chain, contractAddress: reqParams.token.contract.address, functionName: 'getNonce', walletAddress: reqParams.sourceWalletAddress, inputs: [ { type: 'address', value: reqParams.sourceWalletAddress } ], outputs: [ { type: 'uint256' } ] }); var getNonceResponse = yield this.readContract(getNonceRequest); if (!getNonceResponse.success) throw getNonceResponse.errorsToStr(); var nonce = Number(getNonceResponse.data[0].value); // Get Chain Info var chainInfoResponse = yield this.getBlockchainInfo(reqParams.chain); if (!chainInfoResponse.success) throw chainInfoResponse.errorsToStr(); var chainInfo = chainInfoResponse.data; //2. EIP721 Json Document Generation var eip721Doc = VyTransactionHelper_1.TransactionHelper.createEIP721_MetaTransaction(reqParams, chainInfo.chainId, nonce); //3. Sign Document (destination wallet) var signatureRequest = new wallet.VyBuildSignatureDto({ signatureRequest: new wallet.VyBuildEip712SignatureRequestDto({ chain: reqParams.chain, walletId: reqParams.sourceWalletId, data: eip721Doc }) }); var signatureResponse = yield this.signSignature(signatureRequest, reqParams.sourceUserAuth); if (!signatureResponse.success) throw signatureResponse.errorsToStr(); var signature = (signatureResponse.data); //4. Execute Transaction (executor wallet, gas fee payer) var executeContractRequest = new wallet.VyBuildContractExecutionTransactionRequest({ walletFromId: reqParams.executorWalletId, chain: reqParams.chain, toAddress: reqParams.token.contract.address, functionName: 'executeMetaTransaction', inputs: [ { type: 'address', value: reqParams.sourceWalletAddress }, { type: 'bytes', value: eip721Doc.message.functionSignature }, { type: 'bytes32', value: signature.r }, { type: 'bytes32', value: signature.s }, { type: 'uint8', value: signature.v } ] }); var transferResponse = yield this.executeContract(executeContractRequest, reqParams.executorUserAuth); if (!transferResponse.success) throw transferResponse.errorsToStr(); resolve(transferResponse); } catch (e) { reject(e); } })); } } exports.VyWalletAPI = VyWalletAPI; //# sourceMappingURL=VyWalletAPI.js.map