pshenmic-dpp 1.0.5 → 1.0.6

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 (118) hide show
  1. package/.github/workflows/build.yml +1 -1
  2. package/.github/workflows/publish.yml +1 -1
  3. package/Cargo.lock +147 -49
  4. package/Cargo.toml +13 -7
  5. package/README.md +10 -1
  6. package/dist/wasm/index.d.ts +52 -0
  7. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  8. package/dist/wasm/pshenmic_dpp.js +3342 -875
  9. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  10. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  11. package/docs/AssetLockProof.md +107 -0
  12. package/docs/Building.md +50 -0
  13. package/docs/ChainLockProof.md +63 -0
  14. package/docs/CoreScript.md +17 -0
  15. package/docs/DataContract.md +192 -0
  16. package/docs/DataContractCreateTransition.md +84 -0
  17. package/docs/DataContractUpdateTransition.md +84 -0
  18. package/docs/Document.md +396 -0
  19. package/docs/DocumentBaseTransition.md +111 -0
  20. package/docs/DocumentCreateTransition.md +132 -0
  21. package/docs/DocumentDeleteTransition.md +82 -0
  22. package/docs/DocumentPurchaseTransition.md +109 -0
  23. package/docs/DocumentReplaceTransition.md +112 -0
  24. package/docs/DocumentTransferTransition.md +96 -0
  25. package/docs/DocumentTransition.md +125 -0
  26. package/docs/DocumentUpdatePriceTransition.md +109 -0
  27. package/docs/DocumentsBatch.md +133 -0
  28. package/docs/Enums.md +103 -0
  29. package/docs/Home.md +28 -0
  30. package/docs/Identifier.md +37 -0
  31. package/docs/Identity.md +140 -0
  32. package/docs/IdentityCreateTransition.md +155 -0
  33. package/docs/IdentityCreditTransfer.md +187 -0
  34. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  35. package/docs/IdentityPublicKey.md +348 -0
  36. package/docs/IdentityPublicKeyInCreation.md +141 -0
  37. package/docs/IdentityTopUpTransition.md +166 -0
  38. package/docs/IdentityUpdateTransition.md +234 -0
  39. package/docs/InstantAssetLockProof.md +117 -0
  40. package/docs/InstantLock.md +100 -0
  41. package/docs/OutPoint.md +80 -0
  42. package/docs/PrefundedVotingBalance.md +48 -0
  43. package/docs/PrivateKey.md +112 -0
  44. package/docs/TxOut.md +93 -0
  45. package/package.json +3 -3
  46. package/packages/asset_lock_proof/Cargo.toml +19 -0
  47. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  48. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  49. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  50. package/packages/asset_lock_proof/src/lib.rs +133 -0
  51. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  52. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  53. package/packages/cbor_conversation/Cargo.toml +1 -1
  54. package/packages/core_script/Cargo.toml +13 -0
  55. package/packages/core_script/src/lib.rs +69 -0
  56. package/packages/data_contract/Cargo.toml +2 -1
  57. package/packages/data_contract/src/lib.rs +34 -30
  58. package/packages/data_contract_transitions/Cargo.toml +1 -1
  59. package/packages/data_contract_transitions/src/create/mod.rs +3 -3
  60. package/packages/data_contract_transitions/src/update/mod.rs +3 -3
  61. package/packages/document/Cargo.toml +2 -1
  62. package/packages/document/src/lib.rs +13 -12
  63. package/packages/document/src/methods/mod.rs +41 -38
  64. package/packages/documents_batch/Cargo.toml +2 -1
  65. package/packages/documents_batch/src/document_base_transition/mod.rs +16 -20
  66. package/packages/documents_batch/src/document_transition/mod.rs +9 -9
  67. package/packages/documents_batch/src/lib.rs +23 -16
  68. package/packages/documents_batch/src/transitions/create/mod.rs +5 -2
  69. package/packages/documents_batch/src/transitions/transfer/mod.rs +9 -11
  70. package/packages/enums/Cargo.toml +1 -1
  71. package/packages/enums/src/batch/batch_enum.rs +2 -2
  72. package/packages/enums/src/lib.rs +2 -0
  73. package/packages/enums/src/lock_types/mod.rs +65 -0
  74. package/packages/enums/src/platform/mod.rs +2 -0
  75. package/packages/enums/src/withdrawal/mod.rs +72 -0
  76. package/packages/identifier/Cargo.toml +9 -0
  77. package/packages/identifier/src/lib.rs +105 -0
  78. package/packages/identity/Cargo.toml +2 -1
  79. package/packages/identity/src/lib.rs +13 -18
  80. package/packages/identity_public_key/Cargo.toml +1 -1
  81. package/packages/identity_transitions/Cargo.toml +7 -3
  82. package/packages/identity_transitions/src/create_transition/mod.rs +99 -36
  83. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  84. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  85. package/packages/identity_transitions/src/lib.rs +6 -1
  86. package/packages/identity_transitions/src/{create_transition/public_key_in_creation → public_key_in_creation}/mod.rs +67 -20
  87. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  88. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  89. package/packages/private_key/Cargo.toml +1 -1
  90. package/packages/state_transition/Cargo.toml +2 -1
  91. package/packages/state_transition/src/lib.rs +3 -2
  92. package/packages/utils/Cargo.toml +2 -2
  93. package/packages/utils/src/lib.rs +0 -3
  94. package/scripts/build-js.sh +16 -0
  95. package/scripts/build.sh +5 -1
  96. package/src/lib.rs +1 -0
  97. package/tests/AssetLockProof.spec.js +80 -0
  98. package/tests/ChainLockProof.spec.js +69 -0
  99. package/tests/CoreScript.spec.js +37 -0
  100. package/tests/DataContract.spec.js +17 -14
  101. package/tests/Document.spec.js +14 -8
  102. package/tests/DocumentBatchTransition.spec.js +11 -11
  103. package/tests/DocumentTransition.spec.js +4 -4
  104. package/tests/DocumentsTransitions.spec.js +22 -22
  105. package/tests/Identifier.spec.js +84 -0
  106. package/tests/Identity.spec.js +1 -1
  107. package/tests/IdentityCreateTransition.spec.js +93 -0
  108. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  109. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  110. package/tests/IdentityTopUpTransition.spec.js +131 -0
  111. package/tests/IdentityUpdateTransition.spec.js +147 -0
  112. package/tests/InstantLockProof.spec.js +97 -0
  113. package/tests/OutPoint.spec.js +55 -0
  114. package/tests/PublicKeyInCreation.spec.js +258 -0
  115. package/tests/TxOut.spec.js +76 -0
  116. package/tests/mocks/Locks/index.js +5 -0
  117. package/tests/mocks/PublicKey/index.js +1 -1
  118. package/typings/index.d.ts +52 -0
