pshenmic-dpp 2.0.0-dev.26 → 2.0.0-dev.27

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.
Files changed (52) hide show
  1. package/dist/binaries/bindingsTypes.d.ts +37 -0
  2. package/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
  3. package/dist/binaries/native/aarch64-pc-windows-msvc/pshenmic_dpp.node +0 -0
  4. package/dist/binaries/native/aarch64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
  5. package/dist/binaries/native/aarch64-unknown-linux-musl/pshenmic_dpp.node +0 -0
  6. package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
  7. package/dist/binaries/native/x86_64-pc-windows-msvc/pshenmic_dpp.node +0 -0
  8. package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
  9. package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
  10. package/dist/binaries/node.cjs +42 -21
  11. package/dist/binaries/node.d.cts +2 -2
  12. package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
  13. package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
  14. package/dist/binaries/wasm/wasmBytes.cjs +1 -1
  15. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.d.ts +3 -1
  16. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.js +6 -0
  17. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.d.ts +2 -1
  18. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.js +3 -0
  19. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.d.ts +3 -1
  20. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.js +6 -0
  21. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.d.ts +2 -1
  22. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.js +3 -0
  23. package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.d.ts +2 -1
  24. package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.js +3 -0
  25. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.d.ts +2 -1
  26. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.js +3 -0
  27. package/dist/src/dpp/structs/Batch/BatchTransition.d.ts +2 -1
  28. package/dist/src/dpp/structs/Batch/BatchTransition.js +3 -0
  29. package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.d.ts +2 -1
  30. package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.js +3 -0
  31. package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.d.ts +2 -1
  32. package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.js +3 -0
  33. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.d.ts +2 -1
  34. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.js +3 -0
  35. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.d.ts +2 -1
  36. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.js +3 -0
  37. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.d.ts +2 -1
  38. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.js +3 -0
  39. package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.d.ts +2 -1
  40. package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.js +3 -0
  41. package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.d.ts +2 -1
  42. package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.js +3 -0
  43. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.d.ts +2 -1
  44. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +3 -0
  45. package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.d.ts +9 -1
  46. package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.js +10 -0
  47. package/dist/src/dpp/structs/StateTransition.d.ts +2 -1
  48. package/dist/src/dpp/structs/StateTransition.js +3 -0
  49. package/package.json +1 -1
  50. package/tests/unit/AddressTransitionsFees.spec.ts +274 -0
  51. package/tests/unit/Shielded.spec.ts +37 -4
  52. package/tests/unit/StateTransitionFees.spec.ts +177 -0
