pshenmic-dpp 2.0.0-dev.2 → 2.0.0-dev.21

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 (207) hide show
  1. package/dist/binaries/bindingsTypes.d.ts +507 -37
  2. package/dist/binaries/bindingsTypes.js +4 -3
  3. package/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
  4. package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
  5. package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
  6. package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
  7. package/dist/binaries/node.cjs +50 -0
  8. package/dist/binaries/node.d.cts +2 -0
  9. package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
  10. package/dist/binaries/pshenmic_dpp.apple.node/Info.plist +29 -0
  11. package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/Info.plist +24 -0
  12. package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
  13. package/dist/binaries/pshenmic_dpp.apple.node/react-native-node-api-module +0 -0
  14. package/dist/binaries/pshenmic_dpp.d.ts +42 -1
  15. package/dist/binaries/pshenmic_dpp.js +1 -1
  16. package/dist/binaries/wasm/wasmBytes.cjs +3 -0
  17. package/dist/binaries/wasm/wasmBytes.d.cts +1 -0
  18. package/dist/binaries/wasm.d.ts +42 -1
  19. package/dist/binaries/wasm.js +2 -44
  20. package/dist/binaries/wasmCreation.cjs +46 -0
  21. package/dist/binaries/wasmCreation.d.cts +2 -0
  22. package/dist/src/dpp/dpp.d.ts +28 -2
  23. package/dist/src/dpp/dpp.js +28 -2
  24. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.d.ts +1 -1
  25. package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.js +2 -2
  26. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.d.ts +1 -1
  27. package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.js +3 -3
  28. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.d.ts +1 -1
  29. package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.js +3 -3
  30. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.d.ts +1 -1
  31. package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.js +2 -2
  32. package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.js +1 -1
  33. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.d.ts +1 -1
  34. package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.js +2 -2
  35. package/dist/src/dpp/structs/AddressTransitions/entities/InputAddress.d.ts +4 -3
  36. package/dist/src/dpp/structs/AddressTransitions/entities/InputAddress.js +5 -4
  37. package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddress.d.ts +4 -3
  38. package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddress.js +5 -4
  39. package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddressNullableCredits.d.ts +4 -3
  40. package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddressNullableCredits.js +5 -4
  41. package/dist/src/dpp/structs/AssetLockProof/AssetLockProof.js +1 -1
  42. package/dist/src/dpp/structs/AssetLockProof/ChainAssetLockProof.js +2 -2
  43. package/dist/src/dpp/structs/AssetLockProof/InstantAssetLockProof.js +1 -1
  44. package/dist/src/dpp/structs/AssetLockProof/OutPoint.js +1 -1
  45. package/dist/src/dpp/structs/AssetLockProof/Transaction.js +1 -1
  46. package/dist/src/dpp/structs/AssetLockProof/TxIn.js +1 -1
  47. package/dist/src/dpp/structs/AssetLockProof/TxOut.js +1 -1
  48. package/dist/src/dpp/structs/AssetLockProof/Witness.js +1 -1
  49. package/dist/src/dpp/structs/Batch/BatchTransition.js +1 -1
  50. package/dist/src/dpp/structs/Batch/BatchedTransition.js +1 -1
  51. package/dist/src/dpp/structs/Batch/DocumentBaseTransition.js +1 -1
  52. package/dist/src/dpp/structs/Batch/DocumentTransition.d.ts +1 -0
  53. package/dist/src/dpp/structs/Batch/DocumentTransition.js +4 -1
  54. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentCreateTransition.d.ts +1 -1
  55. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentCreateTransition.js +2 -2
  56. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentDeleteTransition.js +1 -1
  57. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentPurchaseTransition.js +1 -1
  58. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentReplaceTransition.d.ts +1 -1
  59. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentReplaceTransition.js +2 -2
  60. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentTransferTransition.js +1 -1
  61. package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentUpdatePriceTransition.js +1 -1
  62. package/dist/src/dpp/structs/Batch/PrefundedVotingBalance.js +1 -1
  63. package/dist/src/dpp/structs/Batch/TokenBaseTransition.js +1 -1
  64. package/dist/src/dpp/structs/Batch/TokenPaymentInfo.js +1 -1
  65. package/dist/src/dpp/structs/Batch/TokenPricingSchedule.js +1 -1
  66. package/dist/src/dpp/structs/Batch/TokenTransition.d.ts +1 -0
  67. package/dist/src/dpp/structs/Batch/TokenTransition.js +4 -1
  68. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenBurnTransition.js +1 -1
  69. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenClaimTransition.js +1 -1
  70. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenConfigUpdateTransition.js +1 -1
  71. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenDestroyFrozenFundsTransition.js +1 -1
  72. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenDirectPurchaseTransition.js +1 -1
  73. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenEmergencyActionTransition.js +1 -1
  74. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenFreezeTransition.js +1 -1
  75. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenMintTransition.js +1 -1
  76. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenSetPriceForDirectPurchaseTransition.js +1 -1
  77. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenTransferTransition.d.ts +3 -0
  78. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenTransferTransition.js +8 -1
  79. package/dist/src/dpp/structs/Batch/TokenTransitions/TokenUnFreezeTransition.js +1 -1
  80. package/dist/src/dpp/structs/ContractBounds.js +1 -1
  81. package/dist/src/dpp/structs/CoreScript.js +1 -1
  82. package/dist/src/dpp/structs/DataContract.d.ts +6 -4
  83. package/dist/src/dpp/structs/DataContract.js +8 -2
  84. package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.js +1 -1
  85. package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.js +1 -1
  86. package/dist/src/dpp/structs/Document.d.ts +1 -1
  87. package/dist/src/dpp/structs/Document.js +1 -1
  88. package/dist/src/dpp/structs/EncryptedNote/PrivateEncryptedNote.js +1 -1
  89. package/dist/src/dpp/structs/EncryptedNote/SharedEncryptedNote.js +1 -1
  90. package/dist/src/dpp/structs/GroupStateTransitionInfo.js +1 -1
  91. package/dist/src/dpp/structs/Identifier.js +1 -1
  92. package/dist/src/dpp/structs/Identity.js +1 -1
  93. package/dist/src/dpp/structs/IdentityPublicKey.d.ts +1 -0
  94. package/dist/src/dpp/structs/IdentityPublicKey.js +6 -1
  95. package/dist/src/dpp/structs/IdentityPublicKeyInCreation.d.ts +1 -0
  96. package/dist/src/dpp/structs/IdentityPublicKeyInCreation.js +6 -1
  97. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.js +1 -1
  98. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.js +1 -1
  99. package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.js +1 -1
  100. package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.js +1 -1
  101. package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.js +1 -1
  102. package/dist/src/dpp/structs/InstantLock.js +1 -1
  103. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.d.ts +0 -2
  104. package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +1 -7
  105. package/dist/src/dpp/structs/MasternodeVote/Vote.js +1 -1
  106. package/dist/src/dpp/structs/MasternodeVote/VotePoll.d.ts +1 -1
  107. package/dist/src/dpp/structs/MasternodeVote/VotePoll.js +3 -3
  108. package/dist/src/dpp/structs/Orchard/CommitmentTree.d.ts +14 -0
  109. package/dist/src/dpp/structs/Orchard/CommitmentTree.js +31 -0
  110. package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.d.ts +21 -0
  111. package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.js +38 -0
  112. package/dist/src/dpp/structs/Orchard/MerklePath.d.ts +11 -0
  113. package/dist/src/dpp/structs/Orchard/MerklePath.js +25 -0
  114. package/dist/src/dpp/structs/Orchard/Note.d.ts +18 -0
  115. package/dist/src/dpp/structs/Orchard/Note.js +42 -0
  116. package/dist/src/dpp/structs/Orchard/OrchardAddress.d.ts +15 -0
  117. package/dist/src/dpp/structs/Orchard/OrchardAddress.js +31 -0
  118. package/dist/src/dpp/structs/Orchard/OrchardProver.d.ts +12 -0
  119. package/dist/src/dpp/structs/Orchard/OrchardProver.js +18 -0
  120. package/dist/src/dpp/structs/Orchard/RecoveredNote.d.ts +18 -0
  121. package/dist/src/dpp/structs/Orchard/RecoveredNote.js +29 -0
  122. package/dist/src/dpp/structs/Orchard/ShieldedBuilder.d.ts +40 -0
  123. package/dist/src/dpp/structs/Orchard/ShieldedBuilder.js +45 -0
  124. package/dist/src/dpp/structs/Orchard/ShieldedMemo.d.ts +11 -0
  125. package/dist/src/dpp/structs/Orchard/ShieldedMemo.js +25 -0
  126. package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.d.ts +11 -0
  127. package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.js +18 -0
  128. package/dist/src/dpp/structs/Orchard/SpendableNote.d.ts +13 -0
  129. package/dist/src/dpp/structs/Orchard/SpendableNote.js +27 -0
  130. package/dist/src/dpp/structs/PartialIdentity.js +1 -1
  131. package/dist/src/dpp/structs/{Address → PlatformAddress}/AddressWitness.d.ts +2 -2
  132. package/dist/src/dpp/structs/{Address → PlatformAddress}/AddressWitness.js +2 -2
  133. package/dist/src/dpp/structs/{Address → PlatformAddress}/PlatformAddress.d.ts +4 -2
  134. package/dist/src/dpp/structs/{Address → PlatformAddress}/PlatformAddress.js +9 -3
  135. package/dist/src/dpp/structs/PrivateKey.js +1 -1
  136. package/dist/src/dpp/structs/PublicKey.js +1 -1
  137. package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.d.ts +31 -0
  138. package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.js +73 -0
  139. package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.d.ts +19 -0
  140. package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.js +49 -0
  141. package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.d.ts +30 -0
  142. package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.js +77 -0
  143. package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.d.ts +32 -0
  144. package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.js +78 -0
  145. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.d.ts +21 -0
  146. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.js +51 -0
  147. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.d.ts +29 -0
  148. package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.js +71 -0
  149. package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.d.ts +25 -0
  150. package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.js +59 -0
  151. package/dist/src/dpp/structs/StateTransition.d.ts +1 -0
  152. package/dist/src/dpp/structs/StateTransition.js +3 -0
  153. package/dist/src/dpp/structs/TokenConfiguration/ActionTaker.js +1 -1
  154. package/dist/src/dpp/structs/TokenConfiguration/ChangeControlRules.js +1 -1
  155. package/dist/src/dpp/structs/TokenConfiguration/Group.js +1 -1
  156. package/dist/src/dpp/structs/TokenConfiguration/TokenConfiguration.js +1 -1
  157. package/dist/src/dpp/structs/TokenConfiguration/TokenConfigurationConvention.js +1 -1
  158. package/dist/src/dpp/structs/TokenConfiguration/TokenConfigurationLocalization.js +1 -1
  159. package/dist/src/dpp/structs/TokenConfiguration/TokenDistributionRules.js +1 -1
  160. package/dist/src/dpp/structs/TokenConfiguration/TokenKeepsHistoryRules.js +1 -1
  161. package/dist/src/dpp/structs/TokenConfiguration/TokenMarketplaceRules.js +1 -1
  162. package/dist/src/dpp/structs/TokenConfiguration/TokenPerpetualDistribution.js +1 -1
  163. package/dist/src/dpp/structs/TokenConfiguration/TokenPreProgrammedDistribution.js +1 -1
  164. package/dist/src/dpp/types.d.ts +85 -11
  165. package/dist/src/dpp/utils.d.ts +4 -3
  166. package/dist/src/dpp/utils.js +24 -6
  167. package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.d.ts +1 -1
  168. package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.js +1 -1
  169. package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressInfo.d.ts +2 -0
  170. package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressInfo.js +12 -0
  171. package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressesInfos.d.ts +2 -0
  172. package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressesInfos.js +14 -0
  173. package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.d.ts +2 -0
  174. package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.js +9 -0
  175. package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.d.ts +2 -0
  176. package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.js +9 -0
  177. package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.d.ts +2 -0
  178. package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.js +15 -0
  179. package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.d.ts +2 -0
  180. package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.js +9 -0
  181. package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.d.ts +2 -0
  182. package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.js +12 -0
  183. package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.d.ts +2 -0
  184. package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.js +9 -0
  185. package/dist/src/dpp/verify/StateTransition/utils.js +80 -15
  186. package/dist/src/dpp/verify/System/verifyEpochsInfoProof.js +1 -1
  187. package/dist/src/dpp/verify/Tokens/verifyTokenBalancesForIdentitiesProof.js +1 -1
  188. package/dist/src/dpp/verify/Tokens/verifyTokensBalancesForIdentityProof.js +1 -1
  189. package/dist/src/native.d.ts +3 -0
  190. package/dist/src/native.js +8 -0
  191. package/dist/utils/{base122.js → base122.cjs} +3 -1
  192. package/package.json +18 -28
  193. package/tests/unit/DataContract.spec.ts +281 -0
  194. package/tests/unit/DynamicValue.spec.ts +42 -2
  195. package/tests/unit/Identifier.spec.ts +1 -1
  196. package/tests/unit/Identity.spec.ts +1 -1
  197. package/tests/unit/IdentityPublicKey.spec.ts +1 -1
  198. package/tests/unit/NodeApi.spec.ts +49 -0
  199. package/tests/unit/Shielded.spec.ts +344 -0
  200. package/tests/unit/ShieldedTransitions.spec.ts +709 -0
  201. package/tests/unit/TokenConfiguration.spec.ts +114 -0
  202. package/tests/unit/WebAssembly.spec.ts +49 -0
  203. package/tests/unit/utils/buildTokenConfiguration.ts +66 -0
  204. package/dist/binaries/pshenmic_dpp.android.node/x86_64/libpshenmic_dpp.so +0 -0
  205. package/dist/binaries/wasm/wasmBytes.d.ts +0 -2
  206. package/dist/binaries/wasm/wasmBytes.js +0 -2
  207. /package/dist/utils/{base122.d.ts → base122.d.cts} +0 -0
