Skip to content

Commit 29b4bad

Browse files
Merge pull request #12 from metaplex-foundation/feat/new-methods
Adding new methods
2 parents 8d411a3 + 76d9f09 commit 29b4bad

16 files changed

+1202
-519
lines changed

README.md

+282-118
Large diffs are not rendered by default.

clients/js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "rimraf dist && tsc -p tsconfig.json",
99
"build:docs": "typedoc",
10-
"test": "ava",
10+
"test": "ava -s",
1111
"lint": "eslint --ext js,ts,tsx src",
1212
"lint:fix": "eslint --fix --ext js,ts,tsx src",
1313
"format": "prettier --check src test",
@@ -76,4 +76,4 @@
7676
"path-to-regexp@>=4.0.0 <6.3.0": ">=6.3.0"
7777
}
7878
}
79-
}
79+
}

clients/js/src/decorator.ts

+66
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
DasApiAsset,
1010
DasApiAssetList,
1111
SearchAssetsRpcInput,
12+
GetAssetSignaturesRpcResponse,
13+
GetAssetProofsRpcResponse,
14+
GetAssetSignaturesRpcInput,
1215
} from './types';
1316

1417
export interface DasApiInterface {
@@ -19,13 +22,27 @@ export interface DasApiInterface {
1922
*/
2023
getAsset(assetId: PublicKey): Promise<DasApiAsset>;
2124

25+
/**
26+
* Return the metadata information of multiple compressed/standard assets.
27+
*
28+
* @param assetIds Array of the ids of the assets to fetch
29+
*/
30+
getAssets(assetIds: PublicKey[]): Promise<DasApiAsset[]>;
31+
2232
/**
2333
* Return the merkle tree proof information for a compressed asset.
2434
*
2535
* @param assetId the id of the asset to fetch the proof for
2636
*/
2737
getAssetProof(assetId: PublicKey): Promise<GetAssetProofRpcResponse>;
2838

39+
/**
40+
* Return the merkle tree proof information for multiple compressed assets.
41+
*
42+
* @param assetIds array of the ids of the assets to fetch the proofs for
43+
*/
44+
getAssetProofs(assetIds: PublicKey[]): Promise<GetAssetProofsRpcResponse>;
45+
2946
/**
3047
* Return the list of assets given an authority address.
3148
*
@@ -64,6 +81,15 @@ export interface DasApiInterface {
6481
* @param input the input parameters for the RPC call
6582
*/
6683
searchAssets(input: SearchAssetsRpcInput): Promise<DasApiAssetList>;
84+
85+
/**
86+
* Return the transaction signatures for a compressed asset
87+
*
88+
* @param input the input parameters for the RPC call
89+
*/
90+
getAssetSignatures(
91+
input: GetAssetSignaturesRpcInput
92+
): Promise<GetAssetSignaturesRpcResponse>;
6793
}
6894

6995
export const createDasApiDecorator = (
@@ -75,6 +101,13 @@ export const createDasApiDecorator = (
75101
if (!asset) throw new DasApiError(`Asset not found: ${assetId}`);
76102
return asset;
77103
},
104+
getAssets: async (assetIds: PublicKey[]) => {
105+
const assets = await rpc.call<DasApiAsset[] | null>('getAssets', [
106+
assetIds,
107+
]);
108+
if (!assets) throw new DasApiError(`No assets found: ${assetIds}`);
109+
return assets;
110+
},
78111
getAssetProof: async (assetId: PublicKey) => {
79112
const proof = await rpc.call<GetAssetProofRpcResponse | null>(
80113
'getAssetProof',
@@ -83,6 +116,15 @@ export const createDasApiDecorator = (
83116
if (!proof) throw new DasApiError(`No proof found for asset: ${assetId}`);
84117
return proof;
85118
},
119+
getAssetProofs: async (assetIds: PublicKey[]) => {
120+
const proofs = await rpc.call<GetAssetProofsRpcResponse | null>(
121+
'getAssetProofs',
122+
[assetIds]
123+
);
124+
if (!proofs)
125+
throw new DasApiError(`No proofs found for assets: ${assetIds}`);
126+
return proofs;
127+
},
86128
getAssetsByAuthority: async (input: GetAssetsByAuthorityRpcInput) => {
87129
if (typeof input.page === 'number' && (input.before || input.after)) {
88130
throw new DasApiError(
@@ -215,4 +257,28 @@ export const createDasApiDecorator = (
215257
}
216258
return assetList;
217259
},
260+
getAssetSignatures: async (input: GetAssetSignaturesRpcInput) => {
261+
const signatures = await rpc.call<GetAssetSignaturesRpcResponse | null>(
262+
'getAssetSignaturesV2',
263+
[
264+
'assetId' in input ? input.assetId : null,
265+
input.limit ?? null,
266+
input.page ?? null,
267+
input.before ?? null,
268+
input.after ?? null,
269+
'tree' in input ? input.tree : null,
270+
'tree' in input ? input.leaf_index : null,
271+
input.cursor ?? null,
272+
input.sort_direction ?? null,
273+
]
274+
);
275+
if (!signatures) {
276+
const identifier =
277+
'assetId' in input
278+
? `asset: ${input.assetId}`
279+
: `tree: ${input.tree}, leaf_index: ${input.leaf_index}`;
280+
throw new DasApiError(`No signatures found for ${identifier}`);
281+
}
282+
return signatures;
283+
},
218284
});

clients/js/src/types.ts

+91-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ type Pagination = {
327327
* Sorting criteria.
328328
*/
329329
type DasApiParamAssetSortBy = {
330-
sortBy: 'created' | 'updated' | 'recent_action' | 'none';
330+
sortBy: 'created' | 'updated' | 'recent_action' | 'id' | 'none';
331331
sortDirection: 'asc' | 'desc';
332332
};
333333

@@ -441,3 +441,93 @@ export type GetAssetProofRpcResponse = {
441441
leaf: PublicKey;
442442
tree_id: PublicKey;
443443
};
444+
445+
export type GetAssetProofsRpcResponse = Record<
446+
PublicKey,
447+
GetAssetProofRpcResponse
448+
>;
449+
450+
export type GetAssetSignaturesRpcInput = {
451+
/**
452+
* The maximum number of assets to retrieve.
453+
*/
454+
limit?: Nullable<number>;
455+
456+
/**
457+
* The page number of the signatures.
458+
*/
459+
page?: Nullable<number>;
460+
461+
/**
462+
* Retrieve signatures before the specified `ID` value.
463+
*/
464+
before?: Nullable<string>;
465+
466+
/**
467+
* Retrieve signatures after the specified `ID` value.
468+
*/
469+
after?: Nullable<string>;
470+
471+
/**
472+
*
473+
*/
474+
cursor?: Nullable<string>;
475+
476+
/**
477+
* The sort direction.
478+
*/
479+
sort_direction?: Nullable<'asc' | 'desc'>;
480+
} & (
481+
| {
482+
/**
483+
* The Asset ID to retrieve signatures for.
484+
*/
485+
assetId: PublicKey;
486+
tree?: never;
487+
leaf_index?: never;
488+
}
489+
| {
490+
/**
491+
* The tree ID to retrieve signatures for.
492+
*/
493+
tree: PublicKey;
494+
/**
495+
* The leaf index to retrieve signatures for.
496+
*/
497+
leaf_index: number;
498+
assetId?: never;
499+
}
500+
);
501+
502+
export type DasApiTransactionSignature = {
503+
signature: string;
504+
instruction: string;
505+
slot: number;
506+
};
507+
508+
export type GetAssetSignaturesRpcResponse = {
509+
/**
510+
* total number of signatures in the list.
511+
*/
512+
total: number;
513+
514+
/**
515+
* Limit of signatures used to create the list. When the `total` value is
516+
* lower than the `limit`, it means that there are no more signatures to be
517+
* retrieved.
518+
*/
519+
limit: number;
520+
521+
before: string;
522+
after: string;
523+
524+
/**
525+
* The page number of the signatures.
526+
*/
527+
page?: number;
528+
529+
/**
530+
* List of individual signatures.
531+
*/
532+
items: DasApiTransactionSignature[];
533+
};

clients/js/test/getAsset.test.ts

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
import { publicKey } from '@metaplex-foundation/umi';
22
import test from 'ava';
3-
import { DasApiAsset } from '../src';
3+
import {
4+
DasApiAsset,
5+
DasApiAssetCompression,
6+
DasApiAssetContent,
7+
} from '../src';
48
import { DAS_API_ENDPOINTS, createUmi } from './_setup';
59

610
DAS_API_ENDPOINTS.forEach((endpoint) => {
711
test(`it can fetch a compressed asset by ID (${endpoint.name})`, async (t) => {
812
// Given a minted NFT.
913
const umi = createUmi(endpoint.url);
10-
const assetId = publicKey('8TrvJBRa6Pzb9BDadqroHhWTHxaxK8Ws8r91oZ2jxaVV');
14+
const assetId = publicKey('GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA');
1115

1216
// When we fetch the asset using its ID.
1317
const asset = await umi.rpc.getAsset(assetId);
1418

1519
// Then we expect the following data.
16-
t.like(asset, <DasApiAsset>{
17-
interface: 'V1_NFT',
18-
id: assetId,
19-
content: {
20-
json_uri:
21-
'https://arweave.net/c9aGs5fOk7gD4wWnSvmzeqgtfxAGRgtI1jYzvl8-IVs/chiaki-violet-azure-common.json',
22-
metadata: {
23-
name: 'Chiaki Azure 55',
24-
},
20+
t.deepEqual(asset.interface, 'V1_NFT');
21+
t.deepEqual(asset.id, assetId);
22+
t.like(asset.content, <DasApiAssetContent>{
23+
json_uri:
24+
'https://arweave.net/c9aGs5fOk7gD4wWnSvmzeqgtfxAGRgtI1jYzvl8-IVs/chiaki-violet-azure-common.json',
25+
metadata: {
26+
name: 'Chiaki Azure 55',
2527
},
26-
compression: {
27-
eligible: false,
28-
compressed: true,
29-
data_hash: '3daLaunnCdbLtYR4Gas4xFnKLVezdMNqgjZEXtzhWqFA',
30-
creator_hash: 'DJ7kGgdfHEMPJLUTW1YdnGX2JBc3DdD6ybJmkfE4wgSq',
31-
asset_hash: 'BtbdpcxueKdAwpwRtyXMpUMV2Zbjd6YYtWvyiAK2FNQ6',
32-
tree: '9PHhh7dJqdWnmjwiZEe6bMCFKnRSL436msEhN587adu5',
33-
seq: 540278,
34-
leaf_id: 539880,
35-
},
36-
grouping: [
37-
{
38-
group_key: 'collection',
39-
group_value: 'PEEiTQbMc87HQ9TbXfHWWyW3bKiMExbGmAiMDR6NUiD',
40-
},
41-
],
42-
mutable: true,
43-
burnt: false,
4428
});
29+
t.deepEqual(asset.compression, <DasApiAssetCompression>{
30+
eligible: false,
31+
compressed: true,
32+
data_hash: '29BdgNWxNB1sinkfmWKFQi3zWXRpsotp2FKoZhoqVa9F',
33+
creator_hash: 'FGAvkyrzeEgvGGMfmi6ztGpvybHMYAL9w82nx6wzLVqn',
34+
asset_hash: 'FGWfA5v5SZnpe9r32NEvDyX9hLeVEoBf3GqEkHX6YK9w',
35+
tree: 'J1imb8C8SPzofrtgCxkN4nsKwHevzxgvHGeYBKFEDEmE',
36+
seq: 1,
37+
leaf_id: 0,
38+
});
39+
t.deepEqual(asset.grouping.length, 1);
40+
t.like(asset.grouping[0], {
41+
group_key: 'collection',
42+
group_value: 'Dm1TRVw82roqpfqpzsFxSsWg6a4z3dku6ebVHSHuVo1c',
43+
});
44+
t.deepEqual(asset.mutable, true);
45+
t.deepEqual(asset.burnt, false);
4546
});
4647

4748
test(`it can fetch a regular asset by ID (${endpoint.name})`, async (t) => {
4849
// Given a minted NFT.
4950
const umi = createUmi(endpoint.url);
50-
const assetId = publicKey('5ja3EvVuEu5rXgtYE3LXKG84s7Pmy5siFfYbcopMc2Dx');
51+
const assetId = publicKey('8bFQbnBrzeiYQabEJ1ghy5T7uFpqFzPjUGsVi3SzSMHB');
5152

5253
// When we fetch the asset using its ID.
5354
const asset = await umi.rpc.getAsset(assetId);
@@ -58,20 +59,19 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
5859
id: assetId,
5960
content: {
6061
metadata: {
61-
name: 'Mad Lads #2732',
62+
name: 'Chiaki Azure 55',
6263
},
6364
},
64-
compression: {
65-
compressed: false,
66-
},
67-
grouping: [
68-
{
69-
group_key: 'collection',
70-
group_value: 'J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w',
71-
},
72-
],
73-
mutable: true,
74-
burnt: false,
7565
});
66+
t.like(asset.compression, <DasApiAssetCompression>{
67+
compressed: false,
68+
});
69+
t.deepEqual(asset.grouping.length, 1);
70+
t.like(asset.grouping[0], {
71+
group_key: 'collection',
72+
group_value: '5RT4e9uHUgG9h13cSc3L4YvkDc9qXSznoLaX4Tx8cpWS',
73+
});
74+
t.deepEqual(asset.mutable, true);
75+
t.deepEqual(asset.burnt, false);
7676
});
7777
});

clients/js/test/getAssetProof.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
77
test(`it can fetch the proof of a compressed asset by ID (${endpoint.name})`, async (t) => {
88
// Given a minted NFT on devnet.
99
const umi = createUmi(endpoint.url);
10-
const assetId = publicKey('Ez6ezCMkRaUkWS5v6WVcP7uuCWiKadr3W2dHFkoZmteW');
10+
const assetId = publicKey('GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA');
1111

1212
// When we fetch the proof of the asset using its ID.
1313
const asset = await umi.rpc.getAssetProof(assetId);
1414

1515
// Then we expect the following data.
1616
t.like(asset, <GetAssetProofRpcResponse>{
17-
root: 'EFCPJ6uVgvwrCgAK3zxYv5xfFNmvSFNfGguQBLjRdDf',
17+
root: 'ATo9owW1JofdTjhZNgMdYx8uS82mkExCSwCTvoyfTxmD',
1818
proof: [
19-
'11111111111111111111111111111111',
20-
'Cf5tmmFZ4D31tviuJezHdFLf5WF7yFvzfxNyftKsqTwr',
19+
'7NCJtYyFmeG82fXeSW2DRfeTvitKeCs7e7hfAUowQtw5',
20+
'8QoG5BnZH9RVz2qLsKPEQ5jnAaCBu3kdRd9Hf4PgSwx9',
2121
'DAbAU9srHpEUogXWuhy5VZ7g8UX9STymELtndcx1xgP1',
22-
'6DVZtacK87UT6bTCLc9MLNJCHqAaySsFSjeGEXymMUh',
22+
'3HCYqQRcQSChEuAw1ybNYHibrTNNjzbYzm56cmEmivB6',
2323
'GSz87YKd3YoZWcEKhnjSsYJwv8o5aWGdBdGGYUphRfTh',
2424
],
25-
node_index: 40,
26-
leaf: 'ADh1Pe7CPB6JUTiPzHwoL1nJTDJA8zxeDMGPC5gYqSHE',
27-
tree_id: '5wu82msJUAs4WWx3XtNMD5u7nuJSnfJMratppsZ6kL27',
25+
node_index: 32,
26+
leaf: 'FGWfA5v5SZnpe9r32NEvDyX9hLeVEoBf3GqEkHX6YK9w',
27+
tree_id: 'J1imb8C8SPzofrtgCxkN4nsKwHevzxgvHGeYBKFEDEmE',
2828
});
2929
});
3030
});

0 commit comments

Comments
 (0)