pshenmic-dpp 2.0.0-dev.25 → 2.0.0-dev.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binaries/bindingsTypes.d.ts +51 -1
- package/dist/binaries/bindingsTypes.js +1 -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 +42 -21
- package/dist/binaries/node.d.cts +2 -2
- package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
- package/dist/binaries/wasm/wasmBytes.cjs +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/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 -1
- package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +3 -0
- package/dist/src/dpp/structs/Orchard/RecoveredNote.d.ts +1 -0
- package/dist/src/dpp/structs/Orchard/RecoveredNote.js +3 -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 +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.js +3 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.d.ts +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.js +3 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.d.ts +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.js +3 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.d.ts +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.js +3 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.d.ts +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.js +3 -0
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.d.ts +2 -1
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.js +3 -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 +6 -0
- package/dist/src/dpp/verify/StateTransition/verifyStateTransitionResult.js +2 -1
- package/package.json +1 -1
- package/tests/unit/AddressTransitionsFees.spec.ts +274 -0
- package/tests/unit/Shielded.spec.ts +37 -4
- package/tests/unit/ShieldedTransitions.spec.ts +168 -0
- package/tests/unit/StateTransitionFees.spec.ts +177 -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
|
+
})
|