dash-platform-sdk 1.5.0-dev.2 → 1.5.0-dev.4
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 +14 -13
- package/bundle.min.js +1 -21
- package/package.json +4 -3
- package/src/platformAddresses/createStateTransition.d.ts +12 -0
- package/src/platformAddresses/createStateTransition.js +62 -0
- package/src/platformAddresses/index.d.ts +20 -2
- package/src/platformAddresses/index.js +21 -0
- package/src/shielded/createStateTransition.d.ts +1 -1
- package/src/shielded/createStateTransition.js +2 -2
- package/src/shielded/index.d.ts +3 -3
- package/src/shielded/index.js +6 -5
- package/test/unit/PlatformAddress.spec.js +111 -0
- package/test/unit/Shielded.spec.js +17 -16
- package/types.d.ts +59 -2
- package/types.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-platform-sdk",
|
|
3
|
-
"version": "1.5.0-dev.
|
|
3
|
+
"version": "1.5.0-dev.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Lightweight SDK for accessing Dash Platform blockchain",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"@babel/preset-env": "^7.28.0",
|
|
26
26
|
"@babel/preset-typescript": "^7.27.1",
|
|
27
27
|
"@protobuf-ts/plugin": "^2.11.1",
|
|
28
|
-
"@rollup/plugin-
|
|
28
|
+
"@rollup/plugin-alias": "^6.0.0",
|
|
29
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
29
30
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
30
31
|
"@rollup/plugin-terser": "^0.4.4",
|
|
31
32
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
@@ -59,6 +60,6 @@
|
|
|
59
60
|
"@scure/bip39": "^2.0.0",
|
|
60
61
|
"@scure/btc-signer": "^2.0.1",
|
|
61
62
|
"cbor-x": "^1.6.0",
|
|
62
|
-
"pshenmic-dpp": "2.0.0-dev.
|
|
63
|
+
"pshenmic-dpp": "2.0.0-dev.24"
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { PlatformAddressTransitionParamsMap, PlatformAddressTransitionType } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function that assembles a {StateTransitionWASM} for Platform Address transitions
|
|
5
|
+
* out of already-built params. The builder is pure: it does not sign, broadcast or
|
|
6
|
+
* mutate the passed params. Producing witnesses / signatures stays the caller's
|
|
7
|
+
* responsibility (they are passed in via the `inputWitness` / `signature` params).
|
|
8
|
+
*
|
|
9
|
+
* @param type {string} type of transition
|
|
10
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
11
|
+
*/
|
|
12
|
+
export default function createStateTransition<K extends PlatformAddressTransitionType>(type: K, params: PlatformAddressTransitionParamsMap[K]): StateTransitionWASM;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { IdentityCreditTransferToAddressesTransitionWASM, IdentityCreateFromAddressesTransitionWASM, IdentityTopUpFromAddressesTransitionWASM, AddressFundsTransferTransitionWASM, AddressFundingFromAssetLockTransitionWASM, AddressCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
const platformAddressTransitionsMap = {
|
|
3
|
+
identityCreditTransferToAddresses: {
|
|
4
|
+
class: IdentityCreditTransferToAddressesTransitionWASM,
|
|
5
|
+
arguments: ['identityId', 'recipients', 'nonce', 'userFeeIncrease'],
|
|
6
|
+
optionalArguments: ['userFeeIncrease']
|
|
7
|
+
},
|
|
8
|
+
identityCreateFromAddresses: {
|
|
9
|
+
class: IdentityCreateFromAddressesTransitionWASM,
|
|
10
|
+
arguments: ['publicKeys', 'inputs', 'feeStrategy', 'userFeeIncrease', 'inputWitness', 'output'],
|
|
11
|
+
optionalArguments: ['userFeeIncrease', 'output']
|
|
12
|
+
},
|
|
13
|
+
identityTopUpFromAddresses: {
|
|
14
|
+
class: IdentityTopUpFromAddressesTransitionWASM,
|
|
15
|
+
arguments: ['identityId', 'inputs', 'feeStrategy', 'userFeeIncrease', 'inputWitness', 'output'],
|
|
16
|
+
optionalArguments: ['userFeeIncrease', 'output']
|
|
17
|
+
},
|
|
18
|
+
addressFundsTransfer: {
|
|
19
|
+
class: AddressFundsTransferTransitionWASM,
|
|
20
|
+
arguments: ['inputs', 'feeStrategy', 'userFeeIncrease', 'inputWitness', 'outputs'],
|
|
21
|
+
optionalArguments: ['userFeeIncrease']
|
|
22
|
+
},
|
|
23
|
+
addressFundingFromAssetLock: {
|
|
24
|
+
class: AddressFundingFromAssetLockTransitionWASM,
|
|
25
|
+
arguments: ['assetLockProof', 'inputs', 'feeStrategy', 'userFeeIncrease', 'inputWitness', 'outputs'],
|
|
26
|
+
optionalArguments: ['userFeeIncrease']
|
|
27
|
+
},
|
|
28
|
+
addressCreditWithdrawal: {
|
|
29
|
+
class: AddressCreditWithdrawalTransitionWASM,
|
|
30
|
+
arguments: ['inputs', 'feeStrategy', 'coreFeePerByte', 'pooling', 'outputScript', 'userFeeIncrease', 'inputWitness', 'output'],
|
|
31
|
+
optionalArguments: ['userFeeIncrease', 'output']
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Helper function that assembles a {StateTransitionWASM} for Platform Address transitions
|
|
36
|
+
* out of already-built params. The builder is pure: it does not sign, broadcast or
|
|
37
|
+
* mutate the passed params. Producing witnesses / signatures stays the caller's
|
|
38
|
+
* responsibility (they are passed in via the `inputWitness` / `signature` params).
|
|
39
|
+
*
|
|
40
|
+
* @param type {string} type of transition
|
|
41
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
42
|
+
*/
|
|
43
|
+
export default function createStateTransition(type, params) {
|
|
44
|
+
const { class: TransitionClass, arguments: classArguments, optionalArguments } = platformAddressTransitionsMap[type] ?? {};
|
|
45
|
+
if (TransitionClass == null) {
|
|
46
|
+
throw new Error(`Unimplemented transition type: ${type}`);
|
|
47
|
+
}
|
|
48
|
+
const [missingArgument] = classArguments
|
|
49
|
+
.filter((classArgument) => params[classArgument] == null &&
|
|
50
|
+
!optionalArguments.includes(classArgument));
|
|
51
|
+
if (missingArgument != null) {
|
|
52
|
+
throw new Error(`Platform address transition param "${missingArgument}" is missing`);
|
|
53
|
+
}
|
|
54
|
+
// userFeeIncrease is a required positional `number` in every WASM constructor,
|
|
55
|
+
// so coerce a missing value to 0 to keep the positional order intact.
|
|
56
|
+
const transitionParams = classArguments.map((classArgument) => classArgument === 'userFeeIncrease'
|
|
57
|
+
? (params[classArgument] ?? 0)
|
|
58
|
+
: params[classArgument]);
|
|
59
|
+
// @ts-expect-error
|
|
60
|
+
const platformAddressTransition = new TransitionClass(...transitionParams);
|
|
61
|
+
return platformAddressTransition.toStateTransition();
|
|
62
|
+
}
|
|
@@ -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 { PlatformAddressLike, StateTransitionWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { PlatformAddressInfo, PlatformAddressTransitionParamsMap, PlatformAddressTransitionType } from '../../types.js';
|
|
4
4
|
export declare class PlatformAddressesController {
|
|
5
5
|
/** @ignore **/
|
|
6
6
|
grpcPool: GRPCConnectionPool;
|
|
@@ -19,4 +19,22 @@ export declare class PlatformAddressesController {
|
|
|
19
19
|
* @return {Promise<PlatformAddressInfo[]>}
|
|
20
20
|
*/
|
|
21
21
|
getAddressesInfos(addresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Helper function for creating {StateTransitionWASM} for Platform Address transitions
|
|
24
|
+
*
|
|
25
|
+
* Unlike identity transitions (which are signed after construction), address transitions carry
|
|
26
|
+
* their signature material as constructor input (the `inputWitness` param, and a `signature`
|
|
27
|
+
* setter on the asset-lock variant), so this builder is pure and only assembles the transition
|
|
28
|
+
* from already-built params - producing witnesses stays the caller's responsibility.
|
|
29
|
+
*
|
|
30
|
+
* Please refer to PlatformAddress.spec.ts or README for example commands
|
|
31
|
+
*
|
|
32
|
+
* @param type {string} type of transition, must be a one of ('identityCreditTransferToAddresses' |
|
|
33
|
+
* 'identityCreateFromAddresses' | 'identityTopUpFromAddresses' | 'addressFundsTransfer' |
|
|
34
|
+
* 'addressFundingFromAssetLock' | 'addressCreditWithdrawal')
|
|
35
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
36
|
+
*
|
|
37
|
+
* @return {StateTransitionWASM}
|
|
38
|
+
*/
|
|
39
|
+
createStateTransition<K extends PlatformAddressTransitionType>(type: K, params: PlatformAddressTransitionParamsMap[K]): StateTransitionWASM;
|
|
22
40
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getAddressInfo } from './getAddressInfo.js';
|
|
2
2
|
import { getAddressesInfos } from './getAddressesInfos.js';
|
|
3
|
+
import createStateTransition from './createStateTransition.js';
|
|
3
4
|
export class PlatformAddressesController {
|
|
4
5
|
/** @ignore **/
|
|
5
6
|
grpcPool;
|
|
@@ -24,4 +25,24 @@ export class PlatformAddressesController {
|
|
|
24
25
|
async getAddressesInfos(addresses) {
|
|
25
26
|
return await getAddressesInfos(this.grpcPool, addresses);
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Helper function for creating {StateTransitionWASM} for Platform Address transitions
|
|
30
|
+
*
|
|
31
|
+
* Unlike identity transitions (which are signed after construction), address transitions carry
|
|
32
|
+
* their signature material as constructor input (the `inputWitness` param, and a `signature`
|
|
33
|
+
* setter on the asset-lock variant), so this builder is pure and only assembles the transition
|
|
34
|
+
* from already-built params - producing witnesses stays the caller's responsibility.
|
|
35
|
+
*
|
|
36
|
+
* Please refer to PlatformAddress.spec.ts or README for example commands
|
|
37
|
+
*
|
|
38
|
+
* @param type {string} type of transition, must be a one of ('identityCreditTransferToAddresses' |
|
|
39
|
+
* 'identityCreateFromAddresses' | 'identityTopUpFromAddresses' | 'addressFundsTransfer' |
|
|
40
|
+
* 'addressFundingFromAssetLock' | 'addressCreditWithdrawal')
|
|
41
|
+
* @param params {PlatformAddressTransitionParamsMap[K]} params required by that transition type
|
|
42
|
+
*
|
|
43
|
+
* @return {StateTransitionWASM}
|
|
44
|
+
*/
|
|
45
|
+
createStateTransition(type, params) {
|
|
46
|
+
return createStateTransition(type, params);
|
|
47
|
+
}
|
|
27
48
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ShieldedBuilderWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { ShieldedTransitionParamsMap, ShieldedTransitionType } from '../../types.js';
|
|
3
|
-
export default function createStateTransition<K extends ShieldedTransitionType>(builder: ShieldedBuilderWASM, type: K, params: ShieldedTransitionParamsMap[K]): StateTransitionWASM
|
|
3
|
+
export default function createStateTransition<K extends ShieldedTransitionType>(builder: ShieldedBuilderWASM, type: K, params: ShieldedTransitionParamsMap[K]): Promise<StateTransitionWASM>;
|
|
@@ -32,7 +32,7 @@ const shieldedTransitionsMap = {
|
|
|
32
32
|
optionalArguments: []
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
export default function createStateTransition(builder, type, params) {
|
|
35
|
+
export default async function createStateTransition(builder, type, params) {
|
|
36
36
|
const { method: builderMethod, arguments: classArguments, optionalArguments } = shieldedTransitionsMap[type];
|
|
37
37
|
if (builderMethod == null) {
|
|
38
38
|
throw new Error(`Unimplemented shielded transition type: ${type}`);
|
|
@@ -43,7 +43,7 @@ export default function createStateTransition(builder, type, params) {
|
|
|
43
43
|
throw new Error(`Shielded transition param "${missingArgument}" is missing`);
|
|
44
44
|
}
|
|
45
45
|
const transitionParams = classArguments.concat(optionalArguments).map((classArgument) => params[classArgument]);
|
|
46
|
-
const result = builderMethod.apply(builder, [...transitionParams, params.platformVersion ?? LATEST_PLATFORM_VERSION]);
|
|
46
|
+
const result = await builderMethod.apply(builder, [...transitionParams, params.platformVersion ?? LATEST_PLATFORM_VERSION]);
|
|
47
47
|
if (result instanceof StateTransitionWASM) {
|
|
48
48
|
return result;
|
|
49
49
|
}
|
package/src/shielded/index.d.ts
CHANGED
|
@@ -16,14 +16,14 @@ export declare class ShieldedController {
|
|
|
16
16
|
* Set bindings instance of builder
|
|
17
17
|
* Needed for custom builder load, because ShieldedBuilderWASM inits very slow on old hardware
|
|
18
18
|
*/
|
|
19
|
-
init(builder?: ShieldedBuilderWASM): ShieldedBuilderWASM
|
|
19
|
+
init(builder?: ShieldedBuilderWASM): Promise<ShieldedBuilderWASM>;
|
|
20
20
|
/**
|
|
21
21
|
* Lazily constructs and caches a {ShieldedBuilderWASM}. Construction builds
|
|
22
22
|
* the Halo 2 proving key (~seconds), so the instance is created once and reused.
|
|
23
23
|
*
|
|
24
24
|
* @ignore
|
|
25
25
|
*/
|
|
26
|
-
getShieldedBuilder(): ShieldedBuilderWASM
|
|
26
|
+
getShieldedBuilder(): Promise<ShieldedBuilderWASM>;
|
|
27
27
|
/**
|
|
28
28
|
* Retrieves a batch of shielded encrypted notes from the shielded pool,
|
|
29
29
|
* starting from the given note index.
|
|
@@ -126,5 +126,5 @@ export declare class ShieldedController {
|
|
|
126
126
|
*
|
|
127
127
|
* @return {StateTransitionWASM}
|
|
128
128
|
*/
|
|
129
|
-
createStateTransition<K extends ShieldedTransitionType>(type: K, params: ShieldedTransitionParamsMap[K]): StateTransitionWASM
|
|
129
|
+
createStateTransition<K extends ShieldedTransitionType>(type: K, params: ShieldedTransitionParamsMap[K]): Promise<StateTransitionWASM>;
|
|
130
130
|
}
|
package/src/shielded/index.js
CHANGED
|
@@ -23,8 +23,9 @@ export class ShieldedController {
|
|
|
23
23
|
* Set bindings instance of builder
|
|
24
24
|
* Needed for custom builder load, because ShieldedBuilderWASM inits very slow on old hardware
|
|
25
25
|
*/
|
|
26
|
-
init(builder) {
|
|
26
|
+
async init(builder) {
|
|
27
27
|
this.shieldedBuilder = builder ?? new ShieldedBuilderWASM();
|
|
28
|
+
await this.shieldedBuilder.init();
|
|
28
29
|
return this.shieldedBuilder;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
@@ -33,9 +34,9 @@ export class ShieldedController {
|
|
|
33
34
|
*
|
|
34
35
|
* @ignore
|
|
35
36
|
*/
|
|
36
|
-
getShieldedBuilder() {
|
|
37
|
+
async getShieldedBuilder() {
|
|
37
38
|
if (this.shieldedBuilder == null) {
|
|
38
|
-
return this.init();
|
|
39
|
+
return await this.init();
|
|
39
40
|
}
|
|
40
41
|
return this.shieldedBuilder;
|
|
41
42
|
}
|
|
@@ -172,7 +173,7 @@ export class ShieldedController {
|
|
|
172
173
|
*
|
|
173
174
|
* @return {StateTransitionWASM}
|
|
174
175
|
*/
|
|
175
|
-
createStateTransition(type, params) {
|
|
176
|
+
async createStateTransition(type, params) {
|
|
176
177
|
// @ts-expect-error a plain string memo is normalized to ShieldedMemoWASM (empty when omitted)
|
|
177
178
|
params.memo = typeof params.memo === 'string' ? ShieldedMemoWASM.fromString(params.memo) : ShieldedMemoWASM.empty();
|
|
178
179
|
if (type === 'identityCreateFromShieldedPool') {
|
|
@@ -181,6 +182,6 @@ export class ShieldedController {
|
|
|
181
182
|
identityParams.publicKeys = identityParams.publicKeys
|
|
182
183
|
.map(({ id, purpose, securityLevel, keyType, readOnly, data, signature, contractBounds }) => new IdentityPublicKeyInCreationWASM(id, purpose, securityLevel, keyType, readOnly, data, signature, (contractBounds != null) ? new ContractBoundsWASM(contractBounds.dataContractId, contractBounds.documentType) : undefined));
|
|
183
184
|
}
|
|
184
|
-
return createStateTransition(this.getShieldedBuilder(), type, params);
|
|
185
|
+
return await createStateTransition(await this.getShieldedBuilder(), type, params);
|
|
185
186
|
}
|
|
186
187
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AddressFundsFeeStrategyStepWASM, AddressWitnessWASM, AssetLockProofWASM, CoreScriptWASM, IdentityPublicKeyInCreationWASM, InputAddressWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, KeyType, OutPointWASM, PlatformAddressWASM, PrivateKeyWASM, Purpose, SecurityLevel, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { base58 } from '@scure/base';
|
|
1
3
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
2
4
|
let sdk;
|
|
3
5
|
describe('PlatformAddress', () => {
|
|
@@ -19,4 +21,113 @@ describe('PlatformAddress', () => {
|
|
|
19
21
|
const info = await sdk.platformAddresses.getAddressesInfos(addresses);
|
|
20
22
|
expect(info).toHaveLength(addresses.length);
|
|
21
23
|
});
|
|
24
|
+
describe('createStateTransition', () => {
|
|
25
|
+
const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
26
|
+
const addressA = PlatformAddressWASM.fromBech32m('tdash1kzg5azscav69z7m6dfzr9ner0a5vt7pn9ca4sz8d');
|
|
27
|
+
const addressB = PlatformAddressWASM.fromBech32m('tdash1kqr3cxhgel75ru0yrhj5eq8j8jt92m5enqrfajxw');
|
|
28
|
+
const inputs = [new InputAddressWASM(addressA, 0, 100000n)];
|
|
29
|
+
const outputs = [new OutputAddressWASM(addressB, 50000n)];
|
|
30
|
+
const recipients = [new OutputAddressWASM(addressB, 50000n)];
|
|
31
|
+
const nullableOutputs = [new OutputAddressNullableCreditsWASM(addressB)];
|
|
32
|
+
const feeStrategy = [AddressFundsFeeStrategyStepWASM.DeductFromInput(1)];
|
|
33
|
+
const inputWitness = [AddressWitnessWASM.P2PKH(new Uint8Array(65))];
|
|
34
|
+
const output = new OutputAddressWASM(addressA, 10000n);
|
|
35
|
+
const nonce = 1n;
|
|
36
|
+
const privateKey = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
|
|
37
|
+
const publicKeys = [
|
|
38
|
+
new IdentityPublicKeyInCreationWASM(0, Purpose.AUTHENTICATION, SecurityLevel.MASTER, KeyType.ECDSA_SECP256K1, false, privateKey.getPublicKey().bytes())
|
|
39
|
+
];
|
|
40
|
+
const assetLockProof = AssetLockProofWASM.createChainAssetLockProof(1337, new OutPointWASM('61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11', 0));
|
|
41
|
+
const withdrawalAddress = 'yjHVQ3dj37UJwXFmvMTKR9ZVfoJSc3opTD';
|
|
42
|
+
const outputScript = CoreScriptWASM.newP2PKH(base58.decode(withdrawalAddress).slice(1, 21));
|
|
43
|
+
test('should be able to create identityCreditTransferToAddresses', () => {
|
|
44
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('identityCreditTransferToAddresses', {
|
|
45
|
+
identityId, recipients, nonce
|
|
46
|
+
});
|
|
47
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
48
|
+
});
|
|
49
|
+
test('should throw when identityCreditTransferToAddresses is missing recipients', () => {
|
|
50
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
51
|
+
expect(() => sdk.platformAddresses.createStateTransition('identityCreditTransferToAddresses', {
|
|
52
|
+
identityId, nonce
|
|
53
|
+
})).toThrow('Platform address transition param "recipients" is missing');
|
|
54
|
+
});
|
|
55
|
+
test('should be able to create identityCreateFromAddresses', () => {
|
|
56
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('identityCreateFromAddresses', {
|
|
57
|
+
publicKeys, inputs, feeStrategy, inputWitness
|
|
58
|
+
});
|
|
59
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
60
|
+
});
|
|
61
|
+
test('should throw when identityCreateFromAddresses is missing publicKeys', () => {
|
|
62
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
63
|
+
expect(() => sdk.platformAddresses.createStateTransition('identityCreateFromAddresses', {
|
|
64
|
+
inputs, feeStrategy, inputWitness
|
|
65
|
+
})).toThrow('Platform address transition param "publicKeys" is missing');
|
|
66
|
+
});
|
|
67
|
+
test('should be able to create identityTopUpFromAddresses', () => {
|
|
68
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('identityTopUpFromAddresses', {
|
|
69
|
+
identityId, inputs, feeStrategy, inputWitness
|
|
70
|
+
});
|
|
71
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
72
|
+
});
|
|
73
|
+
test('should throw when identityTopUpFromAddresses is missing identityId', () => {
|
|
74
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
75
|
+
expect(() => sdk.platformAddresses.createStateTransition('identityTopUpFromAddresses', {
|
|
76
|
+
inputs, feeStrategy, inputWitness
|
|
77
|
+
})).toThrow('Platform address transition param "identityId" is missing');
|
|
78
|
+
});
|
|
79
|
+
test('should be able to create addressFundsTransfer', () => {
|
|
80
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('addressFundsTransfer', {
|
|
81
|
+
inputs, feeStrategy, inputWitness, outputs
|
|
82
|
+
});
|
|
83
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
84
|
+
});
|
|
85
|
+
test('should throw when addressFundsTransfer is missing outputs', () => {
|
|
86
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
87
|
+
expect(() => sdk.platformAddresses.createStateTransition('addressFundsTransfer', {
|
|
88
|
+
inputs, feeStrategy, inputWitness
|
|
89
|
+
})).toThrow('Platform address transition param "outputs" is missing');
|
|
90
|
+
});
|
|
91
|
+
test('should be able to create addressFundingFromAssetLock', () => {
|
|
92
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('addressFundingFromAssetLock', {
|
|
93
|
+
assetLockProof, inputs, feeStrategy, inputWitness, outputs: nullableOutputs
|
|
94
|
+
});
|
|
95
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
96
|
+
});
|
|
97
|
+
test('should throw when addressFundingFromAssetLock is missing assetLockProof', () => {
|
|
98
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
99
|
+
expect(() => sdk.platformAddresses.createStateTransition('addressFundingFromAssetLock', {
|
|
100
|
+
inputs, feeStrategy, inputWitness, outputs: nullableOutputs
|
|
101
|
+
})).toThrow('Platform address transition param "assetLockProof" is missing');
|
|
102
|
+
});
|
|
103
|
+
test('should be able to create addressCreditWithdrawal', () => {
|
|
104
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('addressCreditWithdrawal', {
|
|
105
|
+
inputs, feeStrategy, coreFeePerByte: 1, pooling: 'Standard', outputScript, inputWitness
|
|
106
|
+
});
|
|
107
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
108
|
+
});
|
|
109
|
+
test('should be able to create addressCreditWithdrawal with optional output', () => {
|
|
110
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('addressCreditWithdrawal', {
|
|
111
|
+
inputs, feeStrategy, coreFeePerByte: 1, pooling: 'Standard', outputScript, inputWitness, output
|
|
112
|
+
});
|
|
113
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
114
|
+
});
|
|
115
|
+
test('should throw when addressCreditWithdrawal is missing outputScript', () => {
|
|
116
|
+
// @ts-expect-error testing the runtime missing-param check
|
|
117
|
+
expect(() => sdk.platformAddresses.createStateTransition('addressCreditWithdrawal', {
|
|
118
|
+
inputs, feeStrategy, coreFeePerByte: 1, pooling: 'Standard', inputWitness
|
|
119
|
+
})).toThrow('Platform address transition param "outputScript" is missing');
|
|
120
|
+
});
|
|
121
|
+
test('should default userFeeIncrease to 0 when omitted', () => {
|
|
122
|
+
const stateTransition = sdk.platformAddresses.createStateTransition('addressFundsTransfer', {
|
|
123
|
+
inputs, feeStrategy, inputWitness, outputs
|
|
124
|
+
});
|
|
125
|
+
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
126
|
+
});
|
|
127
|
+
test('should throw on unimplemented transition type', () => {
|
|
128
|
+
expect(() => sdk.platformAddresses.createStateTransition(
|
|
129
|
+
// @ts-expect-error testing an unknown transition type
|
|
130
|
+
'unknownTransition', {})).toThrow('Unimplemented transition type: unknownTransition');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
22
133
|
});
|
|
@@ -35,9 +35,10 @@ function makeSpendableNote(seed, value) {
|
|
|
35
35
|
return { spend: new SpendableNoteWASM(note, merklePath), anchor, owner };
|
|
36
36
|
}
|
|
37
37
|
describe('Shielded', () => {
|
|
38
|
-
beforeAll(() => {
|
|
38
|
+
beforeAll(async () => {
|
|
39
39
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
40
|
-
|
|
40
|
+
await sdk.shielded.init();
|
|
41
|
+
}, 60000);
|
|
41
42
|
test('getShieldedNotesCount', async () => {
|
|
42
43
|
const count = await sdk.shielded.getShieldedNotesCount();
|
|
43
44
|
expect(typeof count).toBe('bigint');
|
|
@@ -89,7 +90,7 @@ describe('Shielded', () => {
|
|
|
89
90
|
expect(Array.isArray(recovered)).toBe(true);
|
|
90
91
|
expect(recovered).toHaveLength(0);
|
|
91
92
|
});
|
|
92
|
-
test('buildSpendableNotes produces a spend usable by a transition', () => {
|
|
93
|
+
test('buildSpendableNotes produces a spend usable by a transition', async () => {
|
|
93
94
|
const seed = randomBytes(32);
|
|
94
95
|
const owner = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
|
|
95
96
|
const rho = randomBytes(32);
|
|
@@ -106,7 +107,7 @@ describe('Shielded', () => {
|
|
|
106
107
|
expect(spends[0]).toEqual(expect.any(SpendableNoteWASM));
|
|
107
108
|
expect(anchor).toBeInstanceOf(Uint8Array);
|
|
108
109
|
// the produced spend + anchor must actually prove a spend transition
|
|
109
|
-
const stateTransition = sdk.shielded.createStateTransition('shieldedTransfer', {
|
|
110
|
+
const stateTransition = await sdk.shielded.createStateTransition('shieldedTransfer', {
|
|
110
111
|
spends,
|
|
111
112
|
recipient: OrchardAddressWASM.fromSeed(randomBytes(32), COIN_TYPE, ACCOUNT),
|
|
112
113
|
transferAmount: BigInt(1000000),
|
|
@@ -119,12 +120,12 @@ describe('Shielded', () => {
|
|
|
119
120
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
120
121
|
}, 60000);
|
|
121
122
|
describe('should be able to create state transition', () => {
|
|
122
|
-
test('should be able to create a shield transition', () => {
|
|
123
|
+
test('should be able to create a shield transition', async () => {
|
|
123
124
|
const seed = randomBytes(32);
|
|
124
125
|
const recipient = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
|
|
125
126
|
const privateKey = new PrivateKeyWASM(randomBytes(32), 'testnet');
|
|
126
127
|
const address = platformAddress(privateKey.getPublicKey().hash160());
|
|
127
|
-
const stateTransition = sdk.shielded.createStateTransition('shield', {
|
|
128
|
+
const stateTransition = await sdk.shielded.createStateTransition('shield', {
|
|
128
129
|
recipient,
|
|
129
130
|
shieldAmount: BigInt(50000000),
|
|
130
131
|
inputs: [new InputAddressWASM(address, 0, BigInt(100000000))],
|
|
@@ -135,13 +136,13 @@ describe('Shielded', () => {
|
|
|
135
136
|
});
|
|
136
137
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
137
138
|
}, 60000);
|
|
138
|
-
test('should be able to create a shieldFromAssetLock transition', () => {
|
|
139
|
+
test('should be able to create a shieldFromAssetLock transition', async () => {
|
|
139
140
|
const seed = randomBytes(32);
|
|
140
141
|
const recipient = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
|
|
141
142
|
const privateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
|
|
142
143
|
const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
|
|
143
144
|
const assetLockProof = AssetLockProofWASM.createChainAssetLockProof(1337, new OutPointWASM(txid, 0));
|
|
144
|
-
const stateTransition = sdk.shielded.createStateTransition('shieldFromAssetLock', {
|
|
145
|
+
const stateTransition = await sdk.shielded.createStateTransition('shieldFromAssetLock', {
|
|
145
146
|
recipient,
|
|
146
147
|
shieldAmount: BigInt(50000000),
|
|
147
148
|
assetLockProof,
|
|
@@ -151,11 +152,11 @@ describe('Shielded', () => {
|
|
|
151
152
|
});
|
|
152
153
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
153
154
|
}, 60000);
|
|
154
|
-
test('should be able to create a shieldedTransfer transition', () => {
|
|
155
|
+
test('should be able to create a shieldedTransfer transition', async () => {
|
|
155
156
|
const seed = randomBytes(32);
|
|
156
157
|
const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
|
|
157
158
|
const recipient = OrchardAddressWASM.fromSeed(randomBytes(32), COIN_TYPE, ACCOUNT);
|
|
158
|
-
const stateTransition = sdk.shielded.createStateTransition('shieldedTransfer', {
|
|
159
|
+
const stateTransition = await sdk.shielded.createStateTransition('shieldedTransfer', {
|
|
159
160
|
spends: [spend],
|
|
160
161
|
recipient,
|
|
161
162
|
transferAmount: BigInt(1000000),
|
|
@@ -168,10 +169,10 @@ describe('Shielded', () => {
|
|
|
168
169
|
});
|
|
169
170
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
170
171
|
}, 60000);
|
|
171
|
-
test('should be able to create an unshield transition', () => {
|
|
172
|
+
test('should be able to create an unshield transition', async () => {
|
|
172
173
|
const seed = randomBytes(32);
|
|
173
174
|
const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
|
|
174
|
-
const stateTransition = sdk.shielded.createStateTransition('unshield', {
|
|
175
|
+
const stateTransition = await sdk.shielded.createStateTransition('unshield', {
|
|
175
176
|
spends: [spend],
|
|
176
177
|
outputAddress: platformAddress(),
|
|
177
178
|
unshieldAmount: BigInt(1000000),
|
|
@@ -184,10 +185,10 @@ describe('Shielded', () => {
|
|
|
184
185
|
});
|
|
185
186
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
186
187
|
}, 60000);
|
|
187
|
-
test('should be able to create a shieldedWithdrawal transition', () => {
|
|
188
|
+
test('should be able to create a shieldedWithdrawal transition', async () => {
|
|
188
189
|
const seed = randomBytes(32);
|
|
189
190
|
const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
|
|
190
|
-
const stateTransition = sdk.shielded.createStateTransition('shieldedWithdrawal', {
|
|
191
|
+
const stateTransition = await sdk.shielded.createStateTransition('shieldedWithdrawal', {
|
|
191
192
|
spends: [spend],
|
|
192
193
|
withdrawalAmount: BigInt(1000000),
|
|
193
194
|
outputScript: CoreScriptWASM.newP2PKH(randomBytes(20)),
|
|
@@ -205,7 +206,7 @@ describe('Shielded', () => {
|
|
|
205
206
|
// The proving step succeeds, but `IdentityCreateFromShieldedPoolResultWASM.identityId`
|
|
206
207
|
// (read while assembling the transition) rejects the derived id for synthetic notes.
|
|
207
208
|
// A real run needs a funded note and signed keys, so this is covered against a live pool.
|
|
208
|
-
test('should be able to create an identityCreateFromShieldedPool transition', () => {
|
|
209
|
+
test('should be able to create an identityCreateFromShieldedPool transition', async () => {
|
|
209
210
|
const seed = randomBytes(32);
|
|
210
211
|
const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(20000000000));
|
|
211
212
|
const privateKey = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
|
|
@@ -217,7 +218,7 @@ describe('Shielded', () => {
|
|
|
217
218
|
readOnly: false,
|
|
218
219
|
data: privateKey.getPublicKey().bytes()
|
|
219
220
|
};
|
|
220
|
-
const stateTransition = sdk.shielded.createStateTransition('identityCreateFromShieldedPool', {
|
|
221
|
+
const stateTransition = await sdk.shielded.createStateTransition('identityCreateFromShieldedPool', {
|
|
221
222
|
publicKeys: [identityPublicKeyInCreation],
|
|
222
223
|
privateKeys: [privateKey],
|
|
223
224
|
denomination: BigInt(10000000000),
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AddressFundsFeeStrategyStepWASM, AssetLockProofWASM, CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, InputAddressWASM, KeyType, OrchardAddressWASM, PlatformAddressLike, PlatformAddressWASM, PlatformVersionWASM, PoolingLike, PrivateKeyWASM, Purpose, SecurityLevel, SpendableNoteWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
|
-
export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM, IdentifierLike, PlatformAddressLike } from 'pshenmic-dpp';
|
|
1
|
+
import { AddressFundsFeeStrategyStepWASM, AssetLockProofWASM, CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, InputAddressWASM, KeyType, OrchardAddressWASM, PlatformAddressLike, PlatformAddressWASM, PlatformVersionWASM, PoolingLike, PrivateKeyWASM, Purpose, SecurityLevel, SpendableNoteWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM } from 'pshenmic-dpp';
|
|
2
|
+
export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM, IdentifierLike, PlatformAddressLike, InputAddressWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, AddressFundsFeeStrategyStepWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, AssetLockProofWASM, IdentityCreditTransferToAddressesTransitionWASM, IdentityCreateFromAddressesTransitionWASM, IdentityTopUpFromAddressesTransitionWASM, AddressFundsTransferTransitionWASM, AddressFundingFromAssetLockTransitionWASM, AddressCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
|
|
3
3
|
export type Network = 'mainnet' | 'testnet';
|
|
4
4
|
export { DashPlatformSDK } from './src/DashPlatformSDK.js';
|
|
5
5
|
export type MasternodeList = Record<string, MasternodeInfo>;
|
|
@@ -294,3 +294,60 @@ export interface ShieldedNullifierStatus {
|
|
|
294
294
|
nullifier: Uint8Array;
|
|
295
295
|
isSpent: boolean;
|
|
296
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Fields shared by the address-funded transitions (the ones spending platform address inputs).
|
|
299
|
+
*
|
|
300
|
+
* The `inputWitness` arrays are produced by the client application (wallet / mobile / browser
|
|
301
|
+
* extension), which is where the address private keys live. The builders only assemble the
|
|
302
|
+
* transition - they never sign or hit the network.
|
|
303
|
+
*/
|
|
304
|
+
export interface AddressFundsBaseParams {
|
|
305
|
+
inputs: InputAddressWASM[];
|
|
306
|
+
feeStrategy: AddressFundsFeeStrategyStepWASM[];
|
|
307
|
+
inputWitness: AddressWitnessWASM[];
|
|
308
|
+
userFeeIncrease?: number;
|
|
309
|
+
}
|
|
310
|
+
/** Identity -> platform addresses (transition type 9). */
|
|
311
|
+
export interface IdentityCreditTransferToAddressesParams {
|
|
312
|
+
identityId: IdentifierLike;
|
|
313
|
+
recipients: OutputAddressWASM[];
|
|
314
|
+
nonce: bigint;
|
|
315
|
+
userFeeIncrease?: number;
|
|
316
|
+
}
|
|
317
|
+
/** Platform addresses -> new identity (transition type 10). */
|
|
318
|
+
export interface IdentityCreateFromAddressesParams extends AddressFundsBaseParams {
|
|
319
|
+
publicKeys: IdentityPublicKeyInCreationWASM[];
|
|
320
|
+
output?: OutputAddressWASM;
|
|
321
|
+
}
|
|
322
|
+
/** Platform addresses -> existing identity (transition type 11). */
|
|
323
|
+
export interface IdentityTopUpFromAddressesParams extends AddressFundsBaseParams {
|
|
324
|
+
identityId: IdentifierLike;
|
|
325
|
+
output?: OutputAddressWASM;
|
|
326
|
+
}
|
|
327
|
+
/** Platform addresses -> platform addresses (transition type 12). */
|
|
328
|
+
export interface AddressFundsTransferParams extends AddressFundsBaseParams {
|
|
329
|
+
outputs: OutputAddressWASM[];
|
|
330
|
+
}
|
|
331
|
+
/** Asset lock -> platform addresses (transition type 13). */
|
|
332
|
+
export interface AddressFundingFromAssetLockParams extends AddressFundsBaseParams {
|
|
333
|
+
assetLockProof: AssetLockProofWASM;
|
|
334
|
+
outputs: OutputAddressNullableCreditsWASM[];
|
|
335
|
+
}
|
|
336
|
+
/** Platform addresses -> core L1 (transition type 14). */
|
|
337
|
+
export interface AddressCreditWithdrawalParams extends AddressFundsBaseParams {
|
|
338
|
+
coreFeePerByte: number;
|
|
339
|
+
pooling: 'Standard' | 'Never' | 'IfAvailable';
|
|
340
|
+
outputScript: CoreScriptWASM;
|
|
341
|
+
output?: OutputAddressWASM;
|
|
342
|
+
}
|
|
343
|
+
/** Maps each platform address transition type to the params it requires. */
|
|
344
|
+
export interface PlatformAddressTransitionParamsMap {
|
|
345
|
+
identityCreditTransferToAddresses: IdentityCreditTransferToAddressesParams;
|
|
346
|
+
identityCreateFromAddresses: IdentityCreateFromAddressesParams;
|
|
347
|
+
identityTopUpFromAddresses: IdentityTopUpFromAddressesParams;
|
|
348
|
+
addressFundsTransfer: AddressFundsTransferParams;
|
|
349
|
+
addressFundingFromAssetLock: AddressFundingFromAssetLockParams;
|
|
350
|
+
addressCreditWithdrawal: AddressCreditWithdrawalParams;
|
|
351
|
+
}
|
|
352
|
+
export type PlatformAddressTransitionType = keyof PlatformAddressTransitionParamsMap;
|
|
353
|
+
export type PlatformAddressTransitionParams = PlatformAddressTransitionParamsMap[PlatformAddressTransitionType];
|
package/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM } from 'pshenmic-dpp';
|
|
1
|
+
export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM, InputAddressWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, AddressFundsFeeStrategyStepWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, AssetLockProofWASM, IdentityCreditTransferToAddressesTransitionWASM, IdentityCreateFromAddressesTransitionWASM, IdentityTopUpFromAddressesTransitionWASM, AddressFundsTransferTransitionWASM, AddressFundingFromAssetLockTransitionWASM, AddressCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
|
|
2
2
|
export { DashPlatformSDK } from './src/DashPlatformSDK.js';
|
|
3
3
|
export var ContestedStateResultType;
|
|
4
4
|
(function (ContestedStateResultType) {
|