-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathparse-nft.ts
More file actions
69 lines (66 loc) · 1.73 KB
/
parse-nft.ts
File metadata and controls
69 lines (66 loc) · 1.73 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { hexToBin } from '../format/format.js';
import type {
AuthenticationProgramCommon,
AuthenticationProgramStateCommon,
AuthenticationVirtualMachine,
Output,
ResolvedTransactionCommon,
} from '../lib.js';
import { createVirtualMachineBCHCHIPs } from '../vm/instruction-sets/bch/chips/bch-chips-vm.js';
export type VMCreator = () => AuthenticationVirtualMachine<
ResolvedTransactionCommon,
AuthenticationProgramCommon,
AuthenticationProgramStateCommon
>;
/**
* Returns the altstack as a result of parsing the NFT's commitment using the
* provided bytecode.
*
* @param utxo - the NFT to parse
* @param bytecode - the bytecode as hex string
* @param createVirtualMachine - a function that returns an {@link AuthenticationVirtualMachine}
*/
export const parseNft = (
utxo: Output,
bytecode: string,
createVirtualMachine?: VMCreator,
): Uint8Array[] => {
const vm = createVirtualMachine
? createVirtualMachine()
: createVirtualMachineBCHCHIPs();
const { alternateStack } = vm.evaluate({
inputIndex: 1,
sourceOutputs: [
utxo,
{
lockingBytecode: hexToBin(bytecode),
valueSatoshis: BigInt(0),
},
],
transaction: {
inputs: [
{
outpointIndex: 0,
outpointTransactionHash: hexToBin(''),
sequenceNumber: 0,
unlockingBytecode: hexToBin(''),
},
{
outpointIndex: 0,
outpointTransactionHash: hexToBin(''),
sequenceNumber: 0,
unlockingBytecode: hexToBin('51'),
},
],
locktime: 0,
outputs: [
{
lockingBytecode: hexToBin('6a'),
valueSatoshis: BigInt(0),
},
],
version: 2,
},
});
return alternateStack;
};