dash-platform-sdk 1.5.0-dev.1 → 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 +15 -14
- package/bundle.min.js +1 -21
- package/package.json +4 -3
- package/proto/generated/platform.client.d.ts +50 -0
- package/proto/generated/platform.client.js +53 -18
- package/proto/generated/platform.d.ts +888 -0
- package/proto/generated/platform.js +2216 -417
- package/src/constants.d.ts +1 -1
- package/src/constants.js +1 -1
- package/src/identities/createStateTransition.js +2 -2
- package/src/keyPair/index.d.ts +63 -1
- package/src/keyPair/index.js +96 -1
- 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 +1 -1
- package/src/shielded/createStateTransition.js +7 -2
- package/src/shielded/index.d.ts +7 -6
- package/src/shielded/index.js +10 -8
- package/src/utils/verifyTenderdashProof.js +3 -0
- package/test/unit/Identity.spec.js +1 -1
- package/test/unit/KeyPair.spec.js +49 -1
- package/test/unit/Node.spec.js +6 -0
- package/test/unit/PlatformAddress.spec.js +155 -1
- package/test/unit/Shielded.spec.js +17 -16
- package/types.d.ts +69 -2
- package/types.js +1 -1
|
@@ -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,6 @@
|
|
|
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
|
-
|
|
1
|
+
import { AddressFundsFeeStrategyStepWASM, AssetLockProofWASM, CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, InputAddressWASM, KeyType, OrchardAddressWASM, PlatformAddressLike, PlatformAddressWASM, PlatformVersionWASM, PoolingLike, PrivateKeyWASM, Purpose, SecurityLevel, ShieldedOutputWASM, SpendableNoteWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, VerifiedAddressesTrunkState } from 'pshenmic-dpp';
|
|
2
|
+
import { ResponseMetadata } from './proto/generated/platform.js';
|
|
3
|
+
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
4
|
export type Network = 'mainnet' | 'testnet';
|
|
4
5
|
export { DashPlatformSDK } from './src/DashPlatformSDK.js';
|
|
5
6
|
export type MasternodeList = Record<string, MasternodeInfo>;
|
|
@@ -76,6 +77,10 @@ export interface ShieldedTransferParams extends ShieldedSpendParams {
|
|
|
76
77
|
recipient: OrchardAddressWASM;
|
|
77
78
|
transferAmount: bigint;
|
|
78
79
|
}
|
|
80
|
+
/** Pool -> pool, several recipients (spend). Each output carries its own memo. */
|
|
81
|
+
export interface ShieldedTransferMultiParams extends Omit<ShieldedSpendParams, 'memo'> {
|
|
82
|
+
outputs: ShieldedOutputWASM[];
|
|
83
|
+
}
|
|
79
84
|
/** Pool -> new identity (spend). */
|
|
80
85
|
export interface IdentityCreateFromShieldedPoolParams extends ShieldedSpendParams {
|
|
81
86
|
publicKeys: IdentityPublicKeyInCreation[];
|
|
@@ -90,6 +95,7 @@ export interface ShieldedTransitionParamsMap {
|
|
|
90
95
|
shieldedWithdrawal: ShieldedWithdrawalParams;
|
|
91
96
|
unshield: UnshieldParams;
|
|
92
97
|
shieldedTransfer: ShieldedTransferParams;
|
|
98
|
+
shieldedTransferMulti: ShieldedTransferMultiParams;
|
|
93
99
|
identityCreateFromShieldedPool: IdentityCreateFromShieldedPoolParams;
|
|
94
100
|
}
|
|
95
101
|
export type ShieldedTransitionType = keyof ShieldedTransitionParamsMap;
|
|
@@ -284,6 +290,10 @@ export interface PlatformAddressInfo {
|
|
|
284
290
|
nonce: number;
|
|
285
291
|
balance: bigint;
|
|
286
292
|
}
|
|
293
|
+
export interface PlatformAddressesTrunkState {
|
|
294
|
+
trunk: VerifiedAddressesTrunkState;
|
|
295
|
+
metadata: ResponseMetadata;
|
|
296
|
+
}
|
|
287
297
|
export interface ShieldedEncryptedNote {
|
|
288
298
|
nullifier: Uint8Array;
|
|
289
299
|
cmx: Uint8Array;
|
|
@@ -294,3 +304,60 @@ export interface ShieldedNullifierStatus {
|
|
|
294
304
|
nullifier: Uint8Array;
|
|
295
305
|
isSpent: boolean;
|
|
296
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Fields shared by the address-funded transitions (the ones spending platform address inputs).
|
|
309
|
+
*
|
|
310
|
+
* The `inputWitness` arrays are produced by the client application (wallet / mobile / browser
|
|
311
|
+
* extension), which is where the address private keys live. The builders only assemble the
|
|
312
|
+
* transition - they never sign or hit the network.
|
|
313
|
+
*/
|
|
314
|
+
export interface AddressFundsBaseParams {
|
|
315
|
+
inputs: InputAddressWASM[];
|
|
316
|
+
feeStrategy: AddressFundsFeeStrategyStepWASM[];
|
|
317
|
+
inputWitness: AddressWitnessWASM[];
|
|
318
|
+
userFeeIncrease?: number;
|
|
319
|
+
}
|
|
320
|
+
/** Identity -> platform addresses (transition type 9). */
|
|
321
|
+
export interface IdentityCreditTransferToAddressesParams {
|
|
322
|
+
identityId: IdentifierLike;
|
|
323
|
+
recipients: OutputAddressWASM[];
|
|
324
|
+
nonce: bigint;
|
|
325
|
+
userFeeIncrease?: number;
|
|
326
|
+
}
|
|
327
|
+
/** Platform addresses -> new identity (transition type 10). */
|
|
328
|
+
export interface IdentityCreateFromAddressesParams extends AddressFundsBaseParams {
|
|
329
|
+
publicKeys: IdentityPublicKeyInCreationWASM[];
|
|
330
|
+
output?: OutputAddressWASM;
|
|
331
|
+
}
|
|
332
|
+
/** Platform addresses -> existing identity (transition type 11). */
|
|
333
|
+
export interface IdentityTopUpFromAddressesParams extends AddressFundsBaseParams {
|
|
334
|
+
identityId: IdentifierLike;
|
|
335
|
+
output?: OutputAddressWASM;
|
|
336
|
+
}
|
|
337
|
+
/** Platform addresses -> platform addresses (transition type 12). */
|
|
338
|
+
export interface AddressFundsTransferParams extends AddressFundsBaseParams {
|
|
339
|
+
outputs: OutputAddressWASM[];
|
|
340
|
+
}
|
|
341
|
+
/** Asset lock -> platform addresses (transition type 13). */
|
|
342
|
+
export interface AddressFundingFromAssetLockParams extends AddressFundsBaseParams {
|
|
343
|
+
assetLockProof: AssetLockProofWASM;
|
|
344
|
+
outputs: OutputAddressNullableCreditsWASM[];
|
|
345
|
+
}
|
|
346
|
+
/** Platform addresses -> core L1 (transition type 14). */
|
|
347
|
+
export interface AddressCreditWithdrawalParams extends AddressFundsBaseParams {
|
|
348
|
+
coreFeePerByte: number;
|
|
349
|
+
pooling: 'Standard' | 'Never' | 'IfAvailable';
|
|
350
|
+
outputScript: CoreScriptWASM;
|
|
351
|
+
output?: OutputAddressWASM;
|
|
352
|
+
}
|
|
353
|
+
/** Maps each platform address transition type to the params it requires. */
|
|
354
|
+
export interface PlatformAddressTransitionParamsMap {
|
|
355
|
+
identityCreditTransferToAddresses: IdentityCreditTransferToAddressesParams;
|
|
356
|
+
identityCreateFromAddresses: IdentityCreateFromAddressesParams;
|
|
357
|
+
identityTopUpFromAddresses: IdentityTopUpFromAddressesParams;
|
|
358
|
+
addressFundsTransfer: AddressFundsTransferParams;
|
|
359
|
+
addressFundingFromAssetLock: AddressFundingFromAssetLockParams;
|
|
360
|
+
addressCreditWithdrawal: AddressCreditWithdrawalParams;
|
|
361
|
+
}
|
|
362
|
+
export type PlatformAddressTransitionType = keyof PlatformAddressTransitionParamsMap;
|
|
363
|
+
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) {
|