dash-platform-sdk 1.4.0 → 1.5.0-dev.10
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/README.md +16 -15
- package/bundle.min.js +1 -21
- package/package.json +4 -3
- package/proto/generated/platform.client.d.ts +110 -0
- package/proto/generated/platform.client.js +89 -12
- package/proto/generated/platform.d.ts +1671 -0
- package/proto/generated/platform.js +3381 -1
- package/src/DashPlatformSDK.d.ts +2 -0
- package/src/DashPlatformSDK.js +3 -0
- package/src/constants.d.ts +2 -1
- package/src/constants.js +2 -1
- package/src/identities/createStateTransition.js +2 -2
- package/src/keyPair/index.d.ts +87 -0
- package/src/keyPair/index.js +128 -0
- package/src/node/{epochs.d.ts → epochInfos.d.ts} +1 -1
- package/src/node/{epochs.js → epochInfos.js} +1 -1
- package/src/node/finalizedEpochInfos.d.ts +21 -0
- package/src/node/finalizedEpochInfos.js +54 -0
- package/src/node/index.d.ts +9 -1
- package/src/node/index.js +11 -1
- package/src/platformAddresses/createStateTransition.d.ts +12 -0
- package/src/platformAddresses/createStateTransition.js +62 -0
- package/src/platformAddresses/getAddressesBranchState.d.ts +3 -0
- package/src/platformAddresses/getAddressesBranchState.js +21 -0
- package/src/platformAddresses/getAddressesTrunkState.d.ts +3 -0
- package/src/platformAddresses/getAddressesTrunkState.js +33 -0
- package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +3 -0
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +38 -0
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +3 -0
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +37 -0
- package/src/platformAddresses/index.d.ts +63 -2
- package/src/platformAddresses/index.js +76 -0
- package/src/shielded/createStateTransition.d.ts +3 -0
- package/src/shielded/createStateTransition.js +60 -0
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -0
- package/src/shielded/getMostRecentShieldedAnchor.js +36 -0
- package/src/shielded/getShieldedAnchors.d.ts +2 -0
- package/src/shielded/getShieldedAnchors.js +36 -0
- package/src/shielded/getShieldedEncryptedNotes.d.ts +3 -0
- package/src/shielded/getShieldedEncryptedNotes.js +43 -0
- package/src/shielded/getShieldedNotesCount.d.ts +2 -0
- package/src/shielded/getShieldedNotesCount.js +36 -0
- package/src/shielded/getShieldedNullifiers.d.ts +3 -0
- package/src/shielded/getShieldedNullifiers.js +40 -0
- package/src/shielded/getShieldedPoolState.d.ts +2 -0
- package/src/shielded/getShieldedPoolState.js +36 -0
- package/src/shielded/index.d.ts +131 -0
- package/src/shielded/index.js +188 -0
- package/src/utils/verifyTenderdashProof.js +3 -0
- package/test/unit/Identity.spec.js +1 -1
- package/test/unit/KeyPair.spec.js +80 -0
- package/test/unit/Node.spec.js +6 -0
- package/test/unit/PlatformAddress.spec.js +155 -1
- package/test/unit/Shielded.spec.d.ts +1 -0
- package/test/unit/Shielded.spec.js +237 -0
- package/types.d.ts +153 -2
- package/types.js +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { verifyRecentAddressBalanceChanges } from 'pshenmic-dpp';
|
|
2
|
+
import { GetRecentAddressBalanceChangesRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
export async function getRecentAddressBalanceChanges(grpcPool, startHeight, startHeightExclusive = false) {
|
|
8
|
+
const getRecentAddressBalanceChangesRequest = GetRecentAddressBalanceChangesRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
startHeight: startHeight.toString(),
|
|
13
|
+
prove: true,
|
|
14
|
+
startHeightExclusive
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getRecentAddressBalanceChanges(getRecentAddressBalanceChangesRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
const { rootHash, blocks } = verifyRecentAddressBalanceChanges(proof.grovedbProof, startHeight, startHeightExclusive, undefined, true, LATEST_PLATFORM_VERSION);
|
|
32
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
33
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
34
|
+
if (!verify) {
|
|
35
|
+
throw new Error('Failed to verify query');
|
|
36
|
+
}
|
|
37
|
+
return blocks;
|
|
38
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { CompactedBlockAddressBalanceChanges } from 'pshenmic-dpp';
|
|
3
|
+
export declare function getRecentCompactedAddressBalanceChanges(grpcPool: GRPCConnectionPool, startBlockHeight: bigint): Promise<CompactedBlockAddressBalanceChanges[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { verifyRecentCompactedAddressBalanceChanges } from 'pshenmic-dpp';
|
|
2
|
+
import { GetRecentCompactedAddressBalanceChangesRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
export async function getRecentCompactedAddressBalanceChanges(grpcPool, startBlockHeight) {
|
|
8
|
+
const getRecentCompactedAddressBalanceChangesRequest = GetRecentCompactedAddressBalanceChangesRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
startBlockHeight: startBlockHeight.toString(),
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getRecentCompactedAddressBalanceChanges(getRecentCompactedAddressBalanceChangesRequest);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, ranges } = verifyRecentCompactedAddressBalanceChanges(proof.grovedbProof, startBlockHeight, undefined, LATEST_PLATFORM_VERSION);
|
|
31
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
32
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
33
|
+
if (!verify) {
|
|
34
|
+
throw new Error('Failed to verify query');
|
|
35
|
+
}
|
|
36
|
+
return ranges;
|
|
37
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
|
-
import { PlatformAddressInfo } from '../../types.js';
|
|
2
|
+
import { BlockAddressBalanceChanges, CompactedBlockAddressBalanceChanges, PlatformAddressLike, StateTransitionWASM, VerifiedAddressesBranchState } from 'pshenmic-dpp';
|
|
3
|
+
import { PlatformAddressesTrunkState, PlatformAddressInfo, PlatformAddressTransitionParamsMap, PlatformAddressTransitionType } from '../../types.js';
|
|
4
4
|
export declare class PlatformAddressesController {
|
|
5
5
|
/** @ignore **/
|
|
6
6
|
grpcPool: GRPCConnectionPool;
|
|
@@ -19,4 +19,65 @@ export declare class PlatformAddressesController {
|
|
|
19
19
|
* @return {Promise<PlatformAddressInfo[]>}
|
|
20
20
|
*/
|
|
21
21
|
getAddressesInfos(addresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Makes a query for the trunk chunk of the address funds tree, used as the entry point
|
|
24
|
+
* for client-side sync of the address funds state
|
|
25
|
+
*
|
|
26
|
+
* Returns the verified trunk state (elements, leaf keys and helpers for descending into
|
|
27
|
+
* branches) along with the response metadata, whose height is the checkpoint height for
|
|
28
|
+
* subsequent branch queries
|
|
29
|
+
*
|
|
30
|
+
* @return {Promise<PlatformAddressesTrunkState>}
|
|
31
|
+
*/
|
|
32
|
+
getAddressesTrunkState(): Promise<PlatformAddressesTrunkState>;
|
|
33
|
+
/**
|
|
34
|
+
* Makes a query for a branch chunk of the address funds tree at the given key and depth,
|
|
35
|
+
* anchored to the checkpoint height returned by the trunk state query
|
|
36
|
+
*
|
|
37
|
+
* The branch proof carries no root hash of its own - it is verified against
|
|
38
|
+
* expectedRootHash, the hash the parent trunk (or branch) reported for this key
|
|
39
|
+
* via its leaf info
|
|
40
|
+
*
|
|
41
|
+
* @param key {Uint8Array} key that was navigated to in the tree
|
|
42
|
+
* @param depth {number} depth of the branch to return
|
|
43
|
+
* @param checkpointHeight {bigint} block height from the trunk response metadata
|
|
44
|
+
* @param expectedRootHash {Uint8Array} hash reported for this key by the parent trunk or branch
|
|
45
|
+
* @return {Promise<VerifiedAddressesBranchState>}
|
|
46
|
+
*/
|
|
47
|
+
getAddressesBranchState(key: Uint8Array, depth: number, checkpointHeight: bigint, expectedRootHash: Uint8Array): Promise<VerifiedAddressesBranchState>;
|
|
48
|
+
/**
|
|
49
|
+
* Makes a query for recent address balance changes starting from the given block height,
|
|
50
|
+
* returns an array of per-block change sets
|
|
51
|
+
*
|
|
52
|
+
* @param startHeight {bigint} block height to start from
|
|
53
|
+
* @param startHeightExclusive {boolean} [startHeightExclusive=false] use exclusive start (RangeAfter) instead of inclusive (RangeFrom)
|
|
54
|
+
* @return {Promise<BlockAddressBalanceChanges[]>}
|
|
55
|
+
*/
|
|
56
|
+
getRecentAddressBalanceChanges(startHeight: bigint, startHeightExclusive?: boolean): Promise<BlockAddressBalanceChanges[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Makes a query for recent compacted address balance changes starting from the given
|
|
59
|
+
* block height, returns an array of compacted (block range) change sets
|
|
60
|
+
*
|
|
61
|
+
* @param startBlockHeight {bigint} block height to start from
|
|
62
|
+
* @return {Promise<CompactedBlockAddressBalanceChanges[]>}
|
|
63
|
+
*/
|
|
64
|
+
getRecentCompactedAddressBalanceChanges(startBlockHeight: bigint): Promise<CompactedBlockAddressBalanceChanges[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Helper function for creating {StateTransitionWASM} for Platform Address transitions
|
|
67
|
+
*
|
|
68
|
+
* Unlike identity transitions (which are signed after construction), address transitions carry
|
|
69
|
+
* their signature material as constructor input (the `inputWitness` param, and a `signature`
|
|
70
|
+
* setter on the asset-lock variant), so this builder is pure and only assembles the transition
|
|
71
|
+
* from already-built params - producing witnesses stays the caller's responsibility.
|
|
72
|
+
*
|
|
73
|
+
* Please refer to PlatformAddress.spec.ts or README for example commands
|
|
74
|
+
*
|
|
75
|
+
* @param type {string} type of transition, must be a one of ('identityCreditTransferToAddresses' |
|
|
76
|
+
* 'identityCreateFromAddresses' | 'identityTopUpFromAddresses' | 'addressFundsTransfer' |
|
|
77
|
+
* 'addressFundingFromAssetLock' | 'addressCreditWithdrawal')
|
|
78
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
79
|
+
*
|
|
80
|
+
* @return {StateTransitionWASM}
|
|
81
|
+
*/
|
|
82
|
+
createStateTransition<K extends PlatformAddressTransitionType>(type: K, params: PlatformAddressTransitionParamsMap[K]): StateTransitionWASM;
|
|
22
83
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { getAddressInfo } from './getAddressInfo.js';
|
|
2
2
|
import { getAddressesInfos } from './getAddressesInfos.js';
|
|
3
|
+
import { getAddressesTrunkState } from './getAddressesTrunkState.js';
|
|
4
|
+
import { getAddressesBranchState } from './getAddressesBranchState.js';
|
|
5
|
+
import { getRecentAddressBalanceChanges } from './getRecentAddressBalanceChanges.js';
|
|
6
|
+
import { getRecentCompactedAddressBalanceChanges } from './getRecentCompactedAddressBalanceChanges.js';
|
|
7
|
+
import createStateTransition from './createStateTransition.js';
|
|
3
8
|
export class PlatformAddressesController {
|
|
4
9
|
/** @ignore **/
|
|
5
10
|
grpcPool;
|
|
@@ -24,4 +29,75 @@ export class PlatformAddressesController {
|
|
|
24
29
|
async getAddressesInfos(addresses) {
|
|
25
30
|
return await getAddressesInfos(this.grpcPool, addresses);
|
|
26
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Makes a query for the trunk chunk of the address funds tree, used as the entry point
|
|
34
|
+
* for client-side sync of the address funds state
|
|
35
|
+
*
|
|
36
|
+
* Returns the verified trunk state (elements, leaf keys and helpers for descending into
|
|
37
|
+
* branches) along with the response metadata, whose height is the checkpoint height for
|
|
38
|
+
* subsequent branch queries
|
|
39
|
+
*
|
|
40
|
+
* @return {Promise<PlatformAddressesTrunkState>}
|
|
41
|
+
*/
|
|
42
|
+
async getAddressesTrunkState() {
|
|
43
|
+
return await getAddressesTrunkState(this.grpcPool);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Makes a query for a branch chunk of the address funds tree at the given key and depth,
|
|
47
|
+
* anchored to the checkpoint height returned by the trunk state query
|
|
48
|
+
*
|
|
49
|
+
* The branch proof carries no root hash of its own - it is verified against
|
|
50
|
+
* expectedRootHash, the hash the parent trunk (or branch) reported for this key
|
|
51
|
+
* via its leaf info
|
|
52
|
+
*
|
|
53
|
+
* @param key {Uint8Array} key that was navigated to in the tree
|
|
54
|
+
* @param depth {number} depth of the branch to return
|
|
55
|
+
* @param checkpointHeight {bigint} block height from the trunk response metadata
|
|
56
|
+
* @param expectedRootHash {Uint8Array} hash reported for this key by the parent trunk or branch
|
|
57
|
+
* @return {Promise<VerifiedAddressesBranchState>}
|
|
58
|
+
*/
|
|
59
|
+
async getAddressesBranchState(key, depth, checkpointHeight, expectedRootHash) {
|
|
60
|
+
return await getAddressesBranchState(this.grpcPool, key, depth, checkpointHeight, expectedRootHash);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Makes a query for recent address balance changes starting from the given block height,
|
|
64
|
+
* returns an array of per-block change sets
|
|
65
|
+
*
|
|
66
|
+
* @param startHeight {bigint} block height to start from
|
|
67
|
+
* @param startHeightExclusive {boolean} [startHeightExclusive=false] use exclusive start (RangeAfter) instead of inclusive (RangeFrom)
|
|
68
|
+
* @return {Promise<BlockAddressBalanceChanges[]>}
|
|
69
|
+
*/
|
|
70
|
+
async getRecentAddressBalanceChanges(startHeight, startHeightExclusive = false) {
|
|
71
|
+
return await getRecentAddressBalanceChanges(this.grpcPool, startHeight, startHeightExclusive);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Makes a query for recent compacted address balance changes starting from the given
|
|
75
|
+
* block height, returns an array of compacted (block range) change sets
|
|
76
|
+
*
|
|
77
|
+
* @param startBlockHeight {bigint} block height to start from
|
|
78
|
+
* @return {Promise<CompactedBlockAddressBalanceChanges[]>}
|
|
79
|
+
*/
|
|
80
|
+
async getRecentCompactedAddressBalanceChanges(startBlockHeight) {
|
|
81
|
+
return await getRecentCompactedAddressBalanceChanges(this.grpcPool, startBlockHeight);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Helper function for creating {StateTransitionWASM} for Platform Address transitions
|
|
85
|
+
*
|
|
86
|
+
* Unlike identity transitions (which are signed after construction), address transitions carry
|
|
87
|
+
* their signature material as constructor input (the `inputWitness` param, and a `signature`
|
|
88
|
+
* setter on the asset-lock variant), so this builder is pure and only assembles the transition
|
|
89
|
+
* from already-built params - producing witnesses stays the caller's responsibility.
|
|
90
|
+
*
|
|
91
|
+
* Please refer to PlatformAddress.spec.ts or README for example commands
|
|
92
|
+
*
|
|
93
|
+
* @param type {string} type of transition, must be a one of ('identityCreditTransferToAddresses' |
|
|
94
|
+
* 'identityCreateFromAddresses' | 'identityTopUpFromAddresses' | 'addressFundsTransfer' |
|
|
95
|
+
* 'addressFundingFromAssetLock' | 'addressCreditWithdrawal')
|
|
96
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
97
|
+
*
|
|
98
|
+
* @return {StateTransitionWASM}
|
|
99
|
+
*/
|
|
100
|
+
createStateTransition(type, params) {
|
|
101
|
+
return createStateTransition(type, params);
|
|
102
|
+
}
|
|
27
103
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ShieldedBuilderWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { ShieldedTransitionParamsMap, ShieldedTransitionType } from '../../types.js';
|
|
3
|
+
export default function createStateTransition<K extends ShieldedTransitionType>(builder: ShieldedBuilderWASM, type: K, params: ShieldedTransitionParamsMap[K]): Promise<StateTransitionWASM>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IdentityCreateFromShieldedPoolTransitionWASM, ShieldedBuilderWASM, ShieldedWithdrawalResultWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
|
+
const shieldedTransitionsMap = {
|
|
4
|
+
shield: {
|
|
5
|
+
method: ShieldedBuilderWASM.prototype.shield,
|
|
6
|
+
arguments: ['recipient', 'shieldAmount', 'inputs', 'privateKeys', 'feeStrategy', 'userFeeIncrease', 'memo'],
|
|
7
|
+
optionalArguments: ['senderOvk']
|
|
8
|
+
},
|
|
9
|
+
shieldFromAssetLock: {
|
|
10
|
+
method: ShieldedBuilderWASM.prototype.shieldFromAssetLock,
|
|
11
|
+
arguments: ['recipient', 'shieldAmount', 'assetLockProof', 'privateKey', 'memo', 'dummyOutputs'],
|
|
12
|
+
optionalArguments: ['senderOvk', 'surplusOutput']
|
|
13
|
+
},
|
|
14
|
+
shieldedWithdrawal: {
|
|
15
|
+
method: ShieldedBuilderWASM.prototype.shieldedWithdrawal,
|
|
16
|
+
arguments: ['spends', 'withdrawalAmount', 'outputScript', 'coreFeePerByte', 'pooling', 'changeAddress', 'seed', 'coinType', 'account', 'anchor', 'memo'],
|
|
17
|
+
optionalArguments: []
|
|
18
|
+
},
|
|
19
|
+
unshield: {
|
|
20
|
+
method: ShieldedBuilderWASM.prototype.unshield,
|
|
21
|
+
arguments: ['spends', 'outputAddress', 'unshieldAmount', 'changeAddress', 'seed', 'coinType', 'account', 'anchor', 'memo'],
|
|
22
|
+
optionalArguments: []
|
|
23
|
+
},
|
|
24
|
+
shieldedTransfer: {
|
|
25
|
+
method: ShieldedBuilderWASM.prototype.shieldedTransfer,
|
|
26
|
+
arguments: ['spends', 'recipient', 'transferAmount', 'changeAddress', 'seed', 'coinType', 'account', 'anchor', 'memo'],
|
|
27
|
+
optionalArguments: []
|
|
28
|
+
},
|
|
29
|
+
shieldedTransferMulti: {
|
|
30
|
+
method: ShieldedBuilderWASM.prototype.shieldedTransferMulti,
|
|
31
|
+
arguments: ['spends', 'outputs', 'changeAddress', 'seed', 'coinType', 'account', 'anchor'],
|
|
32
|
+
optionalArguments: []
|
|
33
|
+
},
|
|
34
|
+
identityCreateFromShieldedPool: {
|
|
35
|
+
method: ShieldedBuilderWASM.prototype.identityCreateFromShieldedPool,
|
|
36
|
+
arguments: ['publicKeys', 'privateKeys', 'denomination', 'sendToAddressOnCreationFailure', 'spends', 'changeAddress', 'seed', 'coinType', 'account', 'anchor', 'memo'],
|
|
37
|
+
optionalArguments: []
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export default async function createStateTransition(builder, type, params) {
|
|
41
|
+
const { method: builderMethod, arguments: classArguments, optionalArguments } = shieldedTransitionsMap[type];
|
|
42
|
+
if (builderMethod == null) {
|
|
43
|
+
throw new Error(`Unimplemented shielded transition type: ${type}`);
|
|
44
|
+
}
|
|
45
|
+
const [missingArgument] = classArguments
|
|
46
|
+
.filter((classArgument) => params[classArgument] == null);
|
|
47
|
+
if (missingArgument != null) {
|
|
48
|
+
throw new Error(`Shielded transition param "${missingArgument}" is missing`);
|
|
49
|
+
}
|
|
50
|
+
const transitionParams = classArguments.concat(optionalArguments).map((classArgument) => params[classArgument]);
|
|
51
|
+
const result = await builderMethod.apply(builder, [...transitionParams, params.platformVersion ?? LATEST_PLATFORM_VERSION]);
|
|
52
|
+
if (result instanceof StateTransitionWASM) {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
if (result instanceof ShieldedWithdrawalResultWASM) {
|
|
56
|
+
return result.stateTransition;
|
|
57
|
+
}
|
|
58
|
+
const { denomination, sendToAddressOnCreationFailure } = params;
|
|
59
|
+
return new IdentityCreateFromShieldedPoolTransitionWASM(result.publicKeys, denomination, result.actions, result.anchor, result.proof, result.bindingsSignature, sendToAddressOnCreationFailure, result.identityId).toStateTransition();
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GetMostRecentShieldedAnchorRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { verifyMostRecentShieldedAnchorProof } from "pshenmic-dpp";
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from "../constants.js";
|
|
4
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
5
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
6
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
+
export default async function getMostRecentShieldedAnchor(grpcPool) {
|
|
8
|
+
const getMostRecentShieldedAnchorRequest = GetMostRecentShieldedAnchorRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
prove: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const { response } = await grpcPool.getClient().getMostRecentShieldedAnchor(getMostRecentShieldedAnchorRequest);
|
|
17
|
+
const { version } = response;
|
|
18
|
+
if (version.oneofKind !== 'v0') {
|
|
19
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
20
|
+
}
|
|
21
|
+
const { v0 } = version;
|
|
22
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
23
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
24
|
+
}
|
|
25
|
+
const { result: { proof }, metadata } = v0;
|
|
26
|
+
if (metadata == null) {
|
|
27
|
+
throw new Error('Metadata not found');
|
|
28
|
+
}
|
|
29
|
+
const { rootHash, anchor } = verifyMostRecentShieldedAnchorProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION);
|
|
30
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
31
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
32
|
+
if (!verify) {
|
|
33
|
+
throw new Error('Failed to verify query');
|
|
34
|
+
}
|
|
35
|
+
return anchor;
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GetShieldedAnchorsRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { verifyShieldedAnchorsProof } from "pshenmic-dpp";
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from "../constants.js";
|
|
4
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
5
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
6
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
+
export default async function getShieldedAnchors(grpcPool) {
|
|
8
|
+
const getShieldedAnchorsRequest = GetShieldedAnchorsRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
prove: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const { response } = await grpcPool.getClient().getShieldedAnchors(getShieldedAnchorsRequest);
|
|
17
|
+
const { version } = response;
|
|
18
|
+
if (version.oneofKind !== 'v0') {
|
|
19
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
20
|
+
}
|
|
21
|
+
const { v0 } = version;
|
|
22
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
23
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
24
|
+
}
|
|
25
|
+
const { result: { proof }, metadata } = v0;
|
|
26
|
+
if (metadata == null) {
|
|
27
|
+
throw new Error('Metadata not found');
|
|
28
|
+
}
|
|
29
|
+
const { rootHash, anchors } = verifyShieldedAnchorsProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION);
|
|
30
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
31
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
32
|
+
if (!verify) {
|
|
33
|
+
throw new Error('Failed to verify query');
|
|
34
|
+
}
|
|
35
|
+
return anchors;
|
|
36
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GetShieldedEncryptedNotesRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { verifyShieldedEncryptedNotesProof } from "pshenmic-dpp";
|
|
3
|
+
import { LATEST_PLATFORM_VERSION, SHIELDED_MAX_NOTES_PER_QUERY } from "../constants.js";
|
|
4
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
5
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
6
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
+
export default async function getShieldedEncryptedNotes(grpcPool, startIndex, count) {
|
|
8
|
+
const getShieldedEncryptedNotesRequest = GetShieldedEncryptedNotesRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
startIndex: startIndex.toString(),
|
|
13
|
+
count,
|
|
14
|
+
prove: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getShieldedEncryptedNotes(getShieldedEncryptedNotesRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
const { rootHash, notes } = verifyShieldedEncryptedNotesProof(proof.grovedbProof, startIndex, count, SHIELDED_MAX_NOTES_PER_QUERY, true, LATEST_PLATFORM_VERSION);
|
|
32
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
33
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
34
|
+
if (!verify) {
|
|
35
|
+
throw new Error('Failed to verify query');
|
|
36
|
+
}
|
|
37
|
+
return notes.map(note => ({
|
|
38
|
+
nullifier: note.nullifier,
|
|
39
|
+
cmx: note.cmx,
|
|
40
|
+
encryptedNote: note.encryptedNote,
|
|
41
|
+
cvNet: note.cvNet
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GetShieldedNotesCountRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { verifyShieldedNotesCountProof } from "pshenmic-dpp";
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from "../constants.js";
|
|
4
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
5
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
6
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
+
export default async function getShieldedNotesCount(grpcPool) {
|
|
8
|
+
const getShieldedNotesCountRequest = GetShieldedNotesCountRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
prove: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const { response } = await grpcPool.getClient().getShieldedNotesCount(getShieldedNotesCountRequest);
|
|
17
|
+
const { version } = response;
|
|
18
|
+
if (version.oneofKind !== 'v0') {
|
|
19
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
20
|
+
}
|
|
21
|
+
const { v0 } = version;
|
|
22
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
23
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
24
|
+
}
|
|
25
|
+
const { result: { proof }, metadata } = v0;
|
|
26
|
+
if (metadata == null) {
|
|
27
|
+
throw new Error('Metadata not found');
|
|
28
|
+
}
|
|
29
|
+
const { rootHash, count } = verifyShieldedNotesCountProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION);
|
|
30
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
31
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
32
|
+
if (!verify) {
|
|
33
|
+
throw new Error('Failed to verify query');
|
|
34
|
+
}
|
|
35
|
+
return count;
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GetShieldedNullifiersRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { verifyShieldedNullifiersProof } from "pshenmic-dpp";
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from "../constants.js";
|
|
4
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
5
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
6
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
+
export default async function getShieldedNullifiers(grpcPool, nullifiers) {
|
|
8
|
+
const getShieldedNullifiersRequest = GetShieldedNullifiersRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
nullifiers,
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getShieldedNullifiers(getShieldedNullifiersRequest);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, nullifiers: nullifiersStatuses } = verifyShieldedNullifiersProof(proof.grovedbProof, nullifiers, true, LATEST_PLATFORM_VERSION);
|
|
31
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
32
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
33
|
+
if (!verify) {
|
|
34
|
+
throw new Error('Failed to verify query');
|
|
35
|
+
}
|
|
36
|
+
return nullifiersStatuses.map(entry => ({
|
|
37
|
+
nullifier: entry.nullifier,
|
|
38
|
+
isSpent: entry.isSpent
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GetShieldedPoolStateRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { getQuorumPublicKey } from "../utils/getQuorumPublicKey.js";
|
|
3
|
+
import bytesToHex from "../utils/bytesToHex.js";
|
|
4
|
+
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
5
|
+
import { verifyShieldedPoolStateProof } from "pshenmic-dpp";
|
|
6
|
+
import { LATEST_PLATFORM_VERSION } from "../constants.js";
|
|
7
|
+
export default async function getShieldedPoolState(grpcPool) {
|
|
8
|
+
const getShieldedPoolStateRequest = GetShieldedPoolStateRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
prove: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const { response } = await grpcPool.getClient().getShieldedPoolState(getShieldedPoolStateRequest);
|
|
17
|
+
const { version } = response;
|
|
18
|
+
if (version.oneofKind !== 'v0') {
|
|
19
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
20
|
+
}
|
|
21
|
+
const { v0 } = version;
|
|
22
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
23
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
24
|
+
}
|
|
25
|
+
const { result: { proof }, metadata } = v0;
|
|
26
|
+
if (metadata == null) {
|
|
27
|
+
throw new Error('Metadata not found');
|
|
28
|
+
}
|
|
29
|
+
const { rootHash, totalBalance } = verifyShieldedPoolStateProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION);
|
|
30
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
31
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
32
|
+
if (!verify) {
|
|
33
|
+
throw new Error('Failed to verify query');
|
|
34
|
+
}
|
|
35
|
+
return totalBalance;
|
|
36
|
+
}
|