@@ -0,0 +1,147 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+
5
+ let wasm
6
+
7
+ describe('IdentityUpdateTransition', function () {
8
+ before(async function () {
9
+ wasm = initWasm()
10
+ })
11
+
12
+ describe('serialization / deserialization', function () {
13
+ it('Should create IdentityUpdateTransition', function () {
14
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [])
15
+
16
+ assert.notEqual(transition.__wbg_ptr, 0)
17
+ })
18
+
19
+ it('Should create IdentityUpdateTransition with key', function () {
20
+ const key = new wasm.IdentityPublicKeyInCreationWASM(
21
+ 1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []
22
+ )
23
+
24
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [key], [])
25
+
26
+ assert.notEqual(transition.__wbg_ptr, 0)
27
+ assert.notEqual(key.__wbg_ptr, 0)
28
+ })
29
+ })
30
+
31
+ describe('getters', function () {
32
+ it('Should return revision', function () {
33
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [])
34
+
35
+ assert.deepEqual(transition.revision, BigInt(1))
36
+ })
37
+
38
+ it('Should return nonce', function () {
39
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [])
40
+
41
+ assert.deepEqual(transition.nonce, BigInt(1))
42
+ })
43
+
44
+ it('Should return identityIdentifier', function () {
45
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [])
46
+
47
+ assert.deepEqual(transition.identityIdentifier.base58(), 'GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3')
48
+ })
49
+
50
+ it('Should return publicKeyIdsToDisable', function () {
51
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
52
+
53
+ assert.deepEqual(Array.from(transition.publicKeyIdsToDisable), [11])
54
+ })
55
+
56
+ it('Should return publicKeyIdsToAdd', function () {
57
+ const key = new wasm.IdentityPublicKeyInCreationWASM(
58
+ 1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []
59
+ )
60
+
61
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [key], [11])
62
+
63
+ assert.deepEqual(transition.publicKeyIdsToAdd.length, 1)
64
+ })
65
+
66
+ it('Should return userFeeIncrease', function () {
67
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
68
+
69
+ assert.deepEqual(transition.userFeeIncrease, 1)
70
+ })
71
+
72
+ it('Should return signature', function () {
73
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
74
+
75
+ assert.deepEqual(transition.signature, Uint8Array.from([]))
76
+ })
77
+
78
+ it('Should return signature public key id', function () {
79
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
80
+
81
+ assert.deepEqual(transition.signaturePublicKeyId, 0)
82
+ })
83
+ })
84
+
85
+ describe('setters', function () {
86
+ it('Should allow to set identityIdentifier', function () {
87
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
88
+
89
+ transition.identityIdentifier = '11Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'
90
+
91
+ assert.deepEqual(transition.identityIdentifier.base58(), '11Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3')
92
+ })
93
+
94
+ it('Should allow to set revision', function () {
95
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
96
+
97
+ transition.revision = BigInt(11111)
98
+
99
+ assert.deepEqual(transition.revision, BigInt(11111))
100
+ })
101
+
102
+ it('Should allow to set nonce', function () {
103
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
104
+
105
+ transition.nonce = BigInt(11111)
106
+
107
+ assert.deepEqual(transition.nonce, BigInt(11111))
108
+ })
109
+
110
+ it('Should allow to set publicKeyIdsToDisable', function () {
111
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
112
+
113
+ transition.publicKeyIdsToDisable = [1, 2, 3, 4]
114
+
115
+ assert.deepEqual(transition.publicKeyIdsToDisable, Uint32Array.from([1, 2, 3, 4]))
116
+ })
117
+
118
+ it('Should allow to set publicKeyIdsToAdd', function () {
119
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
120
+
121
+ const key = new wasm.IdentityPublicKeyInCreationWASM(
122
+ 1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []
123
+ )
124
+
125
+ transition.publicKeyIdsToAdd = [key, key]
126
+
127
+ assert.deepEqual(transition.publicKeyIdsToAdd.length, 2)
128
+ assert.notEqual(key.__wbg_ptr, 0)
129
+ })
130
+
131
+ it('Should allow to set signature', function () {
132
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
133
+
134
+ transition.signature = [0, 1, 2, 3, 5]
135
+
136
+ assert.deepEqual(transition.signature, Uint8Array.from([0, 1, 2, 3, 5]))
137
+ })
138
+
139
+ it('Should allow to set signature public key id', function () {
140
+ const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], [11])
141
+
142
+ transition.signaturePublicKeyId = 11
143
+
144
+ assert.deepEqual(transition.signaturePublicKeyId, 11)
145
+ })
146
+ })
147
+ })
@@ -0,0 +1,97 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+ const { instantLockBytes, transactionBytes } = require('./mocks/Locks')
5
+
6
+ let wasm
7
+
8
+ describe('InstantLock', function () {
9
+ before(async function () {
10
+ wasm = initWasm()
11
+ })
12
+
13
+ describe('serialization / deserialization', function () {
14
+ it('should allow to create InstantLock from values', () => {
15
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
16
+
17
+ assert.notEqual(instantLockProof.__wbg_ptr, 0)
18
+ })
19
+
20
+ it('should allow to convert to object', () => {
21
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
22
+
23
+ const expected = {
24
+ instantLock: instantLockBytes,
25
+ transaction: transactionBytes,
26
+ outputIndex: 0
27
+ }
28
+
29
+ assert.deepEqual(instantLockProof.toObject(), expected)
30
+ })
31
+
32
+ it('should allow to create from object', () => {
33
+ const lockObject = {
34
+ instantLock: instantLockBytes,
35
+ transaction: transactionBytes,
36
+ outputIndex: 0
37
+ }
38
+
39
+ const instantLockProof = wasm.InstantAssetLockProofWASM.fromObject(lockObject)
40
+
41
+ assert.notEqual(instantLockProof.__wbg_ptr, 0)
42
+ })
43
+ })
44
+
45
+ describe('getters', function () {
46
+ it('should allow to get output', () => {
47
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
48
+
49
+ assert.deepEqual(instantLockProof.getOutput().constructor.name, 'TxOutWASM')
50
+ })
51
+
52
+ it('should allow to convert to get OutPoint', () => {
53
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
54
+
55
+ assert.deepEqual(instantLockProof.getOutPoint().constructor.name, 'OutPointWASM')
56
+ })
57
+
58
+ it('should allow to get output index', () => {
59
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
60
+
61
+ assert.deepEqual(instantLockProof.outputIndex, 0)
62
+ })
63
+
64
+ it('should allow to get instant lock', () => {
65
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
66
+
67
+ assert.deepEqual(instantLockProof.instantLock.constructor.name, 'InstantLockWASM')
68
+ })
69
+ })
70
+
71
+ describe('setters', function () {
72
+ it('should allow to set output index', () => {
73
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
74
+
75
+ instantLockProof.outputIndex = 12
76
+
77
+ assert.deepEqual(instantLockProof.outputIndex, 12)
78
+ })
79
+
80
+ it('should allow to set instant lock', () => {
81
+ const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0)
82
+
83
+ const newInstantLockProof = new wasm.InstantLockWASM(
84
+ 0,
85
+ [],
86
+ 'dbdb604952d08184b55d48c915ed78aadc81dbc5cc98e8b4821abe5b4bbcbecb',
87
+ '00000000000000151e0fe3ab9a12c57402153c9f476236148364ec4337213101',
88
+ 'a9f131626c49a2f183b7a2f563ad1dc50ac8220190dbedb805209b608eb864e01d62f18bc9faa60a8b8a27f5a0c7c8b914fa3a14360a2f25558ee0e0a693b18faccbb59ec39b9b3cae430e0b76eb080752ce103df76537a1a583680a5914529d'
89
+ )
90
+
91
+ instantLockProof.instantLock = newInstantLockProof
92
+
93
+ assert.deepEqual(instantLockProof.instantLock.version, 0)
94
+ assert.notEqual(newInstantLockProof.__wbg_ptr, 0)
95
+ })
96
+ })
97
+ })
@@ -0,0 +1,55 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+
5
+ let wasm
6
+
7
+ describe('OutPoint', function () {
8
+ before(async function () {
9
+ wasm = initWasm()
10
+ })
11
+
12
+ describe('serialization / deserialization', function () {
13
+ it('should allow to create from values', () => {
14
+ const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
15
+
16
+ assert.notEqual(outpoint.__wbg_ptr, 0)
17
+ })
18
+
19
+ it('should allow to create from bytes', () => {
20
+ const txIdBytes = Buffer.from('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 'hex')
21
+
22
+ // 32 bytes for txId and 4 bytes for vout
23
+ const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]
24
+
25
+ const outpoint = wasm.OutPointWASM.fromBytes(bytes)
26
+
27
+ assert.notEqual(outpoint.__wbg_ptr, 0)
28
+ })
29
+ })
30
+
31
+ describe('getters', function () {
32
+ it('should allow to get txid', function () {
33
+ const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
34
+
35
+ assert.equal(outpoint.getTXID(), 'e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d')
36
+ })
37
+
38
+ it('should allow to get VOUT', function () {
39
+ const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
40
+
41
+ assert.equal(outpoint.getVOUT(), 1)
42
+ })
43
+
44
+ it('should allow to get bytes', function () {
45
+ const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
46
+
47
+ const txIdBytes = Buffer.from('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 'hex')
48
+
49
+ // 32 bytes for txId and 4 bytes for vout
50
+ const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]
51
+
52
+ assert.deepEqual(outpoint.toBytes(), Uint8Array.from(bytes))
53
+ })
54
+ })
55
+ })
@@ -0,0 +1,258 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+
5
+ let wasm
6
+
7
+ describe('InstantLock', function () {
8
+ before(async function () {
9
+ wasm = initWasm()
10
+ })
11
+
12
+ describe('serialization / deserialization', function () {
13
+ it('should allow to create from values', () => {
14
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
15
+ 0,
16
+ 'AUTHENTICATION',
17
+ 'master',
18
+ 'ECDSA_SECP256K1',
19
+ false,
20
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
21
+ []
22
+ )
23
+
24
+ assert.notEqual(publicKeyInCreation.__wbg_ptr, 0)
25
+ })
26
+
27
+ it('should allow to create from values and convert to identity public key', () => {
28
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
29
+ 0,
30
+ 'AUTHENTICATION',
31
+ 'master',
32
+ 'ECDSA_SECP256K1',
33
+ false,
34
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
35
+ []
36
+ )
37
+
38
+ const publicKey = publicKeyInCreation.toIdentityPublicKey()
39
+
40
+ assert.notEqual(publicKeyInCreation.__wbg_ptr, 0)
41
+ assert.equal(publicKey.constructor.name, 'IdentityPublicKeyWASM')
42
+ })
43
+ })
44
+
45
+ describe('getters', function () {
46
+ it('should allow to get key id', () => {
47
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
48
+ 0,
49
+ 'AUTHENTICATION',
50
+ 'master',
51
+ 'ECDSA_SECP256K1',
52
+ false,
53
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
54
+ []
55
+ )
56
+
57
+ assert.equal(publicKeyInCreation.keyId, 0)
58
+ })
59
+
60
+ it('should allow to get purpose', () => {
61
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
62
+ 0,
63
+ 'AUTHENTICATION',
64
+ 'master',
65
+ 'ECDSA_SECP256K1',
66
+ false,
67
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
68
+ []
69
+ )
70
+
71
+ assert.equal(publicKeyInCreation.purpose, 'AUTHENTICATION')
72
+ })
73
+
74
+ it('should allow to get security level', () => {
75
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
76
+ 0,
77
+ 'AUTHENTICATION',
78
+ 'master',
79
+ 'ECDSA_SECP256K1',
80
+ false,
81
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
82
+ []
83
+ )
84
+
85
+ assert.equal(publicKeyInCreation.securityLevel, 'MASTER')
86
+ })
87
+
88
+ it('should allow to get key type', () => {
89
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
90
+ 0,
91
+ 'AUTHENTICATION',
92
+ 'master',
93
+ 'ECDSA_SECP256K1',
94
+ false,
95
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
96
+ []
97
+ )
98
+
99
+ assert.equal(publicKeyInCreation.keyType, 'ECDSA_SECP256K1')
100
+ })
101
+
102
+ it('should allow to get read only', () => {
103
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
104
+ 0,
105
+ 'AUTHENTICATION',
106
+ 'master',
107
+ 'ECDSA_SECP256K1',
108
+ false,
109
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
110
+ []
111
+ )
112
+
113
+ assert.equal(publicKeyInCreation.readOnly, false)
114
+ })
115
+
116
+ it('should allow to get data', () => {
117
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
118
+ 0,
119
+ 'AUTHENTICATION',
120
+ 'master',
121
+ 'ECDSA_SECP256K1',
122
+ false,
123
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
124
+ []
125
+ )
126
+
127
+ assert.deepEqual(Buffer.from(publicKeyInCreation.data), Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'))
128
+ })
129
+
130
+ it('should allow to get signature', () => {
131
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
132
+ 0,
133
+ 'AUTHENTICATION',
134
+ 'master',
135
+ 'ECDSA_SECP256K1',
136
+ false,
137
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
138
+ []
139
+ )
140
+
141
+ assert.deepEqual([...publicKeyInCreation.signature], [])
142
+ })
143
+ })
144
+
145
+ describe('setters', function () {
146
+ it('should allow to set key id', () => {
147
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
148
+ 0,
149
+ 'AUTHENTICATION',
150
+ 'master',
151
+ 'ECDSA_SECP256K1',
152
+ false,
153
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
154
+ []
155
+ )
156
+
157
+ publicKeyInCreation.keyId = 123
158
+
159
+ assert.equal(publicKeyInCreation.keyId, 123)
160
+ })
161
+
162
+ it('should allow to set purpose', () => {
163
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
164
+ 0,
165
+ 'AUTHENTICATION',
166
+ 'master',
167
+ 'ECDSA_SECP256K1',
168
+ false,
169
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
170
+ []
171
+ )
172
+
173
+ publicKeyInCreation.purpose = 'OWNER'
174
+
175
+ assert.equal(publicKeyInCreation.purpose, 'OWNER')
176
+ })
177
+
178
+ it('should allow to set security level', () => {
179
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
180
+ 0,
181
+ 'AUTHENTICATION',
182
+ 'master',
183
+ 'ECDSA_SECP256K1',
184
+ false,
185
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
186
+ []
187
+ )
188
+
189
+ publicKeyInCreation.securityLevel = 'critical'
190
+
191
+ assert.equal(publicKeyInCreation.securityLevel, 'CRITICAL')
192
+ })
193
+
194
+ it('should allow to set key type', () => {
195
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
196
+ 0,
197
+ 'AUTHENTICATION',
198
+ 'master',
199
+ 'ECDSA_SECP256K1',
200
+ false,
201
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
202
+ []
203
+ )
204
+
205
+ publicKeyInCreation.keyType = 'ECDSA_HASH160'
206
+
207
+ assert.equal(publicKeyInCreation.keyType, 'ECDSA_HASH160')
208
+ })
209
+
210
+ it('should allow to set read only', () => {
211
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
212
+ 0,
213
+ 'AUTHENTICATION',
214
+ 'master',
215
+ 'ECDSA_SECP256K1',
216
+ false,
217
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
218
+ []
219
+ )
220
+
221
+ publicKeyInCreation.readOnly = true
222
+
223
+ assert.equal(publicKeyInCreation.readOnly, true)
224
+ })
225
+
226
+ it('should allow to set data', () => {
227
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
228
+ 0,
229
+ 'AUTHENTICATION',
230
+ 'master',
231
+ 'ECDSA_SECP256K1',
232
+ false,
233
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
234
+ []
235
+ )
236
+
237
+ publicKeyInCreation.data = Buffer.from('333333333334001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex')
238
+
239
+ assert.deepEqual(Buffer.from(publicKeyInCreation.data), Buffer.from('333333333334001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'))
240
+ })
241
+
242
+ it('should allow to set signature', () => {
243
+ const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM(
244
+ 0,
245
+ 'AUTHENTICATION',
246
+ 'master',
247
+ 'ECDSA_SECP256K1',
248
+ false,
249
+ Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'),
250
+ []
251
+ )
252
+
253
+ publicKeyInCreation.signature = [1, 2, 3, 4, 5, 6]
254
+
255
+ assert.deepEqual([...publicKeyInCreation.signature], [1, 2, 3, 4, 5, 6])
256
+ })
257
+ })
258
+ })
@@ -0,0 +1,76 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+
5
+ let wasm
6
+
7
+ describe('TxOut', function () {
8
+ before(async function () {
9
+ wasm = initWasm()
10
+ })
11
+
12
+ describe('serialization / deserialization', function () {
13
+ it('should allow to create from values with pubkey hex', function () {
14
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
15
+ assert.notEqual(out.__wbg_ptr, 0)
16
+ })
17
+
18
+ it('should allow to create from values with pubkey array', function () {
19
+ const out = new wasm.TxOutWASM(BigInt(100), Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex')))
20
+
21
+ assert.notEqual(out.__wbg_ptr, 0)
22
+ })
23
+ })
24
+
25
+ describe('getters', function () {
26
+ it('should allow to get value', function () {
27
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
28
+
29
+ assert.equal(out.value, BigInt(100))
30
+ })
31
+
32
+ it('should allow to get script hex', function () {
33
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
34
+
35
+ assert.equal(out.scriptPubKeyHex, '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
36
+ })
37
+
38
+ it('should allow to get script bytes', function () {
39
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
40
+
41
+ assert.deepEqual(out.scriptPubKeyBytes, Uint8Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex')))
42
+ })
43
+
44
+ it('should allow to get script asm', function () {
45
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
46
+
47
+ assert.deepEqual(out.getScriptPubKeyASM(), 'OP_DUP OP_HASH160 OP_PUSHBYTES_20 1a486a3855e6dc6dd02874424f53a6f2197b3d45 OP_EQUALVERIFY OP_CHECKSIG')
48
+ })
49
+ })
50
+
51
+ describe('setters', function () {
52
+ it('should allow to set value', function () {
53
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
54
+
55
+ out.value = BigInt(101)
56
+
57
+ assert.equal(out.value, BigInt(101))
58
+ })
59
+
60
+ it('should allow to set script hex', function () {
61
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
62
+
63
+ out.scriptPubKeyHex = '16a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'
64
+
65
+ assert.equal(out.scriptPubKeyHex, '16a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
66
+ })
67
+
68
+ it('should allow to set script bytes', function () {
69
+ const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
70
+
71
+ out.scriptPubKeyBytes = Array.from(Buffer.from('76a914f995e42d1aa7a31b0106b63e1b896fe9aeeccc9988ac', 'hex'))
72
+
73
+ assert.deepEqual(out.scriptPubKeyBytes, Uint8Array.from(Buffer.from('76a914f995e42d1aa7a31b0106b63e1b896fe9aeeccc9988ac', 'hex')))
74
+ })
75
+ })
76
+ })
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ instantLockBytes: [1, 1, 89, 68, 206, 254, 139, 111, 183, 115, 169, 122, 19, 26, 29, 175, 97, 14, 156, 207, 215, 16, 92, 152, 110, 29, 167, 34, 91, 149, 243, 48, 250, 217, 0, 0, 0, 0, 61, 111, 50, 237, 225, 255, 25, 159, 133, 89, 244, 234, 150, 19, 61, 198, 218, 144, 144, 44, 45, 189, 109, 187, 247, 117, 93, 95, 156, 46, 12, 216, 1, 49, 33, 55, 67, 236, 100, 131, 20, 54, 98, 71, 159, 60, 21, 2, 116, 197, 18, 154, 171, 227, 15, 30, 21, 0, 0, 0, 0, 0, 0, 0, 169, 241, 49, 98, 108, 73, 162, 241, 131, 183, 162, 245, 99, 173, 29, 197, 10, 200, 34, 1, 144, 219, 237, 184, 5, 32, 155, 96, 142, 184, 100, 224, 29, 98, 241, 139, 201, 250, 166, 10, 139, 138, 39, 245, 160, 199, 200, 185, 20, 250, 58, 20, 54, 10, 47, 37, 85, 142, 224, 224, 166, 147, 177, 143, 172, 203, 181, 158, 195, 155, 155, 60, 174, 67, 14, 11, 118, 235, 8, 7, 82, 206, 16, 61, 247, 101, 55, 161, 165, 131, 104, 10, 89, 20, 82, 157],
3
+ transactionBytes: [3, 0, 8, 0, 1, 89, 68, 206, 254, 139, 111, 183, 115, 169, 122, 19, 26, 29, 175, 97, 14, 156, 207, 215, 16, 92, 152, 110, 29, 167, 34, 91, 149, 243, 48, 250, 217, 0, 0, 0, 0, 107, 72, 48, 69, 2, 33, 0, 157, 215, 234, 11, 75, 36, 23, 153, 82, 143, 163, 76, 75, 118, 142, 19, 6, 13, 64, 50, 24, 199, 141, 199, 163, 14, 86, 81, 67, 150, 240, 28, 2, 32, 105, 238, 106, 123, 228, 237, 166, 210, 251, 103, 249, 36, 15, 233, 177, 30, 40, 125, 67, 108, 224, 183, 4, 5, 18, 239, 231, 185, 223, 195, 92, 240, 1, 33, 3, 238, 76, 67, 141, 205, 25, 38, 200, 164, 105, 53, 55, 189, 36, 52, 232, 121, 166, 108, 186, 227, 161, 55, 7, 105, 135, 102, 219, 224, 117, 213, 70, 255, 255, 255, 255, 2, 128, 29, 44, 4, 0, 0, 0, 0, 2, 106, 0, 48, 232, 38, 1, 0, 0, 0, 0, 25, 118, 169, 20, 232, 101, 217, 39, 144, 120, 74, 135, 230, 203, 134, 239, 207, 15, 238, 152, 16, 172, 45, 177, 136, 172, 0, 0, 0, 0, 36, 1, 1, 128, 29, 44, 4, 0, 0, 0, 0, 25, 118, 169, 20, 12, 182, 70, 130, 142, 161, 106, 83, 94, 200, 33, 4, 251, 5, 50, 93, 28, 107, 159, 168, 136, 172]
4
+
5
+ }
@@ -2,7 +2,7 @@ const { Purpose, SecurityLevel, KeyType } = require('../../../dist/cjs/wasm/pshe
2
2
 
3
3
  module.exports = {
4
4
  keyId: 2,
5
- purpose: Purpose.AUTHENTICATION,
5
+ purpose: 'AUTHENTICATION',
6
6
  securityLevel: SecurityLevel.CRITICAL,
7
7
  keyType: KeyType.ECDSA_SECP256K1,
8
8
  binaryData: '036a394312e40e81d928fde2bde7880070e4fa9c1d1d9b168da707ea468afa2b48',