sdk/js: getOriginalAssetAptos NFT returns tokenId

This commit is contained in:
Kevin Peters 2023-01-31 14:59:00 +00:00 committed by Evan Gray
parent aa56dc5498
commit 7a8dea5158
3 changed files with 23 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import {
CONTRACTS,
deriveCollectionHashFromTokenId,
deriveTokenHashFromTokenId,
ensureHexPrefix,
generateSignAndSubmitEntryFunction,
tryNativeToHexString,
tryNativeToUint8Array,
@ -160,6 +161,9 @@ describe("Aptos NFT SDK tests", () => {
isWrapped: true,
chainId: CHAIN_ID_ETH,
assetAddress: Uint8Array.from(ethTransferVaaParsed.tokenAddress),
tokenId: ensureHexPrefix(
ethTransferVaaParsed.tokenId.toString(16).padStart(64, "0")
),
});
// transfer NFT from Aptos back to Ethereum
@ -345,6 +349,9 @@ describe("Aptos NFT SDK tests", () => {
isWrapped: false,
chainId: CHAIN_ID_APTOS,
assetAddress: tokenAddressAptos,
tokenId: ensureHexPrefix(
ethTransferVaaParsed.tokenId.toString(16).padStart(64, "0")
),
});
});

View File

@ -22,6 +22,9 @@ import {
coalesceChainId,
deriveCollectionHashFromTokenId,
hex,
deriveTokenHashFromTokenId,
ensureHexPrefix,
uint8ArrayToHex,
} from "../utils";
import { getIsWrappedAssetEth } from "./getIsWrappedAsset";
@ -198,7 +201,7 @@ export async function getOriginalAssetAptos(
client: AptosClient,
nftBridgeAddress: string,
tokenId: TokenTypes.TokenId
): Promise<WormholeWrappedInfo> {
): Promise<WormholeWrappedNFTInfo> {
try {
const originInfo = (
await client.getAccountResource(
@ -210,10 +213,12 @@ export async function getOriginalAssetAptos(
assertChain(chainId);
return {
isWrapped: true,
chainId: chainId,
assetAddress: new Uint8Array(
hex(originInfo.token_address.external_address)
),
chainId,
assetAddress:
chainId === CHAIN_ID_SOLANA
? arrayify(BigNumber.from(hex(tokenId.token_data_id.name)))
: new Uint8Array(hex(originInfo.token_address.external_address)),
tokenId: ensureHexPrefix(hex(tokenId.token_data_id.name).toString("hex")),
};
} catch (e: any) {
if (
@ -230,5 +235,8 @@ export async function getOriginalAssetAptos(
isWrapped: false,
chainId: CHAIN_ID_APTOS,
assetAddress: await deriveCollectionHashFromTokenId(tokenId),
tokenId: ensureHexPrefix(
uint8ArrayToHex(await deriveTokenHashFromTokenId(tokenId))
),
};
}

View File

@ -315,7 +315,9 @@ export const deriveTokenHashFromTokenId = async (
const propertyVersion = Buffer.alloc(8);
propertyVersion.writeBigUInt64BE(BigInt(tokenId.property_version));
const inputs = Buffer.concat([
Buffer.from(tokenId.token_data_id.creator, "hex"),
BCS.bcsToBytes(
TxnBuilderTypes.AccountAddress.fromHex(tokenId.token_data_id.creator)
),
Buffer.from(sha3_256(tokenId.token_data_id.collection), "hex"),
Buffer.from(sha3_256(tokenId.token_data_id.name), "hex"),
propertyVersion,