pshenmic-dpp 2.0.0-dev.9 → 2.0.0

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 (161) hide show
  1. package/README.md +164 -77
  2. package/dist/binaries/bindingsTypes.d.ts +903 -18
  3. package/dist/binaries/bindingsTypes.js +13 -0
  4. package/dist/binaries/memory.cjs +7 -0
  5. package/dist/binaries/memory.d.cts +2 -0
  6. package/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
  7. package/dist/binaries/native/aarch64-pc-windows-msvc/pshenmic_dpp.node +0 -0
  8. package/dist/binaries/native/aarch64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
  9. package/dist/binaries/native/aarch64-unknown-linux-musl/pshenmic_dpp.node +0 -0
  10. package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
  11. package/dist/binaries/native/x86_64-pc-windows-msvc/pshenmic_dpp.node +0 -0
  12. package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
  13. package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
  14. package/dist/binaries/node.cjs +71 -0
  15. package/dist/binaries/node.d.cts +2 -0
  16. package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
  17. package/dist/binaries/pshenmic_dpp.apple.node/Info.plist +29 -0
  18. package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/Info.plist +24 -0
  19. package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
  20. package/dist/binaries/pshenmic_dpp.apple.node/react-native-node-api-module +0 -0
  21. package/dist/binaries/pshenmic_dpp.d.ts +60 -0
  22. package/dist/binaries/pshenmic_dpp.js +1 -1
  23. package/dist/binaries/wasm/wasmBytes.cjs +4 -0
  24. package/dist/binaries/wasm/wasmBytes.d.cts +2 -0
  25. package/dist/binaries/wasm/workerBundle.cjs +6 -0
  26. package/dist/binaries/wasm/workerBundle.d.cts +2 -0
  27. package/dist/binaries/wasm.d.ts +60 -0
  28. package/dist/binaries/wasm.js +2 -44
  29. package/dist/binaries/wasmCreation.cjs +127 -0
  30. package/dist/binaries/wasmCreation.d.cts +4 -0
  31. package/dist/src/dpp/dpp.d.ts +32 -0
  32. package/dist/src/dpp/dpp.js +32 -0
  33. package/dist/src/dpp/enums.d.ts +1 -1
  34. package/dist/src/dpp/enums.js +1 -1
  35. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.d.ts +3 -1
  36. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.js +6 -0
  37. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.d.ts +2 -1
  38. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.js +3 -0
  39. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.d.ts +3 -1
  40. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.js +6 -0
  41. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.d.ts +2 -1
  42. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.js +3 -0
  43. package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.d.ts +2 -1
  44. package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.js +3 -0
  45. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.d.ts +2 -1
  46. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.js +3 -0
  47. package/dist/src/dpp/structs/Batch/BatchTransition.d.ts +2 -1
  48. package/dist/src/dpp/structs/Batch/BatchTransition.js +3 -0
  49. package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.d.ts +2 -1
  50. package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.js +3 -0
  51. package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.d.ts +2 -1
  52. package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.js +3 -0
  53. package/dist/src/dpp/structs/Identifier.js +3 -0
  54. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.d.ts +2 -1
  55. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.js +3 -0
  56. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.d.ts +2 -1
  57. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.js +3 -0
  58. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.d.ts +2 -1
  59. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.js +3 -0
  60. package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.d.ts +2 -1
  61. package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.js +3 -0
  62. package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.d.ts +2 -1
  63. package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.js +3 -0
  64. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.d.ts +2 -3
  65. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +3 -6
  66. package/dist/src/dpp/structs/Orchard/CommitmentTree.d.ts +14 -0
  67. package/dist/src/dpp/structs/Orchard/CommitmentTree.js +31 -0
  68. package/dist/src/dpp/structs/Orchard/FullViewingKey.d.ts +27 -0
  69. package/dist/src/dpp/structs/Orchard/FullViewingKey.js +45 -0
  70. package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.d.ts +21 -0
  71. package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.js +38 -0
  72. package/dist/src/dpp/structs/Orchard/IncomingViewingKey.d.ts +29 -0
  73. package/dist/src/dpp/structs/Orchard/IncomingViewingKey.js +44 -0
  74. package/dist/src/dpp/structs/Orchard/MerklePath.d.ts +11 -0
  75. package/dist/src/dpp/structs/Orchard/MerklePath.js +25 -0
  76. package/dist/src/dpp/structs/Orchard/Note.d.ts +18 -0
  77. package/dist/src/dpp/structs/Orchard/Note.js +42 -0
  78. package/dist/src/dpp/structs/Orchard/OrchardAddress.d.ts +27 -0
  79. package/dist/src/dpp/structs/Orchard/OrchardAddress.js +45 -0
  80. package/dist/src/dpp/structs/Orchard/OrchardProver.d.ts +19 -0
  81. package/dist/src/dpp/structs/Orchard/OrchardProver.js +34 -0
  82. package/dist/src/dpp/structs/Orchard/RecoveredNote.d.ts +19 -0
  83. package/dist/src/dpp/structs/Orchard/RecoveredNote.js +32 -0
  84. package/dist/src/dpp/structs/Orchard/ShieldedBuilder.d.ts +64 -0
  85. package/dist/src/dpp/structs/Orchard/ShieldedBuilder.js +79 -0
  86. package/dist/src/dpp/structs/Orchard/ShieldedMemo.d.ts +11 -0
  87. package/dist/src/dpp/structs/Orchard/ShieldedMemo.js +25 -0
  88. package/dist/src/dpp/structs/Orchard/ShieldedOutput.d.ts +23 -0
  89. package/dist/src/dpp/structs/Orchard/ShieldedOutput.js +41 -0
  90. package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.d.ts +11 -0
  91. package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.js +18 -0
  92. package/dist/src/dpp/structs/Orchard/SpendableNote.d.ts +13 -0
  93. package/dist/src/dpp/structs/Orchard/SpendableNote.js +27 -0
  94. package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.d.ts +9 -1
  95. package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.js +10 -0
  96. package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.d.ts +32 -0
  97. package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.js +76 -0
  98. package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.d.ts +19 -0
  99. package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.js +49 -0
  100. package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.d.ts +31 -0
  101. package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.js +80 -0
  102. package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.d.ts +33 -0
  103. package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.js +81 -0
  104. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.d.ts +22 -0
  105. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.js +54 -0
  106. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.d.ts +30 -0
  107. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.js +74 -0
  108. package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.d.ts +26 -0
  109. package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.js +62 -0
  110. package/dist/src/dpp/structs/StateTransition.d.ts +2 -1
  111. package/dist/src/dpp/structs/StateTransition.js +3 -0
  112. package/dist/src/dpp/types.d.ts +177 -3
  113. package/dist/src/dpp/verify/AddressFunds/utils.d.ts +5 -0
  114. package/dist/src/dpp/verify/AddressFunds/utils.js +28 -0
  115. package/dist/src/dpp/verify/AddressFunds/verifyAddressesBranchState.d.ts +12 -0
  116. package/dist/src/dpp/verify/AddressFunds/verifyAddressesBranchState.js +29 -0
  117. package/dist/src/dpp/verify/AddressFunds/verifyAddressesTrunkState.d.ts +9 -0
  118. package/dist/src/dpp/verify/AddressFunds/verifyAddressesTrunkState.js +30 -0
  119. package/dist/src/dpp/verify/AddressFunds/verifyRecentAddressBalanceChanges.d.ts +9 -0
  120. package/dist/src/dpp/verify/AddressFunds/verifyRecentAddressBalanceChanges.js +24 -0
  121. package/dist/src/dpp/verify/AddressFunds/verifyRecentCompactedAddressBalanceChanges.d.ts +10 -0
  122. package/dist/src/dpp/verify/AddressFunds/verifyRecentCompactedAddressBalanceChanges.js +30 -0
  123. package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.d.ts +1 -1
  124. package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.js +1 -1
  125. package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.d.ts +2 -0
  126. package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.js +9 -0
  127. package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.d.ts +2 -0
  128. package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.js +9 -0
  129. package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.d.ts +2 -0
  130. package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.js +15 -0
  131. package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.d.ts +2 -0
  132. package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.js +9 -0
  133. package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.d.ts +2 -0
  134. package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.js +12 -0
  135. package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.d.ts +2 -0
  136. package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.js +9 -0
  137. package/dist/src/dpp/verify/StateTransition/utils.js +76 -11
  138. package/dist/src/dpp/verify/StateTransition/verifyStateTransitionResult.js +2 -1
  139. package/dist/src/dpp/verify/System/verifyFinalizedEpochInfosProof.d.ts +2 -0
  140. package/dist/src/dpp/verify/System/verifyFinalizedEpochInfosProof.js +27 -0
  141. package/dist/src/native.d.ts +3 -0
  142. package/dist/src/native.js +8 -0
  143. package/dist/utils/{base122.js → base122.cjs} +3 -1
  144. package/package.json +17 -27
  145. package/tests/unit/AddressTransitionsFees.spec.ts +274 -0
  146. package/tests/unit/DataContract.spec.ts +281 -0
  147. package/tests/unit/DynamicValue.spec.ts +2 -2
  148. package/tests/unit/Identifier.spec.ts +1 -1
  149. package/tests/unit/Identity.spec.ts +1 -1
  150. package/tests/unit/IdentityPublicKey.spec.ts +1 -1
  151. package/tests/unit/NodeApi.spec.ts +49 -0
  152. package/tests/unit/Shielded.spec.ts +555 -0
  153. package/tests/unit/ShieldedTransitions.spec.ts +877 -0
  154. package/tests/unit/StateTransitionFees.spec.ts +177 -0
  155. package/tests/unit/TokenConfiguration.spec.ts +114 -0
  156. package/tests/unit/WebAssembly.spec.ts +88 -0
  157. package/tests/unit/utils/buildTokenConfiguration.ts +66 -0
  158. package/dist/binaries/pshenmic_dpp.android.node/x86_64/libpshenmic_dpp.so +0 -0
  159. package/dist/binaries/wasm/wasmBytes.d.ts +0 -2
  160. package/dist/binaries/wasm/wasmBytes.js +0 -2
  161. /package/dist/utils/{base122.d.ts → base122.d.cts} +0 -0
