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
@@ -0,0 +1,177 @@
1
+ import {
2
+ AssetLockProofWASM,
3
+ BatchTransitionWASM,
4
+ CoreScriptWASM,
5
+ DataContractCreateTransitionWASM,
6
+ DataContractWASM,
7
+ IdentityCreateTransitionWASM,
8
+ IdentityCreditTransferWASM,
9
+ IdentityCreditWithdrawalTransitionWASM,
10
+ IdentityPublicKeyInCreationWASM,
11
+ IdentityTopUpTransitionWASM,
12
+ IdentityUpdateTransitionWASM,
13
+ KeyType,
14
+ OutPointWASM,
15
+ Purpose,
16
+ SecurityLevel,
17
+ StateTransitionWASM
18
+ } from 'pshenmic-dpp'
19
+
20
+ // Min fees from the platform fee version (STATE_TRANSITION_MIN_FEES_VERSION1)
21
+ const CREDIT_TRANSFER_COST = BigInt(100000)
22
+ const CREDIT_WITHDRAWAL_COST = BigInt(400000000)
23
+ const IDENTITY_UPDATE_COST = BigInt(100000)
24
+ const CONTRACT_CREATE_COST = BigInt(100000)
25
+ const DOCUMENT_BATCH_SUB_TRANSITION_COST = BigInt(100000)
26
+ const IDENTITY_CREATE_BASE_COST = BigInt(2000000)
27
+ const IDENTITY_KEY_IN_CREATION_COST = BigInt(6500000)
28
+ const IDENTITY_TOPUP_BASE_COST = BigInt(500000)
29
+ // required asset lock duff balance × CREDITS_PER_DUFF (1000)
30
+ const IDENTITY_CREATE_ASSET_LOCK_COST = BigInt(200000) * BigInt(1000)
31
+ const IDENTITY_TOPUP_ASSET_LOCK_COST = BigInt(50000) * BigInt(1000)
32
+
33
+ // A signed document batch transition holding a single document create transition
34
+ const BATCH_TRANSITION_BASE64 = 'AgHv88sfWzscuW2Ob/0v5d+EgqmWG7ZIvlQG7mHWBH7z9gEAAAAB7JH7W+JkM0Vne2U1zlWYVeQNzRPTpdiWRfsgfwNS2UoCCGJsb2dQb3N0KBdMgeznVQ1smUXVFNPfE2PC379wpWVH8cdu2ilzeI0Ah/i2xfrKCm5ACQAbEQkSc+GRUkdLor4Eu7Vzf6oRc9UHBmJsb2dJZAogdhC4nVm3ufPCgdfoOKXtnhqwg7O3axyTS9WB3EFvNBYPY29tbWVudHNFbmFibGVkEwEHY29udGVudAr7AUh4nM2TTWrDMBCFrxK0jkCyJMvqLnRV6A1KFhpplJgotrEVaAi+e8clpdBuvCnNcn7ezPvQ6O3G2siemKgNSGETT8ZarhUm7hpX8yStEpVCk6xlW1auA1L34Ed/GP1wpNQw9sPEnm6s4Ht57nM/UkPE5C+5UBl8OB3G/tLF37VFscvtoTtjV6iSMRU2b1nou/KZIXf3jUvrXUHRrosbv8ltKRk30JbNl2LLpnLNuPiZ5z1NOrY5jtjRqP28vbM656zTleagJHCNXnIQiUIpgozGg2/0N2s4Yji9tlN5KXj+A97FJG1AcpZ8nnANv1wHGo22ASrFXQDJde0SBzDIdQBVRQEoDDw2aLUONPkKtfF0s9bR9bqGkJW3PNYCg/FOgIqPDarWgQrRxKapBXdCJ3pR7TjUVnJrpAo6yhSc/4dv+tPu/gNBt2qtC3B1Ymxpc2hlZEF0Av0AAAGcptJlIwRzbHVnEhV0aGlzLWlzLW15LWZpcnN0LXBvc3QIc3VidGl0bGUSD1dpdGggYSBzdWJ0aXRsZQV0aXRsZRIVVGhpcyBpcyBteSBmaXJzdCBwb3N0AAABQR+H40MbUEmFXQbTPcwy9vMD8EiTwDzMpW3YIkfSIDvHij5ZIAVvqm0ZJScJzKV7EnRUi/f1tZ/wFJfd1+LDtpps'
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 createTestKey (): IdentityPublicKeyInCreationWASM {
45
+ return new IdentityPublicKeyInCreationWASM(
46
+ 0,
47
+ Purpose.AUTHENTICATION,
48
+ SecurityLevel.MASTER,
49
+ KeyType.ECDSA_SECP256K1,
50
+ false,
51
+ randomBytes(33)
52
+ )
53
+ }
54
+
55
+ function createAssetLockProof (): AssetLockProofWASM {
56
+ return AssetLockProofWASM.createChainAssetLockProof(100, new OutPointWASM('a'.repeat(64), 0))
57
+ }
58
+
59
+ describe('IdentityCreditTransferTransition fees', function () {
60
+ test('calculateMinRequiredFee should return the credit transfer min fee', function () {
61
+ const transition = new IdentityCreditTransferWASM(
62
+ randomBytes(32), BigInt(100000), randomBytes(32), BigInt(1)
63
+ )
64
+
65
+ expect(transition.calculateMinRequiredFee()).toEqual(CREDIT_TRANSFER_COST)
66
+ })
67
+ })
68
+
69
+ describe('IdentityCreditWithdrawalTransition fees', function () {
70
+ test('calculateMinRequiredFee should return the credit withdrawal min fee', function () {
71
+ const transition = new IdentityCreditWithdrawalTransitionWASM(
72
+ randomBytes(32),
73
+ BigInt(1000000),
74
+ 1,
75
+ 'Standard',
76
+ BigInt(1),
77
+ CoreScriptWASM.newP2PKH(randomBytes(20))
78
+ )
79
+
80
+ expect(transition.calculateMinRequiredFee()).toEqual(CREDIT_WITHDRAWAL_COST)
81
+ })
82
+ })
83
+
84
+ describe('IdentityUpdateTransition fees', function () {
85
+ test('calculateMinRequiredFee should return the identity update min fee', function () {
86
+ const transition = new IdentityUpdateTransitionWASM(
87
+ randomBytes(32), BigInt(1), BigInt(1), [createTestKey()], []
88
+ )
89
+
90
+ expect(transition.calculateMinRequiredFee()).toEqual(IDENTITY_UPDATE_COST)
91
+ })
92
+ })
93
+
94
+ describe('IdentityCreateTransition fees', function () {
95
+ test('calculateMinRequiredFee should price the base cost, asset lock and keys', function () {
96
+ const transition = new IdentityCreateTransitionWASM([createTestKey()], createAssetLockProof())
97
+
98
+ expect(transition.calculateMinRequiredFee()).toEqual(
99
+ IDENTITY_CREATE_BASE_COST + IDENTITY_CREATE_ASSET_LOCK_COST + IDENTITY_KEY_IN_CREATION_COST
100
+ )
101
+ })
102
+
103
+ test('calculateMinRequiredFee should grow with the key count', function () {
104
+ const oneKey = new IdentityCreateTransitionWASM([createTestKey()], createAssetLockProof())
105
+ const twoKeys = new IdentityCreateTransitionWASM(
106
+ [createTestKey(), createTestKey()], createAssetLockProof()
107
+ )
108
+
109
+ expect(twoKeys.calculateMinRequiredFee() - oneKey.calculateMinRequiredFee())
110
+ .toEqual(IDENTITY_KEY_IN_CREATION_COST)
111
+ })
112
+ })
113
+
114
+ describe('IdentityTopUpTransition fees', function () {
115
+ test('calculateMinRequiredFee should price the base cost and the asset lock', function () {
116
+ const transition = new IdentityTopUpTransitionWASM(createAssetLockProof(), randomBytes(32))
117
+
118
+ expect(transition.calculateMinRequiredFee())
119
+ .toEqual(IDENTITY_TOPUP_BASE_COST + IDENTITY_TOPUP_ASSET_LOCK_COST)
120
+ })
121
+ })
122
+
123
+ describe('BatchTransition fees', function () {
124
+ test('calculateMinRequiredFee should price each sub transition', function () {
125
+ const batch = BatchTransitionWASM.fromStateTransition(
126
+ StateTransitionWASM.fromBase64(BATCH_TRANSITION_BASE64)
127
+ )
128
+
129
+ expect(batch.calculateMinRequiredFee())
130
+ .toEqual(DOCUMENT_BATCH_SUB_TRANSITION_COST * BigInt(batch.transitions.length))
131
+ })
132
+ })
133
+
134
+ describe('StateTransition fees', function () {
135
+ test('calculateMinRequiredFee should match the concrete transition', function () {
136
+ const transition = new IdentityCreditTransferWASM(
137
+ randomBytes(32), BigInt(100000), randomBytes(32), BigInt(1)
138
+ )
139
+
140
+ expect(transition.toStateTransition().calculateMinRequiredFee())
141
+ .toEqual(transition.calculateMinRequiredFee())
142
+ })
143
+
144
+ test('calculateMinRequiredFee should work for a deserialized transition', function () {
145
+ const stateTransition = StateTransitionWASM.fromBase64(BATCH_TRANSITION_BASE64)
146
+
147
+ expect(stateTransition.calculateMinRequiredFee())
148
+ .toEqual(DOCUMENT_BATCH_SUB_TRANSITION_COST)
149
+ })
150
+ })
151
+
152
+ describe('DataContractCreateTransition fees', function () {
153
+ const OWNER_ID_BASE58 = 'HEAmUtC72dPcZ59yyLUgfS8pfrEWqzYfDPzTofgWxXRr'
154
+ const DOCUMENT_SCHEMA = {
155
+ note: {
156
+ type: 'object',
157
+ properties: {
158
+ message: {
159
+ type: 'string',
160
+ position: 0
161
+ }
162
+ },
163
+ additionalProperties: false
164
+ }
165
+ }
166
+
167
+ test('calculateMinRequiredFee should cover the base fee plus the registration cost', function () {
168
+ const contract = new DataContractWASM(
169
+ OWNER_ID_BASE58, BigInt(1), DOCUMENT_SCHEMA, undefined, undefined, true
170
+ )
171
+ const transition = new DataContractCreateTransitionWASM(contract, BigInt(1))
172
+
173
+ expect(transition.calculateMinRequiredFee()).toBeGreaterThanOrEqual(CONTRACT_CREATE_COST)
174
+ expect(transition.calculateMinRequiredFee())
175
+ .toEqual(transition.toStateTransition().calculateMinRequiredFee())
176
+ })
177
+ })
@@ -0,0 +1,114 @@
1
+ import {
2
+ AuthorizedActionTakersWASM,
3
+ IdentifierWASM,
4
+ TokenConfigurationWASM
5
+ } from 'pshenmic-dpp'
6
+ import { buildTokenConfiguration } from './utils/buildTokenConfiguration'
7
+
8
+ describe('TokenConfiguration', function () {
9
+ describe('constructor', function () {
10
+ test('should build a token configuration with defaults from the helper', function () {
11
+ const config = buildTokenConfiguration()
12
+
13
+ expect(config).toBeInstanceOf(TokenConfigurationWASM)
14
+ expect(config.baseSupply).toEqual(BigInt(100000))
15
+ expect(config.maxSupply).toBeUndefined()
16
+ expect(config.description).toBeUndefined()
17
+ expect(config.startAsPaused).toEqual(false)
18
+ expect(config.isAllowedTransferToFrozenBalance).toEqual(false)
19
+ })
20
+
21
+ test('should set max supply and description when provided', function () {
22
+ const config = buildTokenConfiguration({
23
+ baseSupply: BigInt(500),
24
+ maxSupply: BigInt(1000),
25
+ description: 'hello'
26
+ })
27
+
28
+ expect(config.baseSupply).toEqual(BigInt(500))
29
+ expect(config.maxSupply).toEqual(BigInt(1000))
30
+ expect(config.description).toEqual('hello')
31
+ })
32
+ })
33
+
34
+ describe('getters', function () {
35
+ test('should expose the convention decimals', function () {
36
+ const config = buildTokenConfiguration()
37
+
38
+ expect(config.conventions.decimals).toEqual(8)
39
+ })
40
+
41
+ test('should default mainControlGroup to undefined', function () {
42
+ const config = buildTokenConfiguration()
43
+
44
+ expect(config.mainControlGroup).toBeUndefined()
45
+ })
46
+ })
47
+
48
+ describe('setters', function () {
49
+ test('should allow updating baseSupply', function () {
50
+ const config = buildTokenConfiguration()
51
+
52
+ config.baseSupply = BigInt(7)
53
+
54
+ expect(config.baseSupply).toEqual(BigInt(7))
55
+ })
56
+
57
+ test('should allow updating maxSupply to a value and back to undefined', function () {
58
+ const config = buildTokenConfiguration()
59
+
60
+ config.maxSupply = BigInt(42)
61
+ expect(config.maxSupply).toEqual(BigInt(42))
62
+
63
+ config.maxSupply = undefined
64
+ expect(config.maxSupply).toBeUndefined()
65
+ })
66
+
67
+ test('should allow updating description', function () {
68
+ const config = buildTokenConfiguration()
69
+
70
+ config.description = 'updated'
71
+
72
+ expect(config.description).toEqual('updated')
73
+ })
74
+
75
+ test('should allow updating startAsPaused / isAllowedTransferToFrozenBalance', function () {
76
+ const config = buildTokenConfiguration()
77
+
78
+ config.startAsPaused = true
79
+ config.isAllowedTransferToFrozenBalance = true
80
+
81
+ expect(config.startAsPaused).toEqual(true)
82
+ expect(config.isAllowedTransferToFrozenBalance).toEqual(true)
83
+ })
84
+
85
+ test('should allow updating mainControlGroup', function () {
86
+ const config = buildTokenConfiguration()
87
+
88
+ config.mainControlGroup = 3
89
+
90
+ expect(config.mainControlGroup).toEqual(3)
91
+ })
92
+
93
+ test('should allow updating mainControlGroupCanBeModified', function () {
94
+ const config = buildTokenConfiguration()
95
+
96
+ config.mainControlGroupCanBeModified = AuthorizedActionTakersWASM.ContractOwner()
97
+
98
+ expect(config.mainControlGroupCanBeModified).toBeDefined()
99
+ })
100
+ })
101
+
102
+ describe('calculateTokenId', function () {
103
+ test('should derive a deterministic token id from a contract id and position', function () {
104
+ const contractId = new IdentifierWASM('HEAmUtC72dPcZ59yyLUgfS8pfrEWqzYfDPzTofgWxXRr')
105
+
106
+ const tokenIdA = TokenConfigurationWASM.calculateTokenId(contractId, 0)
107
+ const tokenIdB = TokenConfigurationWASM.calculateTokenId(contractId, 0)
108
+ const tokenIdC = TokenConfigurationWASM.calculateTokenId(contractId, 1)
109
+
110
+ expect(tokenIdA.base58()).toEqual(tokenIdB.base58())
111
+ expect(tokenIdA.base58()).not.toEqual(tokenIdC.base58())
112
+ })
113
+ })
114
+ })
@@ -0,0 +1,88 @@
1
+ import * as dpp from "pshenmic-dpp/wasm";
2
+ import {IdentifierWASM, ShieldedBuilderWASM} from "pshenmic-dpp/wasm";
3
+
4
+ let identifierBytes: Uint8Array;
5
+
6
+ describe("dpp", function () {
7
+ beforeAll(async function () {
8
+ identifierBytes = Uint8Array.from([
9
+ 9, 40, 40, 237, 192, 129, 211, 186, 26, 84, 240, 67, 37, 155, 148, 19,
10
+ 104, 242, 199, 24, 136, 27, 6, 169, 211, 71, 136, 59, 33, 191, 227, 19,
11
+ ]);
12
+ });
13
+
14
+ it('dpp object shouldn\'t be undefined or empty', () => {
15
+ expect(dpp).toBeDefined();
16
+ });
17
+
18
+ describe('classes accesibles', function () {
19
+ test("should allows to create Identifier from base58 via dpp object", function () {
20
+ const identifier = dpp.IdentifierWASM.fromBase58(
21
+ "ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U",
22
+ );
23
+
24
+ expect(identifier.bytes()).toEqual(identifierBytes);
25
+ });
26
+
27
+ test("should allows to create Identifier from base64 via IdentifierWASM import", function () {
28
+ const identifier = IdentifierWASM.fromBase64(
29
+ "CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM=",
30
+ );
31
+
32
+ expect(identifier.bytes()).toEqual(identifierBytes);
33
+ });
34
+
35
+ test("should allows to create Identifier from hex", function () {
36
+ const identifier = IdentifierWASM.fromHex(
37
+ "092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313",
38
+ );
39
+
40
+ expect(identifier.bytes()).toEqual(identifierBytes);
41
+ });
42
+
43
+ test("should allows to create Identifier from bytes", function () {
44
+ const identifier = IdentifierWASM.fromBytes(identifierBytes);
45
+
46
+ expect(identifier.bytes()).toEqual(identifierBytes);
47
+ });
48
+ })
49
+
50
+ describe('shielded init', function () {
51
+ test('should allow to use old instances after shielded init', async function () {
52
+ const identifier = IdentifierWASM.fromBytes(identifierBytes);
53
+
54
+ const builder = new ShieldedBuilderWASM()
55
+
56
+ await builder.init();
57
+
58
+ expect(identifier.bytes()).toEqual(identifierBytes);
59
+ })
60
+
61
+ test('should build a real Halo 2 proof with instances created before init', async function () {
62
+ const seed = new Uint8Array(64).fill(7);
63
+
64
+ // created BEFORE init — must stay usable by the proving call
65
+ const recipient = dpp.OrchardAddressWASM.fromSeed(seed, 1, 0);
66
+ const senderOvk = dpp.orchardOvkFromSeed(seed, 1, 0);
67
+ const privateKey = dpp.PrivateKeyWASM.fromWIF('cUy4wbim4y9NDwC24omx8oWY5WqfmjSU2gdcZtTXza2xDCAkQXRP');
68
+ const outPoint = new dpp.OutPointWASM('79af4b339ddfee8c9b6d08d74155373c6ef547cda5e65473a254b9b0f8533f0c', 0);
69
+ const assetLockProof = dpp.AssetLockProofWASM.createChainAssetLockProof(1499737, outPoint);
70
+ const memo = dpp.ShieldedMemoWASM.empty();
71
+
72
+ const builder = new ShieldedBuilderWASM();
73
+ await builder.init();
74
+
75
+ const st = await builder.shieldFromAssetLock(
76
+ recipient,
77
+ 40_000_000_000n,
78
+ assetLockProof,
79
+ privateKey,
80
+ memo,
81
+ 0,
82
+ senderOvk
83
+ );
84
+
85
+ expect(st.hex().length).toBeGreaterThan(0);
86
+ }, 120000)
87
+ })
88
+ });
@@ -0,0 +1,66 @@
1
+ import {
2
+ AuthorizedActionTakersWASM,
3
+ ChangeControlRulesWASM,
4
+ TokenConfigurationConventionWASM,
5
+ TokenConfigurationWASM,
6
+ TokenDistributionRulesWASM,
7
+ TokenKeepsHistoryRulesWASM,
8
+ TokenMarketplaceRulesWASM,
9
+ TokenTradeModeWASM
10
+ } from 'pshenmic-dpp'
11
+
12
+ export function buildChangeControlRules (): ChangeControlRulesWASM {
13
+ return new ChangeControlRulesWASM(
14
+ AuthorizedActionTakersWASM.NoOne(),
15
+ AuthorizedActionTakersWASM.NoOne(),
16
+ false,
17
+ false,
18
+ false
19
+ )
20
+ }
21
+
22
+ export function buildTokenConfiguration (
23
+ overrides: { baseSupply?: bigint, maxSupply?: bigint, description?: string } = {}
24
+ ): TokenConfigurationWASM {
25
+ const conventions = new TokenConfigurationConventionWASM({}, 8)
26
+
27
+ const keepsHistory = new TokenKeepsHistoryRulesWASM(false, false, false, false, false, false)
28
+
29
+ const distributionRules = new TokenDistributionRulesWASM(
30
+ buildChangeControlRules(),
31
+ buildChangeControlRules(),
32
+ false,
33
+ buildChangeControlRules(),
34
+ buildChangeControlRules(),
35
+ undefined,
36
+ undefined,
37
+ undefined
38
+ )
39
+
40
+ const marketplaceRules = new TokenMarketplaceRulesWASM(
41
+ TokenTradeModeWASM.NotTradeable(),
42
+ buildChangeControlRules()
43
+ )
44
+
45
+ return new TokenConfigurationWASM(
46
+ conventions,
47
+ buildChangeControlRules(),
48
+ overrides.baseSupply ?? BigInt(100000),
49
+ keepsHistory,
50
+ false,
51
+ false,
52
+ buildChangeControlRules(),
53
+ distributionRules,
54
+ marketplaceRules,
55
+ buildChangeControlRules(),
56
+ buildChangeControlRules(),
57
+ buildChangeControlRules(),
58
+ buildChangeControlRules(),
59
+ buildChangeControlRules(),
60
+ buildChangeControlRules(),
61
+ AuthorizedActionTakersWASM.NoOne(),
62
+ overrides.maxSupply,
63
+ undefined,
64
+ overrides.description
65
+ )
66
+ }
@@ -1,2 +0,0 @@
1
- declare const bytes: string;
2
- export { bytes };