/
verify.ts
49 lines (44 loc) · 1.15 KB
/
verify.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import "./env";
import assert from "assert";
import fs from "fs";
import { MetalServiceV2, SymbolService } from "metal-on-symbol";
// Edit here -------------
const nodeUrl = process.env.TEST_NODE_URL;
const metalId = process.argv[2];
const payloadFilePath = process.argv[3];
// -----------------------
assert(payloadFilePath);
const payload = fs.readFileSync(payloadFilePath);
assert(nodeUrl);
const symbolService = new SymbolService({ node_url: nodeUrl });
const metalService = new MetalServiceV2(symbolService);
const verifyMetal = async (
metalId: string,
payload: Uint8Array,
) => {
const {
metadataType: type,
sourceAddress,
targetAddress,
targetId,
scopedMetadataKey: key,
} = (await metalService.getFirstChunk(metalId)).metadataEntry;
const { mismatches } = await metalService.verify(
payload,
type,
sourceAddress,
targetAddress,
key,
targetId,
);
return mismatches === 0;
};
verifyMetal(
metalId,
payload,
).then((result) => {
console.log(`Verified! result=${result}`);
}).catch((e) => {
console.error(e);
process.exit(1);
});