@aptos-labs/ts-sdk
Advanced tools
Comparing version 1.27.1 to 1.28.0
import { ChildProcessWithoutNullStreams } from 'child_process'; | ||
import { N as Network, g as AccountAddress } from '../accountAddress-LOYE4_sG.js'; | ||
import { N as Network, g as AccountAddress } from '../accountAddress-OVl7-qVN.js'; | ||
@@ -4,0 +4,0 @@ declare class LocalNode { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkJ4IUXT5Wjs = require('../chunk-J4IUXT5W.js');var _child_process = require('child_process');var _treekill = require('tree-kill'); var _treekill2 = _interopRequireDefault(_treekill);var _os = require('os');var p=class{constructor(){this.MAXIMUM_WAIT_TIME_SEC=75;this.READINESS_ENDPOINT="http://127.0.0.1:8070/";this.process=null}async stop(){await new Promise((s,e)=>{_optionalChain([this, 'access', _ => _.process, 'optionalAccess', _2 => _2.pid])&&_treekill2.default.call(void 0, this.process.pid,t=>{t?e(t):s(!0)})})}async run(){await this.checkIfProcessIsUp()||(this.start(),await this.waitUntilProcessIsUp())}start(){let s="npx",e=["aptos","node","run-localnet","--force-restart","--assume-yes","--with-indexer-api"],t=_os.platform.call(void 0, ),a;t==="win32"?a=_child_process.spawn.call(void 0, s,e,{shell:!0}):a=_child_process.spawn.call(void 0, s,e),this.process=a,_optionalChain([a, 'access', _3 => _3.stderr, 'optionalAccess', _4 => _4.on, 'call', _5 => _5("data",r=>{let o=r.toString();console.log(o)})]),_optionalChain([a, 'access', _6 => _6.stdout, 'optionalAccess', _7 => _7.on, 'call', _8 => _8("data",r=>{let o=r.toString();console.log(o)})])}async waitUntilProcessIsUp(){let s=await this.checkIfProcessIsUp(),e=Date.now()/1e3,t=e;for(;!s&&e+this.MAXIMUM_WAIT_TIME_SEC>t;)await _chunkJ4IUXT5Wjs.b.call(void 0, 1e3),s=await this.checkIfProcessIsUp(),t=Date.now()/1e3;if(!s)throw new Error("Process failed to start");return!0}async checkIfProcessIsUp(){try{return(await fetch(this.READINESS_ENDPOINT)).status===200}catch (e2){return!1}}};var m=class{async init(s){let{network:e,profile:t,extraArguments:a}=s,r=["aptos","init",`--network=${_nullishCoalesce(e, () => ("local"))}`,`--profile=${_nullishCoalesce(t, () => ("default"))}`];return a&&r.push(...a),this.runCommand(r)}async compile(s){let{packageDirectoryPath:e,namedAddresses:t,extraArguments:a}=s,r=["aptos","move","compile","--package-dir",e],o=this.parseNamedAddresses(t);return r.push(...this.prepareNamedAddresses(o)),a&&r.push(...a),this.runCommand(r)}async test(s){let{packageDirectoryPath:e,namedAddresses:t,extraArguments:a}=s,r=["aptos","move","test","--package-dir",e],o=this.parseNamedAddresses(t);return r.push(...this.prepareNamedAddresses(o)),a&&r.push(...a),this.runCommand(r)}async publish(s){let{packageDirectoryPath:e,namedAddresses:t,profile:a,extraArguments:r}=s,o=["aptos","move","publish","--package-dir",e,`--profile=${_nullishCoalesce(a, () => ("default"))}`],n=this.parseNamedAddresses(t);return o.push(...this.prepareNamedAddresses(n)),r&&o.push(...r),this.runCommand(o)}async createObjectAndPublishPackage(s){let{packageDirectoryPath:e,addressName:t,namedAddresses:a,profile:r,extraArguments:o}=s,n=["aptos","move","create-object-and-publish-package","--package-dir",e,"--address-name",t,`--profile=${_nullishCoalesce(r, () => ("default"))}`],i=this.parseNamedAddresses(a);n.push(...this.prepareNamedAddresses(i)),o&&n.push(...o);let g=await this.runCommand(n);return{objectAddress:this.extractAddressFromOutput(g.output)}}async upgradeObjectPackage(s){let{packageDirectoryPath:e,objectAddress:t,namedAddresses:a,profile:r,extraArguments:o}=s,n=["aptos","move","upgrade-object-package","--package-dir",e,"--object-address",t,`--profile=${_nullishCoalesce(r, () => ("default"))}`],i=this.parseNamedAddresses(a);return n.push(...this.prepareNamedAddresses(i)),o&&n.push(...o),this.runCommand(n)}async buildPublishPayload(s){let{outputFile:e,packageDirectoryPath:t,namedAddresses:a,extraArguments:r}=s,o=["aptos","move","build-publish-payload","--json-output-file",e,"--package-dir",t],n=this.parseNamedAddresses(a);return o.push(...this.prepareNamedAddresses(n)),r&&o.push(...r),this.runCommand(o)}async runScript(s){let{compiledScriptPath:e,profile:t,extraArguments:a}=s,r=["aptos","move","run-script","--compiled-script-path",e,`--profile=${_nullishCoalesce(t, () => ("default"))}`];return a&&r.push(...a),this.runCommand(r)}async runCommand(s){return new Promise((e,t)=>{let a=_os.platform.call(void 0, ),r,o="";a==="win32"?r=_child_process.spawn.call(void 0, "npx",s,{shell:!0}):r=_child_process.spawn.call(void 0, "npx",s),r.stdout.on("data",n=>{o+=n.toString()}),r.stdout.pipe(process.stdout),r.stderr.pipe(process.stderr),process.stdin.pipe(r.stdin),r.on("close",n=>{n===0?e({output:o}):t(new Error(`Child process exited with code ${n}`))})})}prepareNamedAddresses(s){let e=s.size,t=[];if(e===0)return t;t.push("--named-addresses");let a=[];return s.forEach((r,o)=>{let n=`${o}=${r.toString()}`;a.push(n)}),t.push(a.join(",")),t}parseNamedAddresses(s){let e=new Map;return Object.keys(s).forEach(t=>{let a=s[t];e.set(t,a)}),e}extractAddressFromOutput(s){let e=s.match("Code was successfully deployed to object address (0x[0-9a-fA-F]+)\\.");if(e)return e[1];throw new Error("Failed to extract object address from output")}};exports.LocalNode = p; exports.Move = m; | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkHBPH2AD3js = require('../chunk-HBPH2AD3.js');var _child_process = require('child_process');var _treekill = require('tree-kill'); var _treekill2 = _interopRequireDefault(_treekill);var _os = require('os');var p=class{constructor(){this.MAXIMUM_WAIT_TIME_SEC=75;this.READINESS_ENDPOINT="http://127.0.0.1:8070/";this.process=null}async stop(){await new Promise((s,e)=>{_optionalChain([this, 'access', _ => _.process, 'optionalAccess', _2 => _2.pid])&&_treekill2.default.call(void 0, this.process.pid,t=>{t?e(t):s(!0)})})}async run(){await this.checkIfProcessIsUp()||(this.start(),await this.waitUntilProcessIsUp())}start(){let s="npx",e=["aptos","node","run-localnet","--force-restart","--assume-yes","--with-indexer-api"],t=_os.platform.call(void 0, ),a;t==="win32"?a=_child_process.spawn.call(void 0, s,e,{shell:!0}):a=_child_process.spawn.call(void 0, s,e),this.process=a,_optionalChain([a, 'access', _3 => _3.stderr, 'optionalAccess', _4 => _4.on, 'call', _5 => _5("data",r=>{let o=r.toString();console.log(o)})]),_optionalChain([a, 'access', _6 => _6.stdout, 'optionalAccess', _7 => _7.on, 'call', _8 => _8("data",r=>{let o=r.toString();console.log(o)})])}async waitUntilProcessIsUp(){let s=await this.checkIfProcessIsUp(),e=Date.now()/1e3,t=e;for(;!s&&e+this.MAXIMUM_WAIT_TIME_SEC>t;)await _chunkHBPH2AD3js.b.call(void 0, 1e3),s=await this.checkIfProcessIsUp(),t=Date.now()/1e3;if(!s)throw new Error("Process failed to start");return!0}async checkIfProcessIsUp(){try{return(await fetch(this.READINESS_ENDPOINT)).status===200}catch (e2){return!1}}};var m=class{async init(s){let{network:e,profile:t,extraArguments:a}=s,r=["aptos","init",`--network=${_nullishCoalesce(e, () => ("local"))}`,`--profile=${_nullishCoalesce(t, () => ("default"))}`];return a&&r.push(...a),this.runCommand(r)}async compile(s){let{packageDirectoryPath:e,namedAddresses:t,extraArguments:a}=s,r=["aptos","move","compile","--package-dir",e],o=this.parseNamedAddresses(t);return r.push(...this.prepareNamedAddresses(o)),a&&r.push(...a),this.runCommand(r)}async test(s){let{packageDirectoryPath:e,namedAddresses:t,extraArguments:a}=s,r=["aptos","move","test","--package-dir",e],o=this.parseNamedAddresses(t);return r.push(...this.prepareNamedAddresses(o)),a&&r.push(...a),this.runCommand(r)}async publish(s){let{packageDirectoryPath:e,namedAddresses:t,profile:a,extraArguments:r}=s,o=["aptos","move","publish","--package-dir",e,`--profile=${_nullishCoalesce(a, () => ("default"))}`],n=this.parseNamedAddresses(t);return o.push(...this.prepareNamedAddresses(n)),r&&o.push(...r),this.runCommand(o)}async createObjectAndPublishPackage(s){let{packageDirectoryPath:e,addressName:t,namedAddresses:a,profile:r,extraArguments:o}=s,n=["aptos","move","create-object-and-publish-package","--package-dir",e,"--address-name",t,`--profile=${_nullishCoalesce(r, () => ("default"))}`],i=this.parseNamedAddresses(a);n.push(...this.prepareNamedAddresses(i)),o&&n.push(...o);let g=await this.runCommand(n);return{objectAddress:this.extractAddressFromOutput(g.output)}}async upgradeObjectPackage(s){let{packageDirectoryPath:e,objectAddress:t,namedAddresses:a,profile:r,extraArguments:o}=s,n=["aptos","move","upgrade-object-package","--package-dir",e,"--object-address",t,`--profile=${_nullishCoalesce(r, () => ("default"))}`],i=this.parseNamedAddresses(a);return n.push(...this.prepareNamedAddresses(i)),o&&n.push(...o),this.runCommand(n)}async buildPublishPayload(s){let{outputFile:e,packageDirectoryPath:t,namedAddresses:a,extraArguments:r}=s,o=["aptos","move","build-publish-payload","--json-output-file",e,"--package-dir",t],n=this.parseNamedAddresses(a);return o.push(...this.prepareNamedAddresses(n)),r&&o.push(...r),this.runCommand(o)}async runScript(s){let{compiledScriptPath:e,profile:t,extraArguments:a}=s,r=["aptos","move","run-script","--compiled-script-path",e,`--profile=${_nullishCoalesce(t, () => ("default"))}`];return a&&r.push(...a),this.runCommand(r)}async runCommand(s){return new Promise((e,t)=>{let a=_os.platform.call(void 0, ),r,o="";a==="win32"?r=_child_process.spawn.call(void 0, "npx",s,{shell:!0}):r=_child_process.spawn.call(void 0, "npx",s),r.stdout.on("data",n=>{o+=n.toString()}),r.stdout.pipe(process.stdout),r.stderr.pipe(process.stderr),process.stdin.pipe(r.stdin),r.on("close",n=>{n===0?e({output:o}):t(new Error(`Child process exited with code ${n}`))})})}prepareNamedAddresses(s){let e=s.size,t=[];if(e===0)return t;t.push("--named-addresses");let a=[];return s.forEach((r,o)=>{let n=`${o}=${r.toString()}`;a.push(n)}),t.push(a.join(",")),t}parseNamedAddresses(s){let e=new Map;return Object.keys(s).forEach(t=>{let a=s[t];e.set(t,a)}),e}extractAddressFromOutput(s){let e=s.match("Code was successfully deployed to object address (0x[0-9a-fA-F]+)");if(e)return e[1];throw new Error("Failed to extract object address from output")}};exports.LocalNode = p; exports.Move = m; | ||
//# sourceMappingURL=index.js.map |
@@ -98,3 +98,3 @@ { | ||
}, | ||
"version": "1.27.1" | ||
"version": "1.28.0" | ||
} |
@@ -6,3 +6,3 @@ // Copyright © Aptos Foundation | ||
import { MultiKey, MultiKeySignature, PublicKey } from "../core/crypto"; | ||
import { AccountAddress } from "../core/accountAddress"; | ||
import { AccountAddress, AccountAddressInput } from "../core/accountAddress"; | ||
import { HexInput, SigningScheme } from "../types"; | ||
@@ -65,4 +65,4 @@ import { AccountAuthenticatorMultiKey } from "../transactions/authenticator/account"; | ||
*/ | ||
constructor(args: { multiKey: MultiKey; signers: Account[] }) { | ||
const { multiKey, signers } = args; | ||
constructor(args: { multiKey: MultiKey; signers: Account[]; address?: AccountAddressInput }) { | ||
const { multiKey, signers, address } = args; | ||
@@ -72,3 +72,3 @@ this.publicKey = multiKey; | ||
this.accountAddress = this.publicKey.authKey().derivedAddress(); | ||
this.accountAddress = address ? AccountAddress.from(address) : this.publicKey.authKey().derivedAddress(); | ||
@@ -75,0 +75,0 @@ // Get the index of each respective signer in the bitmap |
@@ -18,2 +18,3 @@ // Copyright © Aptos Foundation | ||
MoveStructId, | ||
MoveValue, | ||
OrderByArg, | ||
@@ -44,6 +45,8 @@ PaginationArgs, | ||
} from "../internal/account"; | ||
import { APTOS_COIN, ProcessorType } from "../utils/const"; | ||
import { APTOS_COIN, APTOS_FA, ProcessorType } from "../utils/const"; | ||
import { AptosConfig } from "./aptosConfig"; | ||
import { waitForIndexerOnVersion } from "./utils"; | ||
import { CurrentFungibleAssetBalancesBoolExp } from "../types/generated/types"; | ||
import { view } from "../internal/view"; | ||
import { isEncodedStruct, parseEncodedStruct } from "../utils"; | ||
@@ -433,3 +436,3 @@ /** | ||
}): Promise<number> { | ||
return this.getAccountCoinAmount({ coinType: APTOS_COIN, ...args }); | ||
return this.getAccountCoinAmount({ coinType: APTOS_COIN, faMetadataAddress: APTOS_FA, ...args }); | ||
} | ||
@@ -444,3 +447,4 @@ | ||
* @param args.accountAddress The account address we want to get the total count for | ||
* @param args.coinType The coin type to query | ||
* @param args.coinType The coin type to query. | ||
* Note: faMetadataAddress will automatically fill this in if not provided when migrated to fungible assets | ||
* @param args.faMetadataAddress The fungible asset metadata address to query. | ||
@@ -457,2 +461,3 @@ * Note: coinType will automatically fill this in if not provided when migrated to fungible assets | ||
}): Promise<number> { | ||
const { coinType, faMetadataAddress } = args; | ||
await waitForIndexerOnVersion({ | ||
@@ -463,3 +468,25 @@ config: this.config, | ||
}); | ||
return getAccountCoinAmount({ aptosConfig: this.config, ...args }); | ||
// Attempt to populate the CoinType field if the FA address is provided. | ||
// We cannot do this internally due to dependency cycles issue. | ||
let coinAssetType: MoveStructId | undefined = coinType; | ||
if (coinType === undefined && faMetadataAddress !== undefined) { | ||
try { | ||
const pairedCoinTypeStruct = ( | ||
await view({ | ||
aptosConfig: this.config, | ||
payload: { function: "0x1::coin::paired_coin", functionArguments: [faMetadataAddress] }, | ||
}) | ||
).at(0) as { vec: MoveValue[] }; | ||
// Check if the Option has a value, and if so, parse the struct | ||
if (pairedCoinTypeStruct.vec.length > 0 && isEncodedStruct(pairedCoinTypeStruct.vec[0])) { | ||
coinAssetType = parseEncodedStruct(pairedCoinTypeStruct.vec[0]); | ||
} | ||
} catch (error) { | ||
/* No paired coin type found */ | ||
} | ||
} | ||
return getAccountCoinAmount({ aptosConfig: this.config, ...args, coinType: coinAssetType }); | ||
} | ||
@@ -466,0 +493,0 @@ |
@@ -70,9 +70,8 @@ // Copyright © Aptos Foundation | ||
serializeForScriptFunction(serializer: Serializer): void { | ||
// runtime check to ensure that you can't serialize anything other than vector<u8> | ||
const isU8 = this.values[0] instanceof U8; | ||
// if the inner array is length 0, we can't check the type because it has no instance, so we assume it's a u8 | ||
// it may not be, but we don't care because regardless of a vector's type, | ||
// a zero-length vector is serialized to a single byte value: 0 | ||
if (!isU8 && this.values[0] !== undefined) { | ||
throw new Error("Script function arguments only accept u8 vectors"); | ||
// This checks if the type of a non-empty vector is of type other than U8. If so, we use the Serialized | ||
// transaction argument type to serialize the argument. | ||
if (this.values[0] !== undefined && !(this.values[0] instanceof U8)) { | ||
const serialized = new Serialized(this.bcsToBytes()); | ||
serialized.serializeForScriptFunction(serializer); | ||
return; | ||
} | ||
@@ -229,2 +228,35 @@ serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.U8Vector); | ||
export class Serialized extends Serializable implements TransactionArgument { | ||
public readonly value: Uint8Array; | ||
constructor(value: HexInput) { | ||
super(); | ||
this.value = Hex.fromHexInput(value).toUint8Array(); | ||
} | ||
serialize(serializer: Serializer): void { | ||
serializer.serializeBytes(this.value); | ||
} | ||
serializeForEntryFunction(serializer: Serializer): void { | ||
this.serialize(serializer); | ||
} | ||
serializeForScriptFunction(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.Serialized); | ||
this.serialize(serializer); | ||
} | ||
static deserialize(deserializer: Deserializer): Serialized { | ||
return new Serialized(deserializer.deserializeBytes()); | ||
} | ||
toMoveVector<T extends Serializable & EntryFunctionArgument>(cls: Deserializable<T>): MoveVector<T> { | ||
const deserializer = new Deserializer(this.bcsToBytes()); | ||
deserializer.deserializeUleb128AsU32(); | ||
const vec = deserializer.deserializeVector(cls); | ||
return new MoveVector(vec); | ||
} | ||
} | ||
export class MoveString extends Serializable implements TransactionArgument { | ||
@@ -249,3 +281,4 @@ public value: string; | ||
// Serialize the string as a fixed byte string, i.e., without the length prefix | ||
const fixedStringBytes = this.bcsToBytes().slice(1); | ||
const textEncoder = new TextEncoder(); | ||
const fixedStringBytes = textEncoder.encode(this.value); | ||
// Put those bytes into a vector<u8> and serialize it as a script function argument | ||
@@ -252,0 +285,0 @@ const vectorU8 = MoveVector.U8(fixedStringBytes); |
@@ -428,3 +428,3 @@ import { spawn } from "child_process"; | ||
private extractAddressFromOutput(output: string): string { | ||
const match = output.match("Code was successfully deployed to object address (0x[0-9a-fA-F]+)\\."); | ||
const match = output.match("Code was successfully deployed to object address (0x[0-9a-fA-F]+)"); | ||
if (match) { | ||
@@ -431,0 +431,0 @@ return match[1]; |
@@ -412,3 +412,4 @@ // Copyright © Aptos Foundation | ||
const { aptosConfig, accountAddress, coinType, faMetadataAddress } = args; | ||
let coinAssetType: string | undefined; | ||
let coinAssetType: string | undefined = coinType; | ||
let faAddress: string; | ||
@@ -419,5 +420,4 @@ | ||
} else if (coinType !== undefined && faMetadataAddress === undefined) { | ||
coinAssetType = coinType; | ||
// TODO Move to a separate function as defined in the AIP for coin migration | ||
if (args.coinType === APTOS_COIN) { | ||
if (coinType === APTOS_COIN) { | ||
faAddress = AccountAddress.A.toStringLong(); | ||
@@ -428,3 +428,2 @@ } else { | ||
} else if (coinType === undefined && faMetadataAddress !== undefined) { | ||
// TODO: add a view function lookup for non-APT migrated coins | ||
const addr = AccountAddress.from(faMetadataAddress); | ||
@@ -435,2 +434,4 @@ faAddress = addr.toStringLong(); | ||
} | ||
// The paired CoinType should be populated outside of this function in another | ||
// async call. We cannot do this internally due to dependency cycles issue. | ||
} else { | ||
@@ -443,3 +444,3 @@ throw new Error("Either coinType, fungibleAssetAddress, or both must be provided"); | ||
let where: any = { asset_type: { _eq: faAddress } }; | ||
if (coinType !== undefined) { | ||
if (coinAssetType !== undefined) { | ||
where = { asset_type: { _in: [coinAssetType, faAddress] } }; | ||
@@ -446,0 +447,0 @@ } |
@@ -34,5 +34,12 @@ // Copyright © Aptos Foundation | ||
const whereCondition: EventsBoolExp = { | ||
account_address: { _eq: "0x0000000000000000000000000000000000000000000000000000000000000000" }, | ||
creation_number: { _eq: "0" }, | ||
sequence_number: { _eq: "0" }, | ||
_or: [ | ||
// EventHandle events | ||
{ account_address: { _eq: eventType.split("::")[0] } }, | ||
// Module events | ||
{ | ||
account_address: { _eq: "0x0000000000000000000000000000000000000000000000000000000000000000" }, | ||
sequence_number: { _eq: 0 }, | ||
creation_number: { _eq: 0 }, | ||
}, | ||
], | ||
indexed_type: { _eq: eventType }, | ||
@@ -39,0 +46,0 @@ }; |
@@ -10,3 +10,3 @@ // Copyright © Aptos Foundation | ||
import { Bool, U128, U16, U256, U32, U64, U8 } from "../../bcs/serializable/movePrimitives"; | ||
import { MoveVector } from "../../bcs/serializable/moveStructs"; | ||
import { MoveVector, Serialized } from "../../bcs/serializable/moveStructs"; | ||
import { AccountAddress } from "../../core"; | ||
@@ -44,2 +44,4 @@ import { Identifier } from "./identifier"; | ||
return U256.deserialize(deserializer); | ||
case ScriptTransactionArgumentVariants.Serialized: | ||
return Serialized.deserialize(deserializer); | ||
default: | ||
@@ -46,0 +48,0 @@ throw new Error(`Unknown variant index for ScriptTransactionArgument: ${index}`); |
@@ -23,2 +23,3 @@ // Copyright © Aptos Foundation | ||
import { MultiAgentTransaction } from "./instances/multiAgentTransaction"; | ||
import { Serialized } from "../bcs"; | ||
@@ -68,5 +69,6 @@ /** | ||
| AccountAddress | ||
| MoveVector<U8> | ||
| MoveVector<ScriptFunctionArgumentTypes> | ||
| MoveString | ||
| FixedBytes; | ||
| FixedBytes | ||
| Serialized; | ||
@@ -73,0 +75,0 @@ /** |
@@ -64,2 +64,3 @@ // Copyright © Aptos Foundation | ||
U256 = 8, | ||
Serialized = 9, | ||
} | ||
@@ -66,0 +67,0 @@ |
@@ -47,2 +47,3 @@ // Copyright © Aptos Foundation | ||
export const APTOS_COIN = "0x1::aptos_coin::AptosCoin"; | ||
export const APTOS_FA = "0x000000000000000000000000000000000000000000000000000000000000000a"; | ||
@@ -49,0 +50,0 @@ export const RAW_TRANSACTION_SALT = "APTOS::RawTransaction"; |
@@ -5,2 +5,3 @@ // Copyright © Aptos Foundation | ||
import { decode } from "js-base64"; | ||
import { MoveStructId } from "../types"; | ||
@@ -62,1 +63,70 @@ /** | ||
export const convertAmountFromOnChainToHumanReadable = (value: number, decimal: number) => value / 10 ** decimal; | ||
/** | ||
* Convert a hex string to an ascii string with the `0x` prefix. | ||
* | ||
* `0x6170746f735f636f696e` --> `aptos_coin` | ||
* | ||
* @param hex The hex string to convert (e.g. `0x6170746f735f636f696e`) | ||
* @returns The ascii string | ||
*/ | ||
const hexToAscii = (hex: string) => { | ||
let str = ""; | ||
for (let n = 2; n < hex.length; n += 2) { | ||
str += String.fromCharCode(parseInt(hex.substring(n, n + 2), 16)); | ||
} | ||
return str; | ||
}; | ||
/** | ||
* Convert an encoded struct to a MoveStructId. | ||
* | ||
* @example | ||
* const structObj = { | ||
* account_address: "0x1", | ||
* module_name: "0x6170746f735f636f696e", | ||
* struct_name: "0x4170746f73436f696e", | ||
* }; | ||
* // structId is "0x1::aptos_coin::AptosCoin" | ||
* const structId = parseEncodedStruct(structObj); | ||
* | ||
* @param structObj The struct with account_address, module_name, and struct_name properties | ||
* @returns The MoveStructId | ||
*/ | ||
export const parseEncodedStruct = (structObj: { | ||
account_address: string; | ||
module_name: string; | ||
struct_name: string; | ||
}): MoveStructId => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const { account_address, module_name, struct_name } = structObj; | ||
const moduleName = hexToAscii(module_name); | ||
const structName = hexToAscii(struct_name); | ||
return `${account_address}::${moduleName}::${structName}`; | ||
}; | ||
/** | ||
* Determines whether the given object is an encoded struct type with the following properties: | ||
* - account_address: string | ||
* - module_name: string | ||
* - struct_name: string | ||
* | ||
* @param structObj The object to check | ||
* @returns Whether the object is an encoded struct type | ||
*/ | ||
export const isEncodedStruct = ( | ||
structObj: any, | ||
): structObj is { | ||
account_address: string; | ||
module_name: string; | ||
struct_name: string; | ||
} => | ||
typeof structObj === "object" && | ||
!Array.isArray(structObj) && | ||
structObj !== null && | ||
"account_address" in structObj && | ||
"module_name" in structObj && | ||
"struct_name" in structObj && | ||
typeof structObj.account_address === "string" && | ||
typeof structObj.module_name === "string" && | ||
typeof structObj.struct_name === "string"; |
@@ -9,2 +9,2 @@ // Copyright © Aptos Foundation | ||
*/ | ||
export const VERSION = "1.27.1"; | ||
export const VERSION = "1.28.0"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
5641040
42502