@@ -75,6 +75,35 @@ const converters = () => {
75
75
  })]
76
76
  ]);
77
77
  };
78
+ function convertPlatformAddressInfos(infos) {
79
+ return infos.map(info => ({
80
+ nonce: info.nonce,
81
+ address: PlatformAddressWASM.createFromRawInstance(info.address),
82
+ balance: info.credits != null ? BigInt(info.credits) : undefined
83
+ }));
84
+ }
85
+ function convertVerifiedDocuments(docs) {
86
+ return docs.map(item => ({
87
+ id: IdentifierWASM.createFromRawInstance(item.id),
88
+ document: item.document != null
89
+ ? DocumentWASM.createFromRawInstance(item.document)
90
+ : undefined
91
+ }));
92
+ }
93
+ function convertAssetLockValue(v) {
94
+ return {
95
+ initialCreditValue: BigInt(v.initialCreditValue),
96
+ txOutScript: v.txOutScript,
97
+ remainingCreditValue: BigInt(v.remainingCreditValue),
98
+ usedTags: v.usedTags
99
+ };
100
+ }
101
+ function convertStoredAssetLockInfo(v) {
102
+ return {
103
+ type: v.type,
104
+ value: v.value != null ? convertAssetLockValue(v.value) : undefined
105
+ };
106
+ }
78
107
  function convertArray(result) {
79
108
  const [first] = result;
80
109
  if (first == null)
@@ -86,26 +115,62 @@ function convertArray(result) {
86
115
  }));
