@venly/venly-core-sdk
Version:
Javascrip/Typescript SDK for Venly's Web3 Services
85 lines • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionHelper = exports.VyEIP721_MetaTransaction = void 0;
class VyEIP721_MetaTransaction {
}
exports.VyEIP721_MetaTransaction = VyEIP721_MetaTransaction;
class TransactionHelper {
static padAddr(input, padSize = 64, padChar = '0', stripPrefix = true) {
if (stripPrefix && input.length >= 2) {
if (input[0] == '0' && input[1] == 'x')
input = input.substring(2);
}
return input.padStart(padSize, padChar);
}
static padHex(input, padSize = 64, padChar = '0') {
if (typeof input === 'string') {
return Number(input).toString(16).padStart(padSize, padChar);
}
return input.toString(16).padStart(padSize, padChar);
}
static createFunctionSignature_safeTransferFrom(fromAddr, toAddr, tokenId, amount = 1) {
return '0xf242432a'
+ `${this.padAddr(fromAddr)}`
+ `${this.padAddr(toAddr)}`
+ `${this.padHex(tokenId)}`
+ `${this.padHex(amount)}`
+ '00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000';
}
static createEIP721_MetaTransaction(data, chainId, nonce) {
//Function Signature
var signature = this.createFunctionSignature_safeTransferFrom(data.sourceWalletAddress, data.destinationAddress, data.token.id, data.amount);
//Document
var doc = {
types: {
EIP712Domain: [
{
name: 'name',
type: 'string'
},
{
name: 'version',
type: 'string'
},
{
name: 'verifyingContract',
type: 'address'
},
{
name: 'salt',
type: 'bytes32'
}
],
MetaTransaction: [
{
name: 'nonce',
type: 'uint256'
},
{
name: 'from',
type: 'address'
},
{
name: 'functionSignature',
type: 'bytes'
}
]
},
domain: {
name: data.token.contract.name,
version: '1',
verifyingContract: data.token.contract.address,
salt: `0x${this.padHex(chainId)}`
},
primaryType: 'MetaTransaction',
message: {
nonce: nonce,
from: data.sourceWalletAddress,
functionSignature: signature
}
};
return doc;
}
}
exports.TransactionHelper = TransactionHelper;
//# sourceMappingURL=VyTransactionHelper.js.map