@tari-project/tarijs-types 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/index.d.ts +7 -0
- package/dist/helpers/index.js +50 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { TransactionStatus } from "../TransactionResult";
|
|
3
|
+
export declare function convertStringToTransactionStatus(status: string): TransactionStatus;
|
|
4
|
+
export declare function createNftAddressFromToken(token: NonFungibleToken): string;
|
|
5
|
+
export declare function convertU256ToHexString(id: NonFungibleId): string;
|
|
6
|
+
export declare function convertHexStringToU256Array(hexString: string): number[];
|
|
7
|
+
export declare function createNftAddressFromResource(address: ResourceAddress, tokenId: NonFungibleId): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TransactionStatus } from "../TransactionResult";
|
|
2
|
+
export function convertStringToTransactionStatus(status) {
|
|
3
|
+
switch (status) {
|
|
4
|
+
case "New":
|
|
5
|
+
return TransactionStatus.New;
|
|
6
|
+
case "DryRun":
|
|
7
|
+
return TransactionStatus.DryRun;
|
|
8
|
+
case "Pending":
|
|
9
|
+
return TransactionStatus.Pending;
|
|
10
|
+
case "Accepted":
|
|
11
|
+
return TransactionStatus.Accepted;
|
|
12
|
+
case "Rejected":
|
|
13
|
+
return TransactionStatus.Rejected;
|
|
14
|
+
case "InvalidTransaction":
|
|
15
|
+
return TransactionStatus.InvalidTransaction;
|
|
16
|
+
case "OnlyFeeAccepted":
|
|
17
|
+
return TransactionStatus.OnlyFeeAccepted;
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unknown status: ${status}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Function to create the Nft address
|
|
23
|
+
// address format: nft_RESOURCEADDR_uuid_TOKENID
|
|
24
|
+
export function createNftAddressFromToken(token) {
|
|
25
|
+
return createNftAddressFromResource(token.resource_address, token.nft_id);
|
|
26
|
+
}
|
|
27
|
+
export function convertU256ToHexString(id) {
|
|
28
|
+
if ("U256" in id && Array.isArray(id.U256)) {
|
|
29
|
+
return id.U256.map((num) => num.toString(16).padStart(2, "0")).join("");
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
export function convertHexStringToU256Array(hexString) {
|
|
34
|
+
const cleanHexString = hexString.replace(/[^0-9a-fA-F]/g, "");
|
|
35
|
+
const u256Array = [];
|
|
36
|
+
for (let i = 0; i < cleanHexString.length; i += 2) {
|
|
37
|
+
const hexPair = cleanHexString.slice(i, i + 2);
|
|
38
|
+
u256Array.push(parseInt(hexPair, 16));
|
|
39
|
+
}
|
|
40
|
+
return u256Array;
|
|
41
|
+
}
|
|
42
|
+
export function createNftAddressFromResource(address, tokenId) {
|
|
43
|
+
let nftAddress = "nft_";
|
|
44
|
+
const resourceAddress = address.replace(/^resource_/, "");
|
|
45
|
+
nftAddress += resourceAddress;
|
|
46
|
+
nftAddress += "_uuid_";
|
|
47
|
+
const nftIdHexString = convertU256ToHexString(tokenId);
|
|
48
|
+
nftAddress += nftIdHexString;
|
|
49
|
+
return nftAddress;
|
|
50
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
|
21
21
|
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
22
22
|
export { ViewableBalanceProof } from "./ViewableBalanceProof";
|
|
23
23
|
export { WorkspaceArg } from "./Workspace";
|
|
24
|
+
export { convertHexStringToU256Array, convertStringToTransactionStatus, convertU256ToHexString, createNftAddressFromResource, createNftAddressFromToken, } from "./helpers";
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tari-project/typescript-bindings": "^1.
|
|
13
|
+
"@tari-project/typescript-bindings": "^1.5.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^22.13.1",
|