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.
- package/README.md +164 -77
- package/dist/binaries/bindingsTypes.d.ts +903 -18
- package/dist/binaries/bindingsTypes.js +13 -0
- package/dist/binaries/memory.cjs +7 -0
- package/dist/binaries/memory.d.cts +2 -0
- package/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/aarch64-pc-windows-msvc/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/aarch64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/aarch64-unknown-linux-musl/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-pc-windows-msvc/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
- package/dist/binaries/node.cjs +71 -0
- package/dist/binaries/node.d.cts +2 -0
- package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/Info.plist +29 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/Info.plist +24 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/react-native-node-api-module +0 -0
- package/dist/binaries/pshenmic_dpp.d.ts +60 -0
- package/dist/binaries/pshenmic_dpp.js +1 -1
- package/dist/binaries/wasm/wasmBytes.cjs +4 -0
- package/dist/binaries/wasm/wasmBytes.d.cts +2 -0
- package/dist/binaries/wasm/workerBundle.cjs +6 -0
- package/dist/binaries/wasm/workerBundle.d.cts +2 -0
- package/dist/binaries/wasm.d.ts +60 -0
- package/dist/binaries/wasm.js +2 -44
- package/dist/binaries/wasmCreation.cjs +127 -0
- package/dist/binaries/wasmCreation.d.cts +4 -0
- package/dist/src/dpp/dpp.d.ts +32 -0
- package/dist/src/dpp/dpp.js +32 -0
- package/dist/src/dpp/enums.d.ts +1 -1
- package/dist/src/dpp/enums.js +1 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.d.ts +3 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.js +6 -0
- package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.d.ts +2 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.js +3 -0
- package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.d.ts +3 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.js +6 -0
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.d.ts +2 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.js +3 -0
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.d.ts +2 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.js +3 -0
- package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.d.ts +2 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.js +3 -0
- package/dist/src/dpp/structs/Batch/BatchTransition.d.ts +2 -1
- package/dist/src/dpp/structs/Batch/BatchTransition.js +3 -0
- package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.d.ts +2 -1
- package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.js +3 -0
- package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.d.ts +2 -1
- package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.js +3 -0
- package/dist/src/dpp/structs/Identifier.js +3 -0
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.d.ts +2 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.js +3 -0
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.d.ts +2 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.js +3 -0
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.d.ts +2 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.js +3 -0
- package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.d.ts +2 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.js +3 -0
- package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.d.ts +2 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.js +3 -0
- package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.d.ts +2 -3
- package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +3 -6
- package/dist/src/dpp/structs/Orchard/CommitmentTree.d.ts +14 -0
- package/dist/src/dpp/structs/Orchard/CommitmentTree.js +31 -0
- package/dist/src/dpp/structs/Orchard/FullViewingKey.d.ts +27 -0
- package/dist/src/dpp/structs/Orchard/FullViewingKey.js +45 -0
- package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.d.ts +21 -0
- package/dist/src/dpp/structs/Orchard/IdentityCreateFromShieldedPoolResult.js +38 -0
- package/dist/src/dpp/structs/Orchard/IncomingViewingKey.d.ts +29 -0
- package/dist/src/dpp/structs/Orchard/IncomingViewingKey.js +44 -0
- package/dist/src/dpp/structs/Orchard/MerklePath.d.ts +11 -0
- package/dist/src/dpp/structs/Orchard/MerklePath.js +25 -0
- package/dist/src/dpp/structs/Orchard/Note.d.ts +18 -0
- package/dist/src/dpp/structs/Orchard/Note.js +42 -0
- package/dist/src/dpp/structs/Orchard/OrchardAddress.d.ts +27 -0
- package/dist/src/dpp/structs/Orchard/OrchardAddress.js +45 -0
- package/dist/src/dpp/structs/Orchard/OrchardProver.d.ts +19 -0
- package/dist/src/dpp/structs/Orchard/OrchardProver.js +34 -0
- package/dist/src/dpp/structs/Orchard/RecoveredNote.d.ts +19 -0
- package/dist/src/dpp/structs/Orchard/RecoveredNote.js +32 -0
- package/dist/src/dpp/structs/Orchard/ShieldedBuilder.d.ts +64 -0
- package/dist/src/dpp/structs/Orchard/ShieldedBuilder.js +79 -0
- package/dist/src/dpp/structs/Orchard/ShieldedMemo.d.ts +11 -0
- package/dist/src/dpp/structs/Orchard/ShieldedMemo.js +25 -0
- package/dist/src/dpp/structs/Orchard/ShieldedOutput.d.ts +23 -0
- package/dist/src/dpp/structs/Orchard/ShieldedOutput.js +41 -0
- package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.d.ts +11 -0
- package/dist/src/dpp/structs/Orchard/ShieldedWithdrawalResult.js +18 -0
- package/dist/src/dpp/structs/Orchard/SpendableNote.d.ts +13 -0
- package/dist/src/dpp/structs/Orchard/SpendableNote.js +27 -0
- package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.d.ts +9 -1
- package/dist/src/dpp/structs/PlatformAddress/PlatformAddress.js +10 -0
- package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.d.ts +32 -0
- package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.js +76 -0
- package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.d.ts +19 -0
- package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.js +49 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.d.ts +31 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.js +80 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.d.ts +33 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.js +81 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.d.ts +22 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.js +54 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.d.ts +30 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.js +74 -0
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.d.ts +26 -0
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.js +62 -0
- package/dist/src/dpp/structs/StateTransition.d.ts +2 -1
- package/dist/src/dpp/structs/StateTransition.js +3 -0
- package/dist/src/dpp/types.d.ts +177 -3
- package/dist/src/dpp/verify/AddressFunds/utils.d.ts +5 -0
- package/dist/src/dpp/verify/AddressFunds/utils.js +28 -0
- package/dist/src/dpp/verify/AddressFunds/verifyAddressesBranchState.d.ts +12 -0
- package/dist/src/dpp/verify/AddressFunds/verifyAddressesBranchState.js +29 -0
- package/dist/src/dpp/verify/AddressFunds/verifyAddressesTrunkState.d.ts +9 -0
- package/dist/src/dpp/verify/AddressFunds/verifyAddressesTrunkState.js +30 -0
- package/dist/src/dpp/verify/AddressFunds/verifyRecentAddressBalanceChanges.d.ts +9 -0
- package/dist/src/dpp/verify/AddressFunds/verifyRecentAddressBalanceChanges.js +24 -0
- package/dist/src/dpp/verify/AddressFunds/verifyRecentCompactedAddressBalanceChanges.d.ts +10 -0
- package/dist/src/dpp/verify/AddressFunds/verifyRecentCompactedAddressBalanceChanges.js +30 -0
- package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.d.ts +1 -1
- package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.js +1 -1
- package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyMostRecentShieldedAnchorProof.js +9 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedAnchorsProof.js +9 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedEncryptedNotesProof.js +15 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedNotesCountProof.js +9 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedNullifiersProof.js +12 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.d.ts +2 -0
- package/dist/src/dpp/verify/Shielded/verifyShieldedPoolStateProof.js +9 -0
- package/dist/src/dpp/verify/StateTransition/utils.js +76 -11
- package/dist/src/dpp/verify/StateTransition/verifyStateTransitionResult.js +2 -1
- package/dist/src/dpp/verify/System/verifyFinalizedEpochInfosProof.d.ts +2 -0
- package/dist/src/dpp/verify/System/verifyFinalizedEpochInfosProof.js +27 -0
- package/dist/src/native.d.ts +3 -0
- package/dist/src/native.js +8 -0
- package/dist/utils/{base122.js → base122.cjs} +3 -1
- package/package.json +17 -27
- package/tests/unit/AddressTransitionsFees.spec.ts +274 -0
- package/tests/unit/DataContract.spec.ts +281 -0
- package/tests/unit/DynamicValue.spec.ts +2 -2
- package/tests/unit/Identifier.spec.ts +1 -1
- package/tests/unit/Identity.spec.ts +1 -1
- package/tests/unit/IdentityPublicKey.spec.ts +1 -1
- package/tests/unit/NodeApi.spec.ts +49 -0
- package/tests/unit/Shielded.spec.ts +555 -0
- package/tests/unit/ShieldedTransitions.spec.ts +877 -0
- package/tests/unit/StateTransitionFees.spec.ts +177 -0
- package/tests/unit/TokenConfiguration.spec.ts +114 -0
- package/tests/unit/WebAssembly.spec.ts +88 -0
- package/tests/unit/utils/buildTokenConfiguration.ts +66 -0
- package/dist/binaries/pshenmic_dpp.android.node/x86_64/libpshenmic_dpp.so +0 -0
- package/dist/binaries/wasm/wasmBytes.d.ts +0 -2
- package/dist/binaries/wasm/wasmBytes.js +0 -2
- /package/dist/utils/{base122.d.ts → base122.d.cts} +0 -0
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SerializedActionWASM,
|
|
3
|
+
ShieldedTransferTransitionWASM,
|
|
4
|
+
ShieldTransitionWASM,
|
|
5
|
+
UnshieldTransitionWASM,
|
|
6
|
+
ShieldFromAssetLockTransitionWASM,
|
|
7
|
+
ShieldedWithdrawalTransitionWASM,
|
|
8
|
+
IdentityCreateFromShieldedPoolTransitionWASM,
|
|
9
|
+
InputAddressWASM,
|
|
10
|
+
AddressFundsFeeStrategyStepWASM,
|
|
11
|
+
AddressWitnessWASM,
|
|
12
|
+
PlatformAddressWASM,
|
|
13
|
+
AssetLockProofWASM,
|
|
14
|
+
OutPointWASM,
|
|
15
|
+
CoreScriptWASM,
|
|
16
|
+
IdentityPublicKeyInCreationWASM,
|
|
17
|
+
IdentifierWASM,
|
|
18
|
+
Purpose,
|
|
19
|
+
SecurityLevel,
|
|
20
|
+
KeyType,
|
|
21
|
+
PlatformVersionWASM,
|
|
22
|
+
StateTransitionWASM
|
|
23
|
+
} from 'pshenmic-dpp'
|
|
24
|
+
|
|
25
|
+
function randomBytes (length: number): Uint8Array {
|
|
26
|
+
const bytes = new Uint8Array(length)
|
|
27
|
+
for (let i = 0; i < length; i++) {
|
|
28
|
+
bytes[i] = Math.floor(Math.random() * 256)
|
|
29
|
+
}
|
|
30
|
+
return bytes
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function createTestAction (): SerializedActionWASM {
|
|
34
|
+
return new SerializedActionWASM(
|
|
35
|
+
randomBytes(32),
|
|
36
|
+
randomBytes(32),
|
|
37
|
+
randomBytes(32),
|
|
38
|
+
randomBytes(580),
|
|
39
|
+
randomBytes(32),
|
|
40
|
+
randomBytes(64)
|
|
41
|
+
)
|
|
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
|
+
describe('SerializedAction', function () {
|
|
52
|
+
let nullifier: Uint8Array
|
|
53
|
+
let rk: Uint8Array
|
|
54
|
+
let cmx: Uint8Array
|
|
55
|
+
let encryptedNote: Uint8Array
|
|
56
|
+
let cvNet: Uint8Array
|
|
57
|
+
let spendAuthSig: Uint8Array
|
|
58
|
+
|
|
59
|
+
beforeAll(function () {
|
|
60
|
+
nullifier = randomBytes(32)
|
|
61
|
+
rk = randomBytes(32)
|
|
62
|
+
cmx = randomBytes(32)
|
|
63
|
+
encryptedNote = randomBytes(580)
|
|
64
|
+
cvNet = randomBytes(32)
|
|
65
|
+
spendAuthSig = randomBytes(64)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('constructor', function () {
|
|
69
|
+
test('should create SerializedAction from values', function () {
|
|
70
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
71
|
+
|
|
72
|
+
expect(action).toBeInstanceOf(SerializedActionWASM)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('getters', function () {
|
|
77
|
+
test('should return all fields', function () {
|
|
78
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
79
|
+
|
|
80
|
+
expect(action.nullifier).toEqual(nullifier)
|
|
81
|
+
expect(action.rk).toEqual(rk)
|
|
82
|
+
expect(action.cmx).toEqual(cmx)
|
|
83
|
+
expect(action.encryptedNote).toEqual(encryptedNote)
|
|
84
|
+
expect(action.cvNet).toEqual(cvNet)
|
|
85
|
+
expect(action.spendAuthSig).toEqual(spendAuthSig)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
describe('setters', function () {
|
|
90
|
+
test('should set all fields', function () {
|
|
91
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
92
|
+
|
|
93
|
+
const newNullifier = randomBytes(32)
|
|
94
|
+
const newRk = randomBytes(32)
|
|
95
|
+
const newCmx = randomBytes(32)
|
|
96
|
+
const newEncryptedNote = randomBytes(580)
|
|
97
|
+
const newCvNet = randomBytes(32)
|
|
98
|
+
const newSpendAuthSig = randomBytes(64)
|
|
99
|
+
|
|
100
|
+
action.nullifier = newNullifier
|
|
101
|
+
action.rk = newRk
|
|
102
|
+
action.cmx = newCmx
|
|
103
|
+
action.encryptedNote = newEncryptedNote
|
|
104
|
+
action.cvNet = newCvNet
|
|
105
|
+
action.spendAuthSig = newSpendAuthSig
|
|
106
|
+
|
|
107
|
+
expect(action.nullifier).toEqual(newNullifier)
|
|
108
|
+
expect(action.rk).toEqual(newRk)
|
|
109
|
+
expect(action.cmx).toEqual(newCmx)
|
|
110
|
+
expect(action.encryptedNote).toEqual(newEncryptedNote)
|
|
111
|
+
expect(action.cvNet).toEqual(newCvNet)
|
|
112
|
+
expect(action.spendAuthSig).toEqual(newSpendAuthSig)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('ShieldedTransferTransition', function () {
|
|
118
|
+
let actions: SerializedActionWASM[]
|
|
119
|
+
let valueBalance: bigint
|
|
120
|
+
let anchor: Uint8Array
|
|
121
|
+
let proof: Uint8Array
|
|
122
|
+
let bindingsSignature: Uint8Array
|
|
123
|
+
|
|
124
|
+
beforeAll(function () {
|
|
125
|
+
actions = [createTestAction()]
|
|
126
|
+
valueBalance = BigInt(100000)
|
|
127
|
+
anchor = randomBytes(32)
|
|
128
|
+
proof = randomBytes(192)
|
|
129
|
+
bindingsSignature = randomBytes(64)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('constructor', function () {
|
|
133
|
+
test('should create ShieldedTransferTransition from values', function () {
|
|
134
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
135
|
+
|
|
136
|
+
expect(transition).toBeInstanceOf(ShieldedTransferTransitionWASM)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe('getters', function () {
|
|
141
|
+
test('should return all fields', function () {
|
|
142
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
143
|
+
|
|
144
|
+
expect(transition.actions.length).toEqual(1)
|
|
145
|
+
expect(transition.actions[0].nullifier).toEqual(actions[0].nullifier)
|
|
146
|
+
expect(transition.valueBalance).toEqual(valueBalance)
|
|
147
|
+
expect(transition.anchor).toEqual(anchor)
|
|
148
|
+
expect(transition.proof).toEqual(proof)
|
|
149
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe('setters', function () {
|
|
154
|
+
test('should set all fields', function () {
|
|
155
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
156
|
+
|
|
157
|
+
const newActions = [createTestAction(), createTestAction()]
|
|
158
|
+
const newValueBalance = BigInt(200000)
|
|
159
|
+
const newAnchor = randomBytes(32)
|
|
160
|
+
const newProof = randomBytes(192)
|
|
161
|
+
const newBindingsSignature = randomBytes(64)
|
|
162
|
+
|
|
163
|
+
transition.actions = newActions
|
|
164
|
+
transition.valueBalance = newValueBalance
|
|
165
|
+
transition.anchor = newAnchor
|
|
166
|
+
transition.proof = newProof
|
|
167
|
+
transition.bindingsSignature = newBindingsSignature
|
|
168
|
+
|
|
169
|
+
expect(transition.actions.length).toEqual(2)
|
|
170
|
+
expect(transition.valueBalance).toEqual(newValueBalance)
|
|
171
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
172
|
+
expect(transition.proof).toEqual(newProof)
|
|
173
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
describe('serialization / deserialization', function () {
|
|
178
|
+
test('should roundtrip through StateTransition', function () {
|
|
179
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
180
|
+
|
|
181
|
+
const st = transition.toStateTransition()
|
|
182
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
183
|
+
|
|
184
|
+
const restored = ShieldedTransferTransitionWASM.fromStateTransition(st)
|
|
185
|
+
expect(restored).toBeInstanceOf(ShieldedTransferTransitionWASM)
|
|
186
|
+
|
|
187
|
+
expect(restored.valueBalance).toEqual(valueBalance)
|
|
188
|
+
expect(restored.anchor).toEqual(anchor)
|
|
189
|
+
expect(restored.proof).toEqual(proof)
|
|
190
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
191
|
+
expect(restored.actions.length).toEqual(1)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('computeMinimumFee', function () {
|
|
196
|
+
test('should return a positive fee', function () {
|
|
197
|
+
const fee = ShieldedTransferTransitionWASM.computeMinimumFee(2)
|
|
198
|
+
|
|
199
|
+
expect(typeof fee).toEqual('bigint')
|
|
200
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('should grow with the action count', function () {
|
|
204
|
+
const oneAction = ShieldedTransferTransitionWASM.computeMinimumFee(1)
|
|
205
|
+
const twoActions = ShieldedTransferTransitionWASM.computeMinimumFee(2)
|
|
206
|
+
|
|
207
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('should default to the latest platform version', function () {
|
|
211
|
+
expect(ShieldedTransferTransitionWASM.computeMinimumFee(2))
|
|
212
|
+
.toEqual(ShieldedTransferTransitionWASM.computeMinimumFee(2, PlatformVersionWASM.PLATFORM_V12))
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
describe('ShieldTransition', function () {
|
|
218
|
+
let inputs: InputAddressWASM[]
|
|
219
|
+
let actions: SerializedActionWASM[]
|
|
220
|
+
let amount: bigint
|
|
221
|
+
let anchor: Uint8Array
|
|
222
|
+
let proof: Uint8Array
|
|
223
|
+
let bindingsSignature: Uint8Array
|
|
224
|
+
let feeStrategy: AddressFundsFeeStrategyStepWASM[]
|
|
225
|
+
let userFeeIncrease: number
|
|
226
|
+
let inputWitnesses: AddressWitnessWASM[]
|
|
227
|
+
|
|
228
|
+
beforeAll(function () {
|
|
229
|
+
const address = createTestAddress()
|
|
230
|
+
inputs = [new InputAddressWASM(address, 0, BigInt(500000))]
|
|
231
|
+
actions = [createTestAction()]
|
|
232
|
+
amount = BigInt(100000)
|
|
233
|
+
anchor = randomBytes(32)
|
|
234
|
+
proof = randomBytes(192)
|
|
235
|
+
bindingsSignature = randomBytes(64)
|
|
236
|
+
feeStrategy = [AddressFundsFeeStrategyStepWASM.DeductFromInput(0)]
|
|
237
|
+
userFeeIncrease = 0
|
|
238
|
+
inputWitnesses = [AddressWitnessWASM.P2PKH(randomBytes(65))]
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
describe('constructor', function () {
|
|
242
|
+
test('should create ShieldTransition from values', function () {
|
|
243
|
+
const transition = new ShieldTransitionWASM(
|
|
244
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
expect(transition).toBeInstanceOf(ShieldTransitionWASM)
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
describe('getters', function () {
|
|
252
|
+
test('should return all fields', function () {
|
|
253
|
+
const transition = new ShieldTransitionWASM(
|
|
254
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
expect(transition.inputs.length).toEqual(1)
|
|
258
|
+
expect(transition.actions.length).toEqual(1)
|
|
259
|
+
expect(transition.amount).toEqual(amount)
|
|
260
|
+
expect(transition.anchor).toEqual(anchor)
|
|
261
|
+
expect(transition.proof).toEqual(proof)
|
|
262
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
263
|
+
expect(transition.feeStrategy.length).toEqual(1)
|
|
264
|
+
expect(transition.userFeeIncrease).toEqual(userFeeIncrease)
|
|
265
|
+
expect(transition.inputWitnesses.length).toEqual(1)
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
describe('setters', function () {
|
|
270
|
+
test('should set all fields', function () {
|
|
271
|
+
const transition = new ShieldTransitionWASM(
|
|
272
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
const newAmount = BigInt(200000)
|
|
276
|
+
const newAnchor = randomBytes(32)
|
|
277
|
+
const newProof = randomBytes(192)
|
|
278
|
+
const newBindingsSignature = randomBytes(64)
|
|
279
|
+
const newUserFeeIncrease = 5
|
|
280
|
+
|
|
281
|
+
transition.amount = newAmount
|
|
282
|
+
transition.anchor = newAnchor
|
|
283
|
+
transition.proof = newProof
|
|
284
|
+
transition.bindingsSignature = newBindingsSignature
|
|
285
|
+
transition.userFeeIncrease = newUserFeeIncrease
|
|
286
|
+
|
|
287
|
+
expect(transition.amount).toEqual(newAmount)
|
|
288
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
289
|
+
expect(transition.proof).toEqual(newProof)
|
|
290
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
291
|
+
expect(transition.userFeeIncrease).toEqual(newUserFeeIncrease)
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
describe('serialization / deserialization', function () {
|
|
296
|
+
test('should roundtrip through StateTransition', function () {
|
|
297
|
+
const transition = new ShieldTransitionWASM(
|
|
298
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
const st = transition.toStateTransition()
|
|
302
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
303
|
+
|
|
304
|
+
const restored = ShieldTransitionWASM.fromStateTransition(st)
|
|
305
|
+
expect(restored).toBeInstanceOf(ShieldTransitionWASM)
|
|
306
|
+
|
|
307
|
+
expect(restored.amount).toEqual(amount)
|
|
308
|
+
expect(restored.anchor).toEqual(anchor)
|
|
309
|
+
expect(restored.proof).toEqual(proof)
|
|
310
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
311
|
+
expect(restored.userFeeIncrease).toEqual(userFeeIncrease)
|
|
312
|
+
expect(restored.inputs.length).toEqual(1)
|
|
313
|
+
expect(restored.actions.length).toEqual(1)
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
describe('computeMinimumFee', function () {
|
|
318
|
+
test('should return a positive fee', function () {
|
|
319
|
+
const fee = ShieldTransitionWASM.computeMinimumFee(2)
|
|
320
|
+
|
|
321
|
+
expect(typeof fee).toEqual('bigint')
|
|
322
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
test('should grow with the action count', function () {
|
|
326
|
+
const oneAction = ShieldTransitionWASM.computeMinimumFee(1)
|
|
327
|
+
const twoActions = ShieldTransitionWASM.computeMinimumFee(2)
|
|
328
|
+
|
|
329
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
test('should default to the latest platform version', function () {
|
|
333
|
+
expect(ShieldTransitionWASM.computeMinimumFee(2))
|
|
334
|
+
.toEqual(ShieldTransitionWASM.computeMinimumFee(2, PlatformVersionWASM.PLATFORM_V12))
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
describe('UnshieldTransition', function () {
|
|
340
|
+
let outputAddress: PlatformAddressWASM
|
|
341
|
+
let actions: SerializedActionWASM[]
|
|
342
|
+
let unshieldingAmount: bigint
|
|
343
|
+
let anchor: Uint8Array
|
|
344
|
+
let proof: Uint8Array
|
|
345
|
+
let bindingsSignature: Uint8Array
|
|
346
|
+
|
|
347
|
+
beforeAll(function () {
|
|
348
|
+
outputAddress = createTestAddress()
|
|
349
|
+
actions = [createTestAction()]
|
|
350
|
+
unshieldingAmount = BigInt(100000)
|
|
351
|
+
anchor = randomBytes(32)
|
|
352
|
+
proof = randomBytes(192)
|
|
353
|
+
bindingsSignature = randomBytes(64)
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
describe('constructor', function () {
|
|
357
|
+
test('should create UnshieldTransition from values', function () {
|
|
358
|
+
const transition = new UnshieldTransitionWASM(
|
|
359
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
expect(transition).toBeInstanceOf(UnshieldTransitionWASM)
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
describe('getters', function () {
|
|
367
|
+
test('should return all fields', function () {
|
|
368
|
+
const transition = new UnshieldTransitionWASM(
|
|
369
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
expect(transition.outputAddress).toBeInstanceOf(PlatformAddressWASM)
|
|
373
|
+
expect(transition.outputAddress.bytes()).toEqual(outputAddress.bytes())
|
|
374
|
+
expect(transition.actions.length).toEqual(1)
|
|
375
|
+
expect(transition.unshieldingAmount).toEqual(unshieldingAmount)
|
|
376
|
+
expect(transition.anchor).toEqual(anchor)
|
|
377
|
+
expect(transition.proof).toEqual(proof)
|
|
378
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
379
|
+
})
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
describe('setters', function () {
|
|
383
|
+
test('should set all fields', function () {
|
|
384
|
+
const transition = new UnshieldTransitionWASM(
|
|
385
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
const newAddress = createTestAddress()
|
|
389
|
+
const newAmount = BigInt(200000)
|
|
390
|
+
const newAnchor = randomBytes(32)
|
|
391
|
+
const newProof = randomBytes(192)
|
|
392
|
+
const newBindingsSignature = randomBytes(64)
|
|
393
|
+
|
|
394
|
+
transition.outputAddress = newAddress
|
|
395
|
+
transition.unshieldingAmount = newAmount
|
|
396
|
+
transition.anchor = newAnchor
|
|
397
|
+
transition.proof = newProof
|
|
398
|
+
transition.bindingsSignature = newBindingsSignature
|
|
399
|
+
|
|
400
|
+
expect(transition.outputAddress.bytes()).toEqual(newAddress.bytes())
|
|
401
|
+
expect(transition.unshieldingAmount).toEqual(newAmount)
|
|
402
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
403
|
+
expect(transition.proof).toEqual(newProof)
|
|
404
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
describe('serialization / deserialization', function () {
|
|
409
|
+
test('should roundtrip through StateTransition', function () {
|
|
410
|
+
const transition = new UnshieldTransitionWASM(
|
|
411
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
const st = transition.toStateTransition()
|
|
415
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
416
|
+
|
|
417
|
+
const restored = UnshieldTransitionWASM.fromStateTransition(st)
|
|
418
|
+
expect(restored).toBeInstanceOf(UnshieldTransitionWASM)
|
|
419
|
+
|
|
420
|
+
expect(restored.outputAddress.bytes()).toEqual(outputAddress.bytes())
|
|
421
|
+
expect(restored.unshieldingAmount).toEqual(unshieldingAmount)
|
|
422
|
+
expect(restored.anchor).toEqual(anchor)
|
|
423
|
+
expect(restored.proof).toEqual(proof)
|
|
424
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
425
|
+
})
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
describe('computeMinimumFee', function () {
|
|
429
|
+
test('should return a positive fee', function () {
|
|
430
|
+
const fee = UnshieldTransitionWASM.computeMinimumFee(2)
|
|
431
|
+
|
|
432
|
+
expect(typeof fee).toEqual('bigint')
|
|
433
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
test('should grow with the action count', function () {
|
|
437
|
+
const oneAction = UnshieldTransitionWASM.computeMinimumFee(1)
|
|
438
|
+
const twoActions = UnshieldTransitionWASM.computeMinimumFee(2)
|
|
439
|
+
|
|
440
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
test('should default to the latest platform version', function () {
|
|
444
|
+
expect(UnshieldTransitionWASM.computeMinimumFee(2))
|
|
445
|
+
.toEqual(UnshieldTransitionWASM.computeMinimumFee(2, PlatformVersionWASM.PLATFORM_V12))
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
describe('ShieldFromAssetLockTransition', function () {
|
|
451
|
+
let assetLockProof: AssetLockProofWASM
|
|
452
|
+
let actions: SerializedActionWASM[]
|
|
453
|
+
let valueBalance: bigint
|
|
454
|
+
let anchor: Uint8Array
|
|
455
|
+
let proof: Uint8Array
|
|
456
|
+
let bindingsSignature: Uint8Array
|
|
457
|
+
|
|
458
|
+
beforeAll(function () {
|
|
459
|
+
const txid = 'a'.repeat(64)
|
|
460
|
+
const outPoint = new OutPointWASM(txid, 0)
|
|
461
|
+
assetLockProof = AssetLockProofWASM.createChainAssetLockProof(100, outPoint)
|
|
462
|
+
actions = [createTestAction()]
|
|
463
|
+
valueBalance = BigInt(100000)
|
|
464
|
+
anchor = randomBytes(32)
|
|
465
|
+
proof = randomBytes(192)
|
|
466
|
+
bindingsSignature = randomBytes(64)
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
describe('constructor', function () {
|
|
470
|
+
test('should create ShieldFromAssetLockTransition from values', function () {
|
|
471
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
472
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
expect(transition).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
test('should create ShieldFromAssetLockTransition with surplusOutput', function () {
|
|
479
|
+
const surplusOutput = createTestAddress()
|
|
480
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
481
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature, surplusOutput
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
expect(transition).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
485
|
+
expect(transition.surplusOutput).toBeInstanceOf(PlatformAddressWASM)
|
|
486
|
+
})
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
describe('getters', function () {
|
|
490
|
+
test('should return all fields', function () {
|
|
491
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
492
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
expect(transition.assetLockProof).toBeInstanceOf(AssetLockProofWASM)
|
|
496
|
+
expect(transition.actions.length).toEqual(1)
|
|
497
|
+
expect(transition.valueBalance).toEqual(valueBalance)
|
|
498
|
+
expect(transition.anchor).toEqual(anchor)
|
|
499
|
+
expect(transition.proof).toEqual(proof)
|
|
500
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
501
|
+
})
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
describe('setters', function () {
|
|
505
|
+
test('should set all fields', function () {
|
|
506
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
507
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
const newValueBalance = BigInt(200000)
|
|
511
|
+
const newAnchor = randomBytes(32)
|
|
512
|
+
const newProof = randomBytes(192)
|
|
513
|
+
const newBindingsSignature = randomBytes(64)
|
|
514
|
+
|
|
515
|
+
transition.valueBalance = newValueBalance
|
|
516
|
+
transition.anchor = newAnchor
|
|
517
|
+
transition.proof = newProof
|
|
518
|
+
transition.bindingsSignature = newBindingsSignature
|
|
519
|
+
|
|
520
|
+
expect(transition.valueBalance).toEqual(newValueBalance)
|
|
521
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
522
|
+
expect(transition.proof).toEqual(newProof)
|
|
523
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
test('should set surplusOutput', function () {
|
|
527
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
528
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
const surplusAddress = createTestAddress()
|
|
532
|
+
transition.surplusOutput = surplusAddress
|
|
533
|
+
|
|
534
|
+
expect(transition.surplusOutput).toBeInstanceOf(PlatformAddressWASM)
|
|
535
|
+
expect(transition.surplusOutput!.bytes()).toEqual(surplusAddress.bytes())
|
|
536
|
+
})
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
describe('serialization / deserialization', function () {
|
|
540
|
+
test('should roundtrip through StateTransition', function () {
|
|
541
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
542
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
const st = transition.toStateTransition()
|
|
546
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
547
|
+
|
|
548
|
+
const restored = ShieldFromAssetLockTransitionWASM.fromStateTransition(st)
|
|
549
|
+
expect(restored).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
550
|
+
|
|
551
|
+
expect(restored.valueBalance).toEqual(valueBalance)
|
|
552
|
+
expect(restored.anchor).toEqual(anchor)
|
|
553
|
+
expect(restored.proof).toEqual(proof)
|
|
554
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
555
|
+
expect(restored.actions.length).toEqual(1)
|
|
556
|
+
})
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
describe('computeMinimumFee', function () {
|
|
560
|
+
test('should return a positive fee', function () {
|
|
561
|
+
const fee = ShieldFromAssetLockTransitionWASM.computeMinimumFee(2)
|
|
562
|
+
|
|
563
|
+
expect(typeof fee).toEqual('bigint')
|
|
564
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
test('should grow with the action count', function () {
|
|
568
|
+
const oneAction = ShieldFromAssetLockTransitionWASM.computeMinimumFee(1)
|
|
569
|
+
const twoActions = ShieldFromAssetLockTransitionWASM.computeMinimumFee(2)
|
|
570
|
+
|
|
571
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
test('should default to the latest platform version', function () {
|
|
575
|
+
expect(ShieldFromAssetLockTransitionWASM.computeMinimumFee(2))
|
|
576
|
+
.toEqual(ShieldFromAssetLockTransitionWASM.computeMinimumFee(2, PlatformVersionWASM.PLATFORM_V12))
|
|
577
|
+
})
|
|
578
|
+
})
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
describe('ShieldedWithdrawalTransition', function () {
|
|
582
|
+
let actions: SerializedActionWASM[]
|
|
583
|
+
let unshieldingAmount: bigint
|
|
584
|
+
let anchor: Uint8Array
|
|
585
|
+
let proof: Uint8Array
|
|
586
|
+
let bindingsSignature: Uint8Array
|
|
587
|
+
let coreFeePerByte: number
|
|
588
|
+
let outputScript: CoreScriptWASM
|
|
589
|
+
|
|
590
|
+
beforeAll(function () {
|
|
591
|
+
actions = [createTestAction()]
|
|
592
|
+
unshieldingAmount = BigInt(100000)
|
|
593
|
+
anchor = randomBytes(32)
|
|
594
|
+
proof = randomBytes(192)
|
|
595
|
+
bindingsSignature = randomBytes(64)
|
|
596
|
+
coreFeePerByte = 1
|
|
597
|
+
outputScript = CoreScriptWASM.newP2PKH(randomBytes(20))
|
|
598
|
+
})
|
|
599
|
+
|
|
600
|
+
describe('constructor', function () {
|
|
601
|
+
test('should create ShieldedWithdrawalTransition from values', function () {
|
|
602
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
603
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
expect(transition).toBeInstanceOf(ShieldedWithdrawalTransitionWASM)
|
|
607
|
+
})
|
|
608
|
+
})
|
|
609
|
+
|
|
610
|
+
describe('getters', function () {
|
|
611
|
+
test('should return all fields', function () {
|
|
612
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
613
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
expect(transition.actions.length).toEqual(1)
|
|
617
|
+
expect(transition.unshieldingAmount).toEqual(unshieldingAmount)
|
|
618
|
+
expect(transition.anchor).toEqual(anchor)
|
|
619
|
+
expect(transition.proof).toEqual(proof)
|
|
620
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
621
|
+
expect(transition.coreFeePerByte).toEqual(coreFeePerByte)
|
|
622
|
+
expect(transition.pooling).toEqual('Never')
|
|
623
|
+
expect(transition.outputScript).toBeInstanceOf(CoreScriptWASM)
|
|
624
|
+
})
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
describe('setters', function () {
|
|
628
|
+
test('should set all fields', function () {
|
|
629
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
630
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
const newAmount = BigInt(200000)
|
|
634
|
+
const newAnchor = randomBytes(32)
|
|
635
|
+
const newProof = randomBytes(192)
|
|
636
|
+
const newBindingsSignature = randomBytes(64)
|
|
637
|
+
const newCoreFeePerByte = 2
|
|
638
|
+
const newOutputScript = CoreScriptWASM.newP2PKH(randomBytes(20))
|
|
639
|
+
|
|
640
|
+
transition.unshieldingAmount = newAmount
|
|
641
|
+
transition.anchor = newAnchor
|
|
642
|
+
transition.proof = newProof
|
|
643
|
+
transition.bindingsSignature = newBindingsSignature
|
|
644
|
+
transition.coreFeePerByte = newCoreFeePerByte
|
|
645
|
+
transition.pooling = 'Standard'
|
|
646
|
+
transition.outputScript = newOutputScript
|
|
647
|
+
|
|
648
|
+
expect(transition.unshieldingAmount).toEqual(newAmount)
|
|
649
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
650
|
+
expect(transition.proof).toEqual(newProof)
|
|
651
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
652
|
+
expect(transition.coreFeePerByte).toEqual(newCoreFeePerByte)
|
|
653
|
+
expect(transition.pooling).toEqual('Standard')
|
|
654
|
+
expect(transition.outputScript.bytes()).toEqual(newOutputScript.bytes())
|
|
655
|
+
})
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
describe('serialization / deserialization', function () {
|
|
659
|
+
test('should roundtrip through StateTransition', function () {
|
|
660
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
661
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
const st = transition.toStateTransition()
|
|
665
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
666
|
+
|
|
667
|
+
const restored = ShieldedWithdrawalTransitionWASM.fromStateTransition(st)
|
|
668
|
+
expect(restored).toBeInstanceOf(ShieldedWithdrawalTransitionWASM)
|
|
669
|
+
|
|
670
|
+
expect(restored.unshieldingAmount).toEqual(unshieldingAmount)
|
|
671
|
+
expect(restored.anchor).toEqual(anchor)
|
|
672
|
+
expect(restored.proof).toEqual(proof)
|
|
673
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
674
|
+
expect(restored.coreFeePerByte).toEqual(coreFeePerByte)
|
|
675
|
+
expect(restored.pooling).toEqual('Never')
|
|
676
|
+
})
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
describe('computeMinimumFee', function () {
|
|
680
|
+
test('should return a positive fee', function () {
|
|
681
|
+
const fee = ShieldedWithdrawalTransitionWASM.computeMinimumFee(2)
|
|
682
|
+
|
|
683
|
+
expect(typeof fee).toEqual('bigint')
|
|
684
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
test('should grow with the action count', function () {
|
|
688
|
+
const oneAction = ShieldedWithdrawalTransitionWASM.computeMinimumFee(1)
|
|
689
|
+
const twoActions = ShieldedWithdrawalTransitionWASM.computeMinimumFee(2)
|
|
690
|
+
|
|
691
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
692
|
+
})
|
|
693
|
+
|
|
694
|
+
test('should default to the latest platform version', function () {
|
|
695
|
+
expect(ShieldedWithdrawalTransitionWASM.computeMinimumFee(2))
|
|
696
|
+
.toEqual(ShieldedWithdrawalTransitionWASM.computeMinimumFee(2, PlatformVersionWASM.PLATFORM_V12))
|
|
697
|
+
})
|
|
698
|
+
})
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
describe('IdentityCreateFromShieldedPoolTransition', function () {
|
|
702
|
+
let publicKeys: IdentityPublicKeyInCreationWASM[]
|
|
703
|
+
let denomination: bigint
|
|
704
|
+
let actions: SerializedActionWASM[]
|
|
705
|
+
let anchor: Uint8Array
|
|
706
|
+
let proof: Uint8Array
|
|
707
|
+
let bindingsSignature: Uint8Array
|
|
708
|
+
let sendToAddressOnCreationFailure: PlatformAddressWASM
|
|
709
|
+
let identityId: IdentifierWASM
|
|
710
|
+
|
|
711
|
+
beforeAll(function () {
|
|
712
|
+
publicKeys = [
|
|
713
|
+
new IdentityPublicKeyInCreationWASM(
|
|
714
|
+
0,
|
|
715
|
+
Purpose.AUTHENTICATION,
|
|
716
|
+
SecurityLevel.MASTER,
|
|
717
|
+
KeyType.ECDSA_SECP256K1,
|
|
718
|
+
false,
|
|
719
|
+
randomBytes(33)
|
|
720
|
+
)
|
|
721
|
+
]
|
|
722
|
+
denomination = BigInt(100000)
|
|
723
|
+
actions = [createTestAction()]
|
|
724
|
+
anchor = randomBytes(32)
|
|
725
|
+
proof = randomBytes(192)
|
|
726
|
+
bindingsSignature = randomBytes(64)
|
|
727
|
+
sendToAddressOnCreationFailure = createTestAddress()
|
|
728
|
+
identityId = IdentifierWASM.fromBytes(randomBytes(32))
|
|
729
|
+
})
|
|
730
|
+
|
|
731
|
+
describe('constructor', function () {
|
|
732
|
+
test('should create IdentityCreateFromShieldedPoolTransition from values', function () {
|
|
733
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
734
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
735
|
+
sendToAddressOnCreationFailure, identityId
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
expect(transition).toBeInstanceOf(IdentityCreateFromShieldedPoolTransitionWASM)
|
|
739
|
+
})
|
|
740
|
+
})
|
|
741
|
+
|
|
742
|
+
describe('getters', function () {
|
|
743
|
+
test('should return all fields', function () {
|
|
744
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
745
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
746
|
+
sendToAddressOnCreationFailure, identityId
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
expect(transition.publicKeys.length).toEqual(1)
|
|
750
|
+
expect(transition.denomination).toEqual(denomination)
|
|
751
|
+
expect(transition.actions.length).toEqual(1)
|
|
752
|
+
expect(transition.anchor).toEqual(anchor)
|
|
753
|
+
expect(transition.proof).toEqual(proof)
|
|
754
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
755
|
+
expect(transition.sendToAddressOnCreationFailure).toBeInstanceOf(PlatformAddressWASM)
|
|
756
|
+
expect(transition.sendToAddressOnCreationFailure.bytes()).toEqual(sendToAddressOnCreationFailure.bytes())
|
|
757
|
+
expect(transition.identityId).toBeInstanceOf(IdentifierWASM)
|
|
758
|
+
expect(transition.identityId.bytes()).toEqual(identityId.bytes())
|
|
759
|
+
})
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
describe('setters', function () {
|
|
763
|
+
test('should set all fields', function () {
|
|
764
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
765
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
766
|
+
sendToAddressOnCreationFailure, identityId
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
const newDenomination = BigInt(200000)
|
|
770
|
+
const newAnchor = randomBytes(32)
|
|
771
|
+
const newProof = randomBytes(192)
|
|
772
|
+
const newBindingsSignature = randomBytes(64)
|
|
773
|
+
const newAddress = createTestAddress()
|
|
774
|
+
const newIdentityId = IdentifierWASM.fromBytes(randomBytes(32))
|
|
775
|
+
|
|
776
|
+
transition.denomination = newDenomination
|
|
777
|
+
transition.anchor = newAnchor
|
|
778
|
+
transition.proof = newProof
|
|
779
|
+
transition.bindingsSignature = newBindingsSignature
|
|
780
|
+
transition.sendToAddressOnCreationFailure = newAddress
|
|
781
|
+
transition.identityId = newIdentityId
|
|
782
|
+
|
|
783
|
+
expect(transition.denomination).toEqual(newDenomination)
|
|
784
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
785
|
+
expect(transition.proof).toEqual(newProof)
|
|
786
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
787
|
+
expect(transition.sendToAddressOnCreationFailure.bytes()).toEqual(newAddress.bytes())
|
|
788
|
+
expect(transition.identityId.bytes()).toEqual(newIdentityId.bytes())
|
|
789
|
+
})
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
describe('serialization / deserialization', function () {
|
|
793
|
+
test('should roundtrip through StateTransition', function () {
|
|
794
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
795
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
796
|
+
sendToAddressOnCreationFailure, identityId
|
|
797
|
+
)
|
|
798
|
+
|
|
799
|
+
const st = transition.toStateTransition()
|
|
800
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
801
|
+
|
|
802
|
+
const restored = IdentityCreateFromShieldedPoolTransitionWASM.fromStateTransition(st)
|
|
803
|
+
expect(restored).toBeInstanceOf(IdentityCreateFromShieldedPoolTransitionWASM)
|
|
804
|
+
|
|
805
|
+
expect(restored.denomination).toEqual(denomination)
|
|
806
|
+
expect(restored.anchor).toEqual(anchor)
|
|
807
|
+
expect(restored.proof).toEqual(proof)
|
|
808
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
809
|
+
expect(restored.publicKeys.length).toEqual(1)
|
|
810
|
+
expect(restored.actions.length).toEqual(1)
|
|
811
|
+
expect(restored.sendToAddressOnCreationFailure.bytes()).toEqual(sendToAddressOnCreationFailure.bytes())
|
|
812
|
+
expect(restored.identityId.bytes()).toEqual(identityId.bytes())
|
|
813
|
+
})
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
describe('computeMinimumFee', function () {
|
|
817
|
+
test('should return a positive fee', function () {
|
|
818
|
+
const fee = IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 3)
|
|
819
|
+
|
|
820
|
+
expect(typeof fee).toEqual('bigint')
|
|
821
|
+
expect(fee).toBeGreaterThan(BigInt(0))
|
|
822
|
+
})
|
|
823
|
+
|
|
824
|
+
test('should grow with the action count', function () {
|
|
825
|
+
const oneAction = IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(1, 3)
|
|
826
|
+
const twoActions = IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 3)
|
|
827
|
+
|
|
828
|
+
expect(twoActions).toBeGreaterThan(oneAction)
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
test('should grow with the key count', function () {
|
|
832
|
+
const oneKey = IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 1)
|
|
833
|
+
const threeKeys = IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 3)
|
|
834
|
+
|
|
835
|
+
expect(threeKeys).toBeGreaterThan(oneKey)
|
|
836
|
+
})
|
|
837
|
+
|
|
838
|
+
test('should default to the latest platform version', function () {
|
|
839
|
+
expect(IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 3))
|
|
840
|
+
.toEqual(IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(2, 3, PlatformVersionWASM.PLATFORM_V12))
|
|
841
|
+
})
|
|
842
|
+
})
|
|
843
|
+
})
|
|
844
|
+
|
|
845
|
+
describe('computeMinimumFee across shielded transitions', function () {
|
|
846
|
+
const numActions = 2
|
|
847
|
+
|
|
848
|
+
test('Shield should be the compute-only fee, without the per-action storage term', function () {
|
|
849
|
+
expect(ShieldTransitionWASM.computeMinimumFee(numActions))
|
|
850
|
+
.toBeLessThan(ShieldedTransferTransitionWASM.computeMinimumFee(numActions))
|
|
851
|
+
})
|
|
852
|
+
|
|
853
|
+
test('Shield and ShieldedTransfer should agree with no actions', function () {
|
|
854
|
+
expect(ShieldTransitionWASM.computeMinimumFee(0))
|
|
855
|
+
.toEqual(ShieldedTransferTransitionWASM.computeMinimumFee(0))
|
|
856
|
+
})
|
|
857
|
+
|
|
858
|
+
test('ShieldFromAssetLock should match ShieldedTransfer', function () {
|
|
859
|
+
expect(ShieldFromAssetLockTransitionWASM.computeMinimumFee(numActions))
|
|
860
|
+
.toEqual(ShieldedTransferTransitionWASM.computeMinimumFee(numActions))
|
|
861
|
+
})
|
|
862
|
+
|
|
863
|
+
test('Unshield should add the output address write on top of ShieldedTransfer', function () {
|
|
864
|
+
expect(UnshieldTransitionWASM.computeMinimumFee(numActions))
|
|
865
|
+
.toBeGreaterThan(ShieldedTransferTransitionWASM.computeMinimumFee(numActions))
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
test('ShieldedWithdrawal should add the withdrawal document write on top of Unshield', function () {
|
|
869
|
+
expect(ShieldedWithdrawalTransitionWASM.computeMinimumFee(numActions))
|
|
870
|
+
.toBeGreaterThan(UnshieldTransitionWASM.computeMinimumFee(numActions))
|
|
871
|
+
})
|
|
872
|
+
|
|
873
|
+
test('IdentityCreateFromShieldedPool should add the identity create floor on top of ShieldedTransfer', function () {
|
|
874
|
+
expect(IdentityCreateFromShieldedPoolTransitionWASM.computeMinimumFee(numActions, 1))
|
|
875
|
+
.toBeGreaterThan(ShieldedTransferTransitionWASM.computeMinimumFee(numActions))
|
|
876
|
+
})
|
|
877
|
+
})
|