@@ -31,6 +31,8 @@ export declare class AddressCreditWithdrawalTransitionNAPI {
31
31
  set feeStrategy(jsFeeStrategy: Array<AddressFundsFeeStrategyStepNAPI>);
32
32
  set userFeeIncrease(userFeeIncrease: number);
33
33
  set inputWitness(jsInputWitnesses: Array<AddressWitnessNAPI>);
34
+ static estimateMinFee(jsInputCount: number, jsHasChangeOutput: boolean, jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
35
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
34
36
  bytes(): Uint8Array;
35
37
  hex(): string;
36
38
  base64(): string;
@@ -56,6 +58,7 @@ export declare class AddressFundingFromAssetLockTransitionNAPI {
56
58
  set feeStrategy(jsFeeStrategy: Array<AddressFundsFeeStrategyStepNAPI>);
57
59
  set userFeeIncrease(userFeeIncrease: number);
58
60
  set inputWitness(jsInputWitnesses: Array<AddressWitnessNAPI>);
61
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
59
62
  bytes(): Uint8Array;
60
63
  hex(): string;
61
64
  base64(): string;
@@ -84,6 +87,8 @@ export declare class AddressFundsTransferTransitionNAPI {
84
87
  set feeStrategy(jsFeeStrategy: Array<AddressFundsFeeStrategyStepNAPI>);
85
88
  set userFeeIncrease(userFeeIncrease: number);
86
89
  set inputWitness(jsInputWitnesses: Array<AddressWitnessNAPI>);
90
+ static estimateMinFee(jsInputCount: number, jsOutputCount: number, jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
91
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
87
92
  bytes(): Uint8Array;
88
93
  hex(): string;
89
94
  base64(): string;
@@ -148,6 +153,7 @@ export declare class BatchTransitionNAPI {
148
153
  setIdentityContractNonce(nonce: BigIntString): void;
149
154
  toStateTransition(): StateTransitionNAPI;
150
155
  static fromStateTransition(stateTransition: StateTransitionNAPI): BatchTransitionNAPI;
156
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
151
157
  bytes(): Uint8Array;
152
158
  hex(): string;
153
159
  base64(): string;
@@ -285,6 +291,7 @@ export declare class DataContractCreateTransitionNAPI {
285
291
  static fromBytes(bytes: Uint8Array): DataContractCreateTransitionNAPI;
286
292
  static fromHex(hex: string): DataContractCreateTransitionNAPI;
287
293
  static fromBase64(base64: string): DataContractCreateTransitionNAPI;
294
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
288
295
  bytes(): Uint8Array;
289
296
  hex(): string;
290
297
  base64(): string;
@@ -334,6 +341,7 @@ export declare class DataContractUpdateTransitionNAPI {
334
341
  static fromBytes(bytes: Uint8Array): DataContractUpdateTransitionNAPI;
335
342
  static fromHex(hex: string): DataContractUpdateTransitionNAPI;
336
343
  static fromBase64(base64: string): DataContractUpdateTransitionNAPI;
344
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
337
345
  bytes(): Uint8Array;
338
346
  hex(): string;
339
347
  base64(): string;
@@ -576,6 +584,7 @@ export declare class IdentityCreateFromAddressesTransitionNAPI {
576
584
  set feeStrategy(jsFeeStrategy: Array<AddressFundsFeeStrategyStepNAPI>);
577
585
  set userFeeIncrease(userFeeIncrease: number);
578
586
  set inputWitness(jsInputWitnesses: Array<AddressWitnessNAPI>);
587
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
579
588
  bytes(): Uint8Array;
580
589
  hex(): string;
581
590
  base64(): string;
@@ -626,6 +635,7 @@ export declare class IdentityCreateTransitionNAPI {
626
635
  static default(jsPlatformVersion: DynamicValue): IdentityCreateTransitionNAPI;
627
636
  static fromHex(hex: string): IdentityCreateTransitionNAPI;
628
637
  static fromBase64(base64: string): IdentityCreateTransitionNAPI;
638
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
629
639
  bytes(): Uint8Array;
630
640
  static fromBytes(bytes: Uint8Array): IdentityCreateTransitionNAPI;
631
641
  get publicKeys(): Array<IdentityPublicKeyInCreationNAPI>;
@@ -643,6 +653,7 @@ export declare class IdentityCreateTransitionNAPI {
643
653
  }
644
654
  export declare class IdentityCreditTransferNAPI {
645
655
  constructor(jsSender: IdentifierLikeNAPI, amount: BigIntString, jsRecipient: IdentifierLikeNAPI, nonce: BigIntString, userFeeIncrease?: number | undefined | null);
656
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
646
657
  bytes(): Uint8Array;
647
658
  hex(): string;
648
659
  base64(): string;
@@ -681,6 +692,7 @@ export declare class IdentityCreditTransferToAddressesTransitionNAPI {
681
692
  set userFeeIncrease(userFeeIncrease: number);
682
693
  set signaturePublicKeyId(keyId: number);
683
694
  set signature(signature: Uint8Array);
695
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
684
696
  bytes(): Uint8Array;
685
697
  hex(): string;
686
698
  base64(): string;
@@ -716,6 +728,7 @@ export declare class IdentityCreditWithdrawalTransitionNAPI {
716
728
  set signaturePublicKeyId(signaturePublicKeyId: number);
717
729
  static fromHex(hex: string): IdentityCreditWithdrawalTransitionNAPI;
718
730
  static fromBase64(base64: string): IdentityCreditWithdrawalTransitionNAPI;
731
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
719
732
  bytes(): Uint8Array;
720
733
  hex(): string;
721
734
  base64(): string;
@@ -823,6 +836,7 @@ export declare class IdentityTopUpFromAddressesTransitionNAPI {
823
836
  set feeStrategy(jsFeeStrategy: Array<AddressFundsFeeStrategyStepNAPI>);
824
837
  set userFeeIncrease(userFeeIncrease: number);
825
838
  set inputWitness(jsInputWitnesses: Array<AddressWitnessNAPI>);
839
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
826
840
  bytes(): Uint8Array;
827
841
  hex(): string;
828
842
  base64(): string;
@@ -845,6 +859,7 @@ export declare class IdentityTopUpTransitionNAPI {
845
859
  get signature(): Uint8Array;
846
860
  getSignableBytes(): Uint8Array;
847
861
  set signature(signature: Uint8Array);
862
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
848
863
  bytes(): Uint8Array;
849
864
  hex(): string;
850
865
  base64(): string;
@@ -878,6 +893,7 @@ export declare class IdentityUpdateTransitionNAPI {
878
893
  set signaturePublicKeyId(signaturePublicKeyId: number);
879
894
  static fromHex(hex: string): IdentityUpdateTransitionNAPI;
880
895
  static fromBase64(base64: string): IdentityUpdateTransitionNAPI;
896
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
881
897
  bytes(): Uint8Array;
882
898
  hex(): string;
883
899
  base64(): string;
@@ -936,6 +952,7 @@ export declare class MasternodeVoteTransitionNAPI {
936
952
  set signature(signature: Uint8Array);
937
953
  static fromHex(hex: string): MasternodeVoteTransitionNAPI;
938
954
  static fromBase64(base64: string): MasternodeVoteTransitionNAPI;
955
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
939
956
  bytes(): Uint8Array;
940
957
  hex(): string;
941
958
  base64(): string;
@@ -1039,6 +1056,17 @@ export declare class PlatformAddressInfoNAPI {
1039
1056
  export declare class PlatformAddressNAPI {
1040
1057
  constructor(address: PlatformAddressLikeNAPI);
1041
1058
  bytes(): Uint8Array;
1059
+ /**
1060
+ * Storage fee GroveDB charges for creating balance entries for addresses that are not in
1061
+ * state yet.
1062
+ *
1063
+ * Minimum fees price a transition as if every one of its outputs pays a fresh address, but
1064
+ * the fee actually charged is metered: paying an address that already exists writes no new
1065
+ * bytes and costs (close to) nothing in storage, while every address created costs
1066
+ * `PLATFORM_ADDRESS_STORAGE_BYTES` at the disk rate. Add this to a processing estimate when
1067
+ * you know how many of your outputs are new.
1068
+ */
1069
+ static estimateStorageFeeForNewAddresses(jsAddressCount: number, jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
1042
1070
  toAddress(jsNetwork: DynamicValue): string;
1043
1071
  toBech32m(jsNetwork: DynamicValue): string;
1044
1072
  isP2PKH(): boolean;
@@ -1359,6 +1387,15 @@ export declare class StateTransitionNAPI {
1359
1387
  static fromBase64(base64: string): StateTransitionNAPI;
1360
1388
  hash(skipSignature: boolean): string;
1361
1389
  getActionName(): string;
1390
+ /**
1391
+ * The minimum fee the network requires for this transition to be accepted.
1392
+ *
1393
+ * This is the same value the node checks the payer balance against before execution.
1394
+ * The fee actually charged is metered during execution and depends on state (for
1395
+ * example, paying an address that does not exist yet adds storage cost), so it can
1396
+ * be higher than this minimum.
1397
+ */
1398
+ calculateMinRequiredFee(jsPlatformVersion?: PlatformVersionNAPI | undefined | null): BigIntString;
1362
1399
  getActionType(): string;
1363
1400
  getActionTypeNumber(): number;
1364
1401
  getOwnerId(): IdentifierNAPI | null;
@@ -3,10 +3,17 @@ const path = require('node:path');
3
3
  function isMusl() {
4
4
  if (process.platform !== 'linux')
5
5
  return false;
6
- const report = process.report?.getReport?.();
7
- return !report?.header?.glibcVersionRuntime;
6
+ try {
7
+ const report = process.report?.getReport?.();
8
+ return !report?.header?.glibcVersionRuntime;
9
+ }
10
+ catch {
11
+ // getReport() is unavailable in some embedders/worker contexts; assume
12
+ // glibc, and let the require below fall back to WebAssembly if wrong.
13
+ return false;
14
+ }
8
15
  }
9
- function getBinaryPath() {
16
+ function getTarget() {
10
17
  const platform = process.platform;
11
18
  const arch = process.arch;
12
19
  let target = '';
@@ -24,27 +31,41 @@ function getBinaryPath() {
24
31
  target = `x86_64-unknown-linux-${libc}`;
25
32
  }
26
33
  }
27
- // else if (platform === 'win32') {
28
- // if (arch === 'arm64') {
29
- // target = 'aarch64-pc-windows-msvc';
30
- // }
31
- // else {
32
- // target = 'x86_64-pc-windows-msvc';
33
- // }
34
- // }
34
+ else if (platform === 'win32') {
35
+ if (arch === 'arm64') {
36
+ target = 'aarch64-pc-windows-msvc';
37
+ }
38
+ else {
39
+ target = 'x86_64-pc-windows-msvc';
40
+ }
41
+ }
35
42
  else {
36
43
  console.error(`Unsupported platform: ${platform} ${arch}. Using WebAssembly instead Node-API`);
37
44
  return null;
38
45
  }
39
- console.log(`running on native dpp (${target})`);
40
- return path.join('native', target, 'pshenmic_dpp.node');
41
- }
42
- const binaryPath = getBinaryPath();
43
- let exportedModule;
44
- if (binaryPath !== null) {
45
- exportedModule = require(`./${binaryPath}`);
46
+ return target;
46
47
  }
47
- else {
48
- exportedModule = require('./wasmCreation.cjs');
48
+ // The native addon can be unusable even on a supported platform: the binary may
49
+ // be missing from the package, built for another libc/arch, or fail to link
50
+ // against a system dependency (e.g. the VC++ runtime on Windows). None of that
51
+ // should be fatal — WebAssembly is a complete fallback, so any load failure
52
+ // degrades to it instead of taking the whole import down.
53
+ function loadNative() {
54
+ const target = getTarget();
55
+ if (target === null) {
56
+ return null;
57
+ }
58
+ try {
59
+ const nativeModule = require(`./${path.join('native', target, 'pshenmic_dpp.node')}`);
60
+ console.log(`running on native dpp (${target})`);
61
+ return nativeModule;
62
+ }
63
+ catch (error) {
64
+ // Only the first line: node appends a multi-line "Require stack" to
65
+ // MODULE_NOT_FOUND messages, which buries the actual reason.
66
+ const reason = String(error?.message ?? error).split('\n')[0];
67
+ console.error(`Failed to load native dpp (${target}): ${reason}. Using WebAssembly instead Node-API`);
68
+ return null;
69
+ }
49
70
  }
50
- module.exports = exportedModule;
71
+ module.exports = loadNative() ?? require('./wasmCreation.cjs');
@@ -1,2 +1,2 @@
1
- export = exportedModule;
2
- declare let exportedModule: any;
1
+ declare const _exports: any;
2
+ export = _exports;