87
116
  }
88
117
  if (first instanceof dppProvider.dpp.VerifiedDocumentNAPI) {
89
- return result.map(item => ({
90
- id: IdentifierWASM.createFromRawInstance(item.id),
91
- document: item.document != null
92
- ? DocumentWASM.createFromRawInstance(item.document)
93
- : undefined
94
- }));
118
+ return convertVerifiedDocuments(result);
95
119
  }
96
120
  if (first instanceof dppProvider.dpp.PlatformAddressInfoNAPI) {
97
- return result.map(item => ({
98
- nonce: item.nonce,
99
- address: PlatformAddressWASM.createFromRawInstance(item.address),
100
- balance: item.credits != null ? BigInt(item.credits) : undefined
101
- }));
121
+ return convertPlatformAddressInfos(result);
102
122
  }
103
123
  throw new Error('Unknown array type');
104
124
  }
125
+ function convertTuple(result) {
126
+ const [first, second] = result;
127
+ if (first instanceof dppProvider.dpp.StoredAssetLockInfoNAPI) {
128
+ return {
129
+ storedAssetLockInfo: convertStoredAssetLockInfo(first),
130
+ infos: convertPlatformAddressInfos(second)
131
+ };
132
+ }
133
+ if (first instanceof dppProvider.dpp.IdentityNAPI) {
134
+ return {
135
+ identity: IdentityWASM.createFromRawInstance(first),
136
+ nullifiers: second
137
+ };
138
+ }
139
+ if (Array.isArray(first) && Array.isArray(second)) {
140
+ const secondFirst = second[0];
141
+ if (secondFirst != null && secondFirst instanceof dppProvider.dpp.VerifiedDocumentNAPI) {
142
+ return {
143
+ nullifiers: first,
144
+ documents: convertVerifiedDocuments(second)
145
+ };
146
+ }
147
+ return {
148
+ nullifiers: first,
149
+ infos: secondFirst != null ? convertPlatformAddressInfos(second) : []
150
+ };
151
+ }
152
+ throw new Error('Unknown tuple type');
153
+ }
105
154
  export function convertResult(result) {
106
155
  if (Array.isArray(result)) {
156
+ if (result.length === 2) {
157
+ const [first] = result;
158
+ if (first instanceof dppProvider.dpp.StoredAssetLockInfoNAPI || first instanceof dppProvider.dpp.IdentityNAPI) {
159
+ return convertTuple(result);
160
+ }
161
+ if (Array.isArray(first) && (first.length === 0 || Array.isArray(first[0]))) {
162
+ return convertTuple(result);
163
+ }
164
+ }
165
+ const [first] = result;
166
+ if (first != null && Array.isArray(first) && first[0] instanceof Uint8Array) {
167
+ return result;
168
+ }
107
169
  return convertArray(result);
108
170
  }
171
+ if (result instanceof dppProvider.dpp.StoredAssetLockInfoNAPI) {
172
+ return convertStoredAssetLockInfo(result);
173
+ }
109
174
  for (const [Type, handler] of converters()) {
110
175
  if (result instanceof Type) {
111
176
  return handler(result);
@@ -5,6 +5,7 @@ export function verifyStateTransitionResult(proof, stateTransition, blockInfo, k
5
5
  const verified = dppProvider.dpp.verifyStateTransitionResult(proof, stateTransition._rawStateTransition, new dppProvider.dpp.BlockInfoNAPI(blockInfo.timeMs.toString(), blockInfo.height.toString(), blockInfo.coreHeight, blockInfo.epoch), knownContractsArray.map(contract => contract._rawDataContract), valueToDynamicValue(platformVersion));
6
6
  return {
7
7
  rootHash: verified.rootHash,
8
- result: convertResult(verified.result)
8
+ result: convertResult(verified.result),
9
+ isExecutionProved: verified.isExecutionProved
9
10
  };
10
11
  }
@@ -0,0 +1,2 @@
1
+ import { PlatformVersionLike, VerifiedFinalizedEpochsInfo } from "../../types.js";
2
+ export declare function verifyFinalizedEpochInfosProof(proof: Uint8Array, startEpoch: number, startEpochIncluded: boolean, endEpoch: number, endEpochIncluded: boolean, platformVersion: PlatformVersionLike): VerifiedFinalizedEpochsInfo;
@@ -0,0 +1,27 @@
1
+ import { dppProvider } from '../../provider.js';
2
+ import { valueToDynamicValue } from '../../utils.js';
3
+ import { IdentifierWASM } from "../../structs/Identifier.js";
4
+ export function verifyFinalizedEpochInfosProof(proof, startEpoch, startEpochIncluded, endEpoch, endEpochIncluded, platformVersion) {
5
+ const result = dppProvider.dpp.verifyFinalizedEpochInfosProof(proof, startEpoch, startEpochIncluded, endEpoch, endEpochIncluded, valueToDynamicValue(platformVersion));
6
+ return {
7
+ rootHash: result.rootHash,
8
+ epochInfos: result.epochInfos.map(([epochIndex, info]) => ({
9
+ epochIndex: epochIndex,
10
+ firstBlockTime: new Date(Number(info.firstBlockTime)),
11
+ firstBlockHeight: BigInt(info.firstBlockHeight),
12
+ totalBlocksInEpoch: BigInt(info.totalBlocksInEpoch),
13
+ firstCoreBlockHeight: info.firstCoreBlockHeight,
14
+ nextEpochStartCoreBlockHeight: info.nextEpochStartCoreBlockHeight,
15
+ totalProcessingFees: BigInt(info.totalProcessingFees),
16
+ totalDistributedStorageFees: BigInt(info.totalDistributedStorageFees),
17
+ totalCreatedStorageFees: BigInt(info.totalCreatedStorageFees),
18
+ coreBlockRewards: BigInt(info.coreBlockRewards),
19
+ blockProposers: info.blockProposers.map(([proposer, count]) => ({
20
+ proposer: IdentifierWASM.createFromRawInstance(proposer),
21
+ count: BigInt(count),
22
+ })),
23
+ feeMultiplierPermille: BigInt(info.feeMultiplierPermille),
24
+ protocolVersion: info.protocolVersion,
25
+ }))
26
+ };
27
+ }
@@ -0,0 +1,3 @@
1
+ export * from './dpp/enums.js';
2
+ export * from './dpp/dpp.js';
3
+ export * from './dpp/types.js';
@@ -0,0 +1,8 @@
1
+ // @ts-ignore
2
+ import protocol from '../binaries/node.cjs';
3
+ import { dppProvider } from './dpp/provider.js';
4
+ // @ts-ignore
5
+ dppProvider.setDpp(protocol);
6
+ export * from './dpp/enums.js';
7
+ export * from './dpp/dpp.js';
8
+ export * from './dpp/types.js';
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  // Original code: https://github.com/kevinAlbs/Base122
2
3
  // Provides functions for encoding/decoding data to and from base-122.
3
4
  const kIllegals = [
@@ -15,7 +16,7 @@ const kShortened = 0b111; // Uses the illegal index to signify the last two-byte
15
16
  * with raw data bytes or a string of bytes (i.e. the type of argument to btoa())
16
17
  * @returns {Uint8Array} The data in a regular array representing byte values.
17
18
  */
18
- export function decode(base122Data) {
19
+ function decode(base122Data) {
19
20
  const strData = typeof (base122Data) === 'string' ? base122Data : utf8DataToString(base122Data);
20
21
  const decoded = [];
21
22
  let curByte = 0;
@@ -61,3 +62,4 @@ export function decode(base122Data) {
61
62
  function utf8DataToString(data) {
62
63
  return new TextDecoder().decode(data);
63
64
  }
65
+ module.exports = { decode };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "pshenmic-dpp",
3
- "version": "2.0.0-dev.9",
3
+ "version": "2.0.0",
4
4
  "main": "dist/src/wasm.js",
5
5
  "types": "dist/src/wasm.d.ts",
6
6
  "react-native": "./dist/src/react-native.js",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/owl352/pshenmic-dpp"
10
+ "url": "git+https://github.com/owl352/pshenmic-dpp.git"
11
11
  },
12
12
  "scripts": {
13
13
  "build:bin": "node build.cjs",
14
- "build:ts": "tsc && cp -R pkg/**/*.*.node dist/binaries/",
14
+ "build:ts": "tsc && cp -R pkg/**/*.*.node dist/binaries/ && cp -R pkg/binaries/native dist/binaries/",
15
15
  "build:full": "npm run build:bin && npm run build:ts",
16
16
  "ferric:build": "ferric build",
17
17
  "bundle": "rollup -c",
@@ -20,41 +20,31 @@
20
20
  "lint:rust": "cargo fmt",
21
21
  "lint:src": "ts-standard --fix ./pkg/src",
22
22
  "lint:tests": "ts-standard --fix ./pkg/src",
23
- "lint": "npm run lint:rust && npm run lint:src && npm run lint:tests"
23
+ "lint": "npm run lint:rust && npm run lint:src && npm run lint:tests",
24
+ "prepack": "npm pkg delete devDependencies"
24
25
  },
25
26
  "files": [
26
27
  "dist/",
27
28
  "tests/"
28
29
  ],
30
+ "exports": {
31
+ ".": {
32
+ "browser": "./dist/src/wasm.js",
33
+ "node": "./dist/src/native.js",
34
+ "react-native": "./dist/src/react-native.js",
35
+ "default": "./dist/src/wasm.js"
36
+ },
37
+ "./wasm": "./dist/src/wasm.js",
38
+ "./wasm/utils": "./dist/src/dpp/utils.js",
39
+ "./native": "./dist/src/native.js"
40
+ },
29
41
  "author": "owl352",
30
42
  "license": "ISC",
31
43
  "description": "",
32
- "devDependencies": {
33
- "@babel/core": "^7.28.5",
34
- "@babel/preset-env": "^7.28.5",
35
- "@babel/preset-typescript": "^7.28.5",
36
- "@scure/base": "^1.2.4",
37
- "@types/jest": "^30.0.0",
38
- "@types/node": "^24.0.13",
39
- "babel": "^6.23.0",
40
- "babel-jest": "^30.2.0",
41
- "core-js": "^3.41.0",
42
- "ferric-cli": "0.3.9",
43
- "jest": "^30.2.0",
44
- "mocha": "^11.1.0",
45
- "node-addon-api": "^8.5.0",
46
- "path": "^0.12.7",
47
- "toml": "^3.0.0",
48
- "ts-morph": "^26.0.0",
49
- "tsx": "^4.20.6",
50
- "typedoc": "^0.28.7",
51
- "typescript": "^5.8.3",
52
- "ts-standard": "^12.0.2"
53
- },
54
44
  "dependencies": {
55
45
  "@emnapi/core": "1.9.0",
56
46
  "@emnapi/runtime": "1.9.0",
57
47
  "@tybys/wasm-util": "^0.10.1",
58
- "fflate": "^0.8.2"
48
+ "fflate": "^0.8.3"
59
49
  }
60
50
  }
@@ -0,0 +1,274 @@
1
+ import {
2
+ AddressCreditWithdrawalTransitionWASM,
3
+ AddressFundingFromAssetLockTransitionWASM,
4
+ AddressFundsFeeStrategyStepWASM,
5
+ AddressFundsTransferTransitionWASM,
6
+ AddressWitnessWASM,
7
+ AssetLockProofWASM,
8
+ CoreScriptWASM,
9
+ IdentityCreateFromAddressesTransitionWASM,
10
+ IdentityCreditTransferToAddressesTransitionWASM,
11
+ IdentityPublicKeyInCreationWASM,
12
+ IdentityTopUpFromAddressesTransitionWASM,
13
+ InputAddressWASM,
14
+ KeyType,
15
+ OutPointWASM,
16
+ OutputAddressNullableCreditsWASM,
17
+ OutputAddressWASM,
18
+ PlatformAddressWASM,
19
+ PlatformVersionWASM,
20
+ Purpose,
21
+ SecurityLevel
22
+ } from 'pshenmic-dpp'
23
+
24
+ // Min fee components from the platform fee version (STATE_TRANSITION_MIN_FEES_VERSION1)
25
+ // Storage charged by the node for one address balance entry that does not exist yet,
26
+ // as pinned by platform's own fee regression suite.
27
+ const NEW_ADDRESS_STORAGE_FEE = BigInt(6075000)
28
+ const INPUT_COST = BigInt(500000)
29
+ const OUTPUT_COST = BigInt(6000000)
30
+ const ADDRESS_CREDIT_WITHDRAWAL_COST = BigInt(400000000)
31
+ const IDENTITY_CREATE_BASE_COST = BigInt(2000000)
32
+ const IDENTITY_KEY_IN_CREATION_COST = BigInt(6500000)
33
+ const IDENTITY_TOPUP_BASE_COST = BigInt(500000)
34
+ const CREDIT_TRANSFER_TO_ADDRESSES_COST = BigInt(500000)
35
+
36
+ function randomBytes (length: number): Uint8Array {
37
+ const bytes = new Uint8Array(length)
38
+ for (let i = 0; i < length; i++) {
39
+ bytes[i] = Math.floor(Math.random() * 256)
40
+ }
41
+ return bytes
42
+ }
43
+
44
+ function createTestAddress (): PlatformAddressWASM {
45
+ const addressBytes = new Uint8Array(21)
46
+ addressBytes[0] = 0x00
47
+ addressBytes.set(randomBytes(20), 1)
48
+ return PlatformAddressWASM.fromBytes(addressBytes)
49
+ }
50
+
51
+ function createTestInputs (count: number): InputAddressWASM[] {
52
+ return Array.from(
53
+ { length: count },
54
+ () => new InputAddressWASM(createTestAddress(), 0, BigInt(500000000))
55
+ )
56
+ }
57
+
58
+ function createTestOutputs (count: number): OutputAddressWASM[] {
59
+ return Array.from(
60
+ { length: count },
61
+ () => new OutputAddressWASM(createTestAddress(), BigInt(100000))
62
+ )
63
+ }
64
+
65
+ function createTestWitnesses (count: number): AddressWitnessWASM[] {
66
+ return Array.from({ length: count }, () => AddressWitnessWASM.P2PKH(randomBytes(65)))
67
+ }
68
+
69
+ const feeStrategy = (): AddressFundsFeeStrategyStepWASM[] =>
70
+ [AddressFundsFeeStrategyStepWASM.DeductFromInput(0)]
71
+
72
+ describe('AddressFundsTransferTransition fees', function () {
73
+ describe('estimateMinFee', function () {
74
+ test('should price inputs and outputs', function () {
75
+ expect(AddressFundsTransferTransitionWASM.estimateMinFee(1, 1))
76
+ .toEqual(INPUT_COST + OUTPUT_COST)
77
+
78
+ expect(AddressFundsTransferTransitionWASM.estimateMinFee(2, 3))
79
+ .toEqual(INPUT_COST * BigInt(2) + OUTPUT_COST * BigInt(3))
80
+ })
81
+
82
+ test('should charge at least one output', function () {
83
+ expect(AddressFundsTransferTransitionWASM.estimateMinFee(1, 0))
84
+ .toEqual(AddressFundsTransferTransitionWASM.estimateMinFee(1, 1))
85
+ })
86
+
87
+ test('should grow with the input and output counts', function () {
88
+ const one = AddressFundsTransferTransitionWASM.estimateMinFee(1, 1)
89
+ const two = AddressFundsTransferTransitionWASM.estimateMinFee(2, 2)
90
+
91
+ expect(two).toBeGreaterThan(one)
92
+ })
93
+
94
+ test('should default to the latest platform version', function () {
95
+ expect(AddressFundsTransferTransitionWASM.estimateMinFee(1, 1))
96
+ .toEqual(AddressFundsTransferTransitionWASM.estimateMinFee(1, 1, PlatformVersionWASM.PLATFORM_V13))
97
+ })
98
+ })
99
+
100
+ describe('calculateMinRequiredFee', function () {
101
+ test('should match the estimate for the transition inputs and outputs', function () {
102
+ const transition = new AddressFundsTransferTransitionWASM(
103
+ createTestInputs(2),
104
+ feeStrategy(),
105
+ 0,
106
+ createTestWitnesses(2),
107
+ createTestOutputs(1)
108
+ )
109
+
110
+ expect(transition.calculateMinRequiredFee())
111
+ .toEqual(AddressFundsTransferTransitionWASM.estimateMinFee(2, 1))
112
+ })
113
+ })
114
+ })
115
+
116
+ describe('AddressCreditWithdrawalTransition fees', function () {
117
+ const outputScript = (): CoreScriptWASM => CoreScriptWASM.newP2PKH(randomBytes(20))
118
+
119
+ describe('estimateMinFee', function () {
120
+ test('should price the withdrawal, its inputs and its change output', function () {
121
+ expect(AddressCreditWithdrawalTransitionWASM.estimateMinFee(1, false))
122
+ .toEqual(ADDRESS_CREDIT_WITHDRAWAL_COST + INPUT_COST)
123
+
124
+ expect(AddressCreditWithdrawalTransitionWASM.estimateMinFee(1, true))
125
+ .toEqual(ADDRESS_CREDIT_WITHDRAWAL_COST + INPUT_COST + OUTPUT_COST)
126
+ })
127
+
128
+ test('should grow with the input count', function () {
129
+ expect(AddressCreditWithdrawalTransitionWASM.estimateMinFee(2, false))
130
+ .toBeGreaterThan(AddressCreditWithdrawalTransitionWASM.estimateMinFee(1, false))
131
+ })
132
+ })
133
+
134
+ describe('calculateMinRequiredFee', function () {
135
+ test('should match the estimate without a change output', function () {
136
+ const transition = new AddressCreditWithdrawalTransitionWASM(
137
+ createTestInputs(1),
138
+ feeStrategy(),
139
+ 1,
140
+ 'Standard',
141
+ outputScript(),
142
+ 0,
143
+ createTestWitnesses(1)
144
+ )
145
+
146
+ expect(transition.calculateMinRequiredFee())
147
+ .toEqual(AddressCreditWithdrawalTransitionWASM.estimateMinFee(1, false))
148
+ })
149
+
150
+ test('should match the estimate with a change output', function () {
151
+ const transition = new AddressCreditWithdrawalTransitionWASM(
152
+ createTestInputs(1),
153
+ feeStrategy(),
154
+ 1,
155
+ 'Standard',
156
+ outputScript(),
157
+ 0,
158
+ createTestWitnesses(1),
159
+ createTestOutputs(1)[0]
160
+ )
161
+
162
+ expect(transition.calculateMinRequiredFee())
163
+ .toEqual(AddressCreditWithdrawalTransitionWASM.estimateMinFee(1, true))
164
+ })
165
+ })
166
+ })
167
+
168
+ describe('IdentityCreateFromAddressesTransition fees', function () {
169
+ test('calculateMinRequiredFee should price the base cost, inputs, output and keys', function () {
170
+ const publicKeys = [
171
+ new IdentityPublicKeyInCreationWASM(
172
+ 0,
173
+ Purpose.AUTHENTICATION,
174
+ SecurityLevel.MASTER,
175
+ KeyType.ECDSA_SECP256K1,
176
+ false,
177
+ randomBytes(33)
178
+ )
179
+ ]
180
+
181
+ const transition = new IdentityCreateFromAddressesTransitionWASM(
182
+ publicKeys,
183
+ createTestInputs(1),
184
+ feeStrategy(),
185
+ 0,
186
+ createTestWitnesses(1),
187
+ createTestOutputs(1)[0]
188
+ )
189
+
190
+ expect(transition.calculateMinRequiredFee()).toEqual(
191
+ IDENTITY_CREATE_BASE_COST + INPUT_COST + OUTPUT_COST + IDENTITY_KEY_IN_CREATION_COST
192
+ )
193
+ })
194
+ })
195
+
196
+ describe('IdentityTopUpFromAddressesTransition fees', function () {
197
+ test('calculateMinRequiredFee should price the base cost, inputs and output', function () {
198
+ const transition = new IdentityTopUpFromAddressesTransitionWASM(
199
+ randomBytes(32),
200
+ createTestInputs(1),
201
+ feeStrategy(),
202
+ 0,
203
+ createTestWitnesses(1),
204
+ createTestOutputs(1)[0]
205
+ )
206
+
207
+ expect(transition.calculateMinRequiredFee())
208
+ .toEqual(IDENTITY_TOPUP_BASE_COST + INPUT_COST + OUTPUT_COST)
209
+ })
210
+ })
211
+
212
+ describe('IdentityCreditTransferToAddressesTransition fees', function () {
213
+ test('calculateMinRequiredFee should price the base cost and each recipient', function () {
214
+ const transition = new IdentityCreditTransferToAddressesTransitionWASM(
215
+ randomBytes(32),
216
+ createTestOutputs(2),
217
+ BigInt(1),
218
+ 0
219
+ )
220
+
221
+ expect(transition.calculateMinRequiredFee())
222
+ .toEqual(CREDIT_TRANSFER_TO_ADDRESSES_COST + OUTPUT_COST * BigInt(2))
223
+ })
224
+ })
225
+
226
+ describe('AddressFundingFromAssetLockTransition fees', function () {
227
+ test('calculateMinRequiredFee should include the asset lock base cost', function () {
228
+ const outPoint = new OutPointWASM('a'.repeat(64), 0)
229
+ const assetLockProof = AssetLockProofWASM.createChainAssetLockProof(100, outPoint)
230
+
231
+ const transition = new AddressFundingFromAssetLockTransitionWASM(
232
+ assetLockProof,
233
+ createTestInputs(1),
234
+ feeStrategy(),
235
+ 0,
236
+ createTestWitnesses(1),
237
+ [new OutputAddressNullableCreditsWASM(createTestAddress(), BigInt(100000))]
238
+ )
239
+
240
+ const fee = transition.calculateMinRequiredFee()
241
+
242
+ expect(typeof fee).toEqual('bigint')
243
+ expect(fee).toBeGreaterThan(INPUT_COST + OUTPUT_COST)
244
+ })
245
+ })
246
+
247
+ describe('new address storage fee', function () {
248
+ test('should match the storage the node charges for one created address', function () {
249
+ expect(PlatformAddressWASM.estimateStorageFeeForNewAddresses(1))
250
+ .toEqual(NEW_ADDRESS_STORAGE_FEE)
251
+ })
252
+
253
+ test('should scale with the number of created addresses', function () {
254
+ expect(PlatformAddressWASM.estimateStorageFeeForNewAddresses(0)).toEqual(BigInt(0))
255
+ expect(PlatformAddressWASM.estimateStorageFeeForNewAddresses(3))
256
+ .toEqual(NEW_ADDRESS_STORAGE_FEE * BigInt(3))
257
+ })
258
+
259
+ test('should default to the latest platform version', function () {
260
+ expect(PlatformAddressWASM.estimateStorageFeeForNewAddresses(1))
261
+ .toEqual(PlatformAddressWASM.estimateStorageFeeForNewAddresses(1, PlatformVersionWASM.PLATFORM_V13))
262
+ })
263
+
264
+ test('should exceed the per output component of the min fee', function () {
265
+ const perOutput =
266
+ AddressFundsTransferTransitionWASM.estimateMinFee(1, 2) -
267
+ AddressFundsTransferTransitionWASM.estimateMinFee(1, 1)
268
+
269
+ // The min fee prices an output slightly below what a created address costs in storage,
270
+ // which is why a transfer paying a brand new address is charged a little more than its
271
+ // minimum required fee.
272
+ expect(NEW_ADDRESS_STORAGE_FEE).toBeGreaterThan(perOutput)
273
+ })
274
+ })