@@ -0,0 +1,344 @@
1
+ import {
2
+ ShieldedMemoWASM,
3
+ OrchardAddressWASM,
4
+ orchardOvkFromSeed,
5
+ NoteWASM,
6
+ MerklePathWASM,
7
+ SpendableNoteWASM,
8
+ CommitmentTreeWASM,
9
+ ShieldedBuilderWASM,
10
+ OrchardProverWASM,
11
+ InputAddressWASM,
12
+ AddressFundsFeeStrategyStepWASM,
13
+ PrivateKeyWASM,
14
+ PlatformAddressWASM,
15
+ ShieldTransitionWASM,
16
+ StateTransitionWASM
17
+ } from 'pshenmic-dpp'
18
+
19
+ // Deterministic 64-byte BIP-39-style seed. Orchard derives via ZIP-32
20
+ // (m/32'/coinType'/account'), so any 64 bytes is a valid seed for derivation.
21
+ const SEED = new Uint8Array(64)
22
+ for (let i = 0; i < 64; i++) SEED[i] = (i * 7 + 1) & 0xff
23
+
24
+ const COIN_TYPE = 1 // testnets
25
+ const ACCOUNT = 0
26
+
27
+ // A funded testnet WIF reused across the builder/deposit tests.
28
+ const WIF = 'cUy4wbim4y9NDwC24omx8oWY5WqfmjSU2gdcZtTXza2xDCAkQXRP'
29
+
30
+ // Memo payloads are a fixed 32 bytes (MEMO_PAYLOAD_SIZE).
31
+ const MEMO_PAYLOAD_SIZE = 32
32
+
33
+ const DASH = 100_000_000_000n
34
+
35
+ function hexToBytes (hex: string): Uint8Array {
36
+ return Uint8Array.from(hex.match(/../g)!.map((x) => parseInt(x, 16)))
37
+ }
38
+
39
+ // A canonical Orchard note: rho is a valid Pallas base-field element (value 1),
40
+ // rseed is non-degenerate. Produces a valid commitment (cmx) the tree accepts.
41
+ function createTestNote (value: bigint = 1000n): NoteWASM {
42
+ const address = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
43
+ const rho = new Uint8Array(32)
44
+ rho[0] = 1
45
+ const rseed = new Uint8Array(32).fill(0x42)
46
+ return new NoteWASM(address, value, rho, rseed)
47
+ }
48
+
49
+ // Platform P2PKH address (21 bytes: 0x00 type + 20-byte pubkey hash) for a key.
50
+ function platformAddressFromPrivateKey (pk: PrivateKeyWASM): PlatformAddressWASM {
51
+ const hash = hexToBytes(pk.getPublicKeyHash())
52
+ const bytes = new Uint8Array(21)
53
+ bytes[0] = 0x00
54
+ bytes.set(hash, 1)
55
+ return PlatformAddressWASM.fromBytes(bytes)
56
+ }
57
+
58
+ describe('ShieldedMemo', function () {
59
+ describe('empty', function () {
60
+ test('should create an empty memo', function () {
61
+ const memo = ShieldedMemoWASM.empty()
62
+
63
+ expect(memo).toBeInstanceOf(ShieldedMemoWASM)
64
+ expect(memo.toBytes().length).toEqual(36) // on-wire memo size
65
+ })
66
+ })
67
+
68
+ describe('fromString', function () {
69
+ test('should create a text memo from a 32-char string', function () {
70
+ const text = 'A'.repeat(MEMO_PAYLOAD_SIZE)
71
+ const memo = ShieldedMemoWASM.fromString(text)
72
+
73
+ expect(memo).toBeInstanceOf(ShieldedMemoWASM)
74
+ expect(memo.toBytes().length).toEqual(36)
75
+ expect(memo.toString().endsWith(text)).toBe(true)
76
+ })
77
+
78
+ test('should reject a payload that is not 32 bytes', function () {
79
+ expect(() => ShieldedMemoWASM.fromString('too short')).toThrow()
80
+ })
81
+ })
82
+
83
+ describe('other', function () {
84
+ test('should create a typed memo from a 32-byte payload', function () {
85
+ const payload = new Uint8Array(MEMO_PAYLOAD_SIZE).fill(9)
86
+ const memo = ShieldedMemoWASM.other(7, payload)
87
+
88
+ expect(memo).toBeInstanceOf(ShieldedMemoWASM)
89
+ expect(memo.toBytes().length).toEqual(36)
90
+ })
91
+
92
+ test('should reject a payload that is not 32 bytes', function () {
93
+ expect(() => ShieldedMemoWASM.other(7, new Uint8Array([1, 2, 3]))).toThrow()
94
+ })
95
+ })
96
+ })
97
+
98
+ describe('OrchardAddress', function () {
99
+ describe('fromSeed', function () {
100
+ test('should derive an address from a seed', function () {
101
+ const address = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
102
+
103
+ expect(address).toBeInstanceOf(OrchardAddressWASM)
104
+ expect(address.bytes().length).toEqual(43)
105
+ })
106
+
107
+ test('should be deterministic for the same seed', function () {
108
+ const a = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
109
+ const b = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
110
+
111
+ expect(a.bytes()).toEqual(b.bytes())
112
+ })
113
+ })
114
+
115
+ describe('serialization', function () {
116
+ test('should roundtrip through bytes', function () {
117
+ const address = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
118
+ const restored = OrchardAddressWASM.fromBytes(address.bytes())
119
+
120
+ expect(restored.bytes()).toEqual(address.bytes())
121
+ })
122
+
123
+ test('should roundtrip through bech32m', function () {
124
+ const address = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
125
+ const bech32m = address.toBech32m('testnet')
126
+ const restored = OrchardAddressWASM.fromBech32m(bech32m)
127
+
128
+ expect(restored.bytes()).toEqual(address.bytes())
129
+ })
130
+ })
131
+
132
+ describe('orchardOvkFromSeed', function () {
133
+ test('should derive a 32-byte outgoing viewing key', function () {
134
+ const ovk = orchardOvkFromSeed(SEED, COIN_TYPE, ACCOUNT)
135
+
136
+ expect(ovk.length).toEqual(32)
137
+ })
138
+ })
139
+ })
140
+
141
+ describe('Note', function () {
142
+ describe('constructor', function () {
143
+ test('should create a note from valid parts', function () {
144
+ const note = createTestNote()
145
+
146
+ expect(note).toBeInstanceOf(NoteWASM)
147
+ })
148
+
149
+ test('should reject an invalid rho', function () {
150
+ const address = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
151
+ const invalidRho = new Uint8Array(32).fill(0xff) // not a canonical field element
152
+ const rseed = new Uint8Array(32).fill(0x42)
153
+
154
+ expect(() => new NoteWASM(address, 1000n, invalidRho, rseed)).toThrow()
155
+ })
156
+ })
157
+
158
+ describe('getters', function () {
159
+ test('should return all fields', function () {
160
+ const note = createTestNote(1234n)
161
+
162
+ expect(note.address).toBeInstanceOf(OrchardAddressWASM)
163
+ expect(note.value).toEqual(1234n)
164
+ expect(note.rho.length).toEqual(32)
165
+ expect(note.rseed.length).toEqual(32)
166
+ expect(note.cmx.length).toEqual(32)
167
+ })
168
+ })
169
+
170
+ describe('setters', function () {
171
+ test('should set the value', function () {
172
+ const note = createTestNote()
173
+
174
+ note.value = 5000n
175
+ expect(note.value).toEqual(5000n)
176
+ })
177
+ })
178
+ })
179
+
180
+ describe('CommitmentTree', function () {
181
+ describe('append / witness / anchor', function () {
182
+ test('should append a commitment and produce a witness and anchor', function () {
183
+ const note = createTestNote()
184
+ const tree = new CommitmentTreeWASM()
185
+
186
+ tree.append(note.cmx, true)
187
+ tree.checkpoint(1)
188
+
189
+ expect(tree.maxLeafPosition()).toEqual(0)
190
+
191
+ const path = tree.witness(0)
192
+ expect(path).toBeInstanceOf(MerklePathWASM)
193
+ expect(path!.authPath.length).toEqual(32)
194
+
195
+ expect(tree.anchor().length).toEqual(32)
196
+ })
197
+
198
+ test('should reject a cmx that is not 32 bytes', function () {
199
+ const tree = new CommitmentTreeWASM()
200
+
201
+ expect(() => tree.append(new Uint8Array(16), true)).toThrow()
202
+ })
203
+ })
204
+ })
205
+
206
+ describe('MerklePath', function () {
207
+ let position: number
208
+ let authPath: Uint8Array[]
209
+
210
+ beforeAll(function () {
211
+ const note = createTestNote()
212
+ const tree = new CommitmentTreeWASM()
213
+ tree.append(note.cmx, true)
214
+ tree.checkpoint(1)
215
+ const path = tree.witness(0)!
216
+ position = path.position
217
+ authPath = path.authPath
218
+ })
219
+
220
+ describe('constructor', function () {
221
+ test('should create a MerklePath from parts', function () {
222
+ const path = new MerklePathWASM(position, authPath)
223
+
224
+ expect(path).toBeInstanceOf(MerklePathWASM)
225
+ })
226
+ })
227
+
228
+ describe('getters', function () {
229
+ test('should return all fields', function () {
230
+ const path = new MerklePathWASM(position, authPath)
231
+
232
+ expect(path.position).toEqual(position)
233
+ expect(path.authPath.length).toEqual(32)
234
+ expect(path.authPath[0].length).toEqual(32)
235
+ })
236
+ })
237
+
238
+ describe('setters', function () {
239
+ test('should set the position', function () {
240
+ const path = new MerklePathWASM(position, authPath)
241
+
242
+ path.position = 0
243
+ expect(path.position).toEqual(0)
244
+ })
245
+ })
246
+ })
247
+
248
+ describe('SpendableNote', function () {
249
+ let note: NoteWASM
250
+ let merklePath: MerklePathWASM
251
+
252
+ beforeAll(function () {
253
+ note = createTestNote()
254
+ const tree = new CommitmentTreeWASM()
255
+ tree.append(note.cmx, true)
256
+ tree.checkpoint(1)
257
+ merklePath = tree.witness(0)!
258
+ })
259
+
260
+ describe('constructor', function () {
261
+ test('should create a SpendableNote from a note and witness', function () {
262
+ const spendable = new SpendableNoteWASM(note, merklePath)
263
+
264
+ expect(spendable).toBeInstanceOf(SpendableNoteWASM)
265
+ })
266
+ })
267
+
268
+ describe('getters', function () {
269
+ test('should return the note and merkle path', function () {
270
+ const spendable = new SpendableNoteWASM(note, merklePath)
271
+
272
+ expect(spendable.note).toBeInstanceOf(NoteWASM)
273
+ expect(spendable.note.value).toEqual(note.value)
274
+ expect(spendable.merklePath).toBeInstanceOf(MerklePathWASM)
275
+ expect(spendable.merklePath.position).toEqual(merklePath.position)
276
+ })
277
+ })
278
+
279
+ describe('setters', function () {
280
+ test('should set the note', function () {
281
+ const spendable = new SpendableNoteWASM(note, merklePath)
282
+ const newNote = createTestNote(2000n)
283
+
284
+ spendable.note = newNote
285
+ expect(spendable.note.value).toEqual(2000n)
286
+ })
287
+ })
288
+ })
289
+
290
+ describe('OrchardProver', function () {
291
+ // Constructing the prover builds the Halo 2 proving key (~seconds).
292
+ test('should construct a prover', function () {
293
+ const prover = new OrchardProverWASM()
294
+
295
+ expect(prover).toBeInstanceOf(OrchardProverWASM)
296
+ }, 30000)
297
+ })
298
+
299
+ describe('ShieldedBuilder', function () {
300
+ // The builder builds its own Halo 2 proving key on construction (~seconds),
301
+ // so build it once and reuse it across the deposit test.
302
+ let builder: ShieldedBuilderWASM
303
+
304
+ beforeAll(function () {
305
+ builder = new ShieldedBuilderWASM()
306
+ }, 30000)
307
+
308
+ describe('constructor', function () {
309
+ test('should construct a builder', function () {
310
+ expect(builder).toBeInstanceOf(ShieldedBuilderWASM)
311
+ })
312
+ })
313
+
314
+ describe('shield (transparent -> pool deposit)', function () {
315
+ test('should build and prove a shield transition', function () {
316
+ const recipient = OrchardAddressWASM.fromSeed(SEED, COIN_TYPE, ACCOUNT)
317
+ const senderOvk = orchardOvkFromSeed(SEED, COIN_TYPE, ACCOUNT)
318
+
319
+ const privateKey = PrivateKeyWASM.fromWIF(WIF)
320
+ const inputAddress = platformAddressFromPrivateKey(privateKey)
321
+ // address, nonce, balance — balance must cover amount + fee.
322
+ const input = new InputAddressWASM(inputAddress, 0, DASH / 2n)
323
+
324
+ const st = builder.shield(
325
+ recipient,
326
+ (DASH * 4n) / 10n, // 0.4 DASH into the pool
327
+ [input],
328
+ [privateKey],
329
+ [AddressFundsFeeStrategyStepWASM.DeductFromInput(0)],
330
+ 0, // user fee increase
331
+ ShieldedMemoWASM.empty(),
332
+ senderOvk
333
+ )
334
+
335
+ expect(st).toBeInstanceOf(StateTransitionWASM)
336
+
337
+ const transition = ShieldTransitionWASM.fromStateTransition(st)
338
+ expect(transition).toBeInstanceOf(ShieldTransitionWASM)
339
+ expect(transition.amount).toEqual((DASH * 4n) / 10n)
340
+ expect(transition.actions.length).toBeGreaterThanOrEqual(1)
341
+ expect(transition.proof.length).toBeGreaterThan(0)
342
+ }, 30000)
343
+ })
344
+ })