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,37 @@
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('CoreScript', function () {
8
+ before(async function () {
9
+ wasm = initWasm()
10
+ })
11
+
12
+ describe('serialization / deserialization', function () {
13
+ it('should allow to create from bytes', () => {
14
+ const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a914c3dbfd40e7f8a4845c2f8e868a167c984049764988ac', 'hex'))
15
+
16
+ assert.notEqual(script._wbg_ptr, 0)
17
+ })
18
+
19
+ it('should allow to create P2PKH', () => {
20
+ const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
21
+
22
+ assert.notEqual(script._wbg_ptr, 0)
23
+ })
24
+
25
+ it('should allow to create P2SH', () => {
26
+ const script = wasm.CoreScriptWASM.newP2SH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
27
+
28
+ assert.notEqual(script._wbg_ptr, 0)
29
+ })
30
+
31
+ it('should allow to convert to asm P2PKH', () => {
32
+ const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
33
+
34
+ assert.equal(script.toASMString(), 'OP_DUP OP_HASH160 OP_PUSHBYTES_20 c3dbfd40e7f8a4845c2f8e868a167c9840497649 OP_EQUALVERIFY OP_CHECKSIG')
35
+ })
36
+ })
37
+ })
@@ -3,7 +3,6 @@ const { describe, it, before } = require('mocha')
3
3
  const initWasm = require('./utils/wasm')
4
4
  const { value, id, ownerId } = require('./mocks/DataContract')
5
5
  const { PlatformVersionWASM } = require('../dist/cjs/wasm/pshenmic_dpp')
6
- const { base58 } = require('@scure/base')
7
6
  const { fromHexString } = require('./utils/hex')
8
7
 
9
8
  let wasm
@@ -19,13 +18,17 @@ describe('DataContract', function () {
19
18
 
20
19
  describe('serialization / deserialization', function () {
21
20
  it('should allows to create DataContract from schema without full validation', function () {
22
- const dataContract = new wasm.DataContractWASM(value.ownerId, BigInt(2), value.documentSchemas, null, false)
21
+ const identifier = new wasm.IdentifierWASM(value.ownerId)
22
+
23
+ const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, false)
23
24
 
24
25
  assert.notEqual(dataContract.__wbg_ptr, 0)
25
26
  })
26
27
 
27
28
  it('should allows to create DataContract from schema with full validation', function () {
28
- const dataContract = new wasm.DataContractWASM(value.ownerId, BigInt(2), value.documentSchemas, null, true)
29
+ const identifier = new wasm.IdentifierWASM(value.ownerId)
30
+
31
+ const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, true)
29
32
 
30
33
  assert.notEqual(dataContract.__wbg_ptr, 0)
31
34
  })
@@ -91,13 +94,13 @@ describe('DataContract', function () {
91
94
  it('should allow to get id', function () {
92
95
  const dataContract = wasm.DataContractWASM.fromValue(value, true)
93
96
 
94
- assert.deepEqual(dataContract.getId(), base58.decode(id))
97
+ assert.deepEqual(dataContract.getId().base58(), id)
95
98
  })
96
99
 
97
100
  it('should allow to get owner id', function () {
98
101
  const dataContract = wasm.DataContractWASM.fromValue(value, true)
99
102
 
100
- assert.deepEqual(dataContract.getOwnerId(), base58.decode(ownerId))
103
+ assert.deepEqual(dataContract.getOwnerId().base58(), ownerId)
101
104
  })
102
105
 
103
106
  it('should allow to get config', function () {
@@ -111,21 +114,21 @@ describe('DataContract', function () {
111
114
  it('should allow to set id', function () {
112
115
  const dataContract = wasm.DataContractWASM.fromValue(value, true)
113
116
 
114
- const valueId = base58.decode('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
117
+ const identifier = new wasm.IdentifierWASM('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
115
118
 
116
- dataContract.setId(Array.from(valueId))
119
+ dataContract.setId(identifier)
117
120
 
118
- assert.deepEqual(dataContract.getId(), valueId)
121
+ assert.deepEqual(dataContract.getId().base58(), '7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
119
122
  })
120
123
 
121
124
  it('should allow to set owner id', function () {
122
125
  const dataContract = wasm.DataContractWASM.fromValue(value, true)
123
126
 
124
- const valueId = base58.decode('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
127
+ const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
125
128
 
126
- dataContract.setOwnerId('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
129
+ dataContract.setOwnerId(identifier)
127
130
 
128
- assert.deepEqual(dataContract.getOwnerId(), valueId)
131
+ assert.deepEqual(dataContract.getOwnerId().base58(), '3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
129
132
  })
130
133
 
131
134
  it('should allow to set version', function () {
@@ -165,11 +168,11 @@ describe('DataContract', function () {
165
168
 
166
169
  describe('static', function () {
167
170
  it('should allow to generate id', function () {
168
- const id = wasm.DataContractWASM.generateId('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL', BigInt(4))
171
+ const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
169
172
 
170
- const valueId = base58.decode('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
173
+ const id = wasm.DataContractWASM.generateId(identifier, BigInt(4))
171
174
 
172
- assert.deepEqual(id, valueId)
175
+ assert.deepEqual(id.base58(), '7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
173
176
  })
174
177
  })
175
178
  })
@@ -5,7 +5,6 @@ const {
5
5
  document, dataContractId, ownerId, documentTypeName, revision, dataContractValue, id, document2, documentBytes
6
6
  } = require('./mocks/Document')
7
7
  const { fromHexString } = require('./utils/hex')
8
- const { base58 } = require('@scure/base')
9
8
 
10
9
  let wasm
11
10
 
@@ -16,13 +15,20 @@ describe('Document', function () {
16
15
 
17
16
  describe('serialization / deserialization', function () {
18
17
  it('should allows to create Document from values', function () {
19
- const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId)
18
+ const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId)
19
+ const ownerIdentifier = new wasm.IdentifierWASM(ownerId)
20
+
21
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier)
20
22
 
21
23
  assert.notEqual(documentInstance.__wbg_ptr, 0)
22
24
  })
23
25
 
24
26
  it('should allows to create Document from values with custom id', function () {
25
- const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
27
+ const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId)
28
+ const ownerIdentifier = new wasm.IdentifierWASM(ownerId)
29
+ const identifier = new wasm.IdentifierWASM(id)
30
+
31
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier, identifier)
26
32
 
27
33
  assert.notEqual(documentInstance.__wbg_ptr, 0)
28
34
  })
@@ -42,19 +48,19 @@ describe('Document', function () {
42
48
  it('should return document id', () => {
43
49
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
44
50
 
45
- assert.deepEqual(documentInstance.getId(), base58.decode(id))
51
+ assert.deepEqual(documentInstance.getId().base58(), id)
46
52
  })
47
53
 
48
54
  it('should return owner id', () => {
49
55
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
50
56
 
51
- assert.deepEqual(documentInstance.getOwnerId(), base58.decode(ownerId))
57
+ assert.deepEqual(documentInstance.getOwnerId().base58(), ownerId)
52
58
  })
53
59
 
54
60
  it('should return data contract id', () => {
55
61
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
56
62
 
57
- assert.deepEqual(documentInstance.getDataContractId(), base58.decode(dataContractId))
63
+ assert.deepEqual(documentInstance.getDataContractId().base58(), dataContractId)
58
64
  })
59
65
 
60
66
  it('should return properties', () => {
@@ -82,7 +88,7 @@ describe('Document', function () {
82
88
 
83
89
  documentInstance.setId(ownerId)
84
90
 
85
- assert.deepEqual(documentInstance.getId(), base58.decode(ownerId))
91
+ assert.deepEqual(documentInstance.getId().base58(), ownerId)
86
92
  })
87
93
 
88
94
  it('should allow to set document owner id', () => {
@@ -90,7 +96,7 @@ describe('Document', function () {
90
96
 
91
97
  documentInstance.setOwnerId(id)
92
98
 
93
- assert.deepEqual(documentInstance.getOwnerId(), base58.decode(id))
99
+ assert.deepEqual(documentInstance.getOwnerId().base58(), id)
94
100
  })
95
101
 
96
102
  it('should allow to set entropy', () => {
@@ -5,7 +5,7 @@ const { document, documentTypeName, revision, dataContractId, ownerId, id } = re
5
5
 
6
6
  let wasm
7
7
 
8
- describe('PrivateKey', function () {
8
+ describe('DocumentsBatch', function () {
9
9
  before(async function () {
10
10
  wasm = initWasm()
11
11
  })
@@ -17,7 +17,7 @@ describe('PrivateKey', function () {
17
17
 
18
18
  const documentTransition = createTransition.toDocumentTransition()
19
19
 
20
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1)
20
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1)
21
21
 
22
22
  assert.notEqual(documentInstance.__wbg_ptr, 0)
23
23
  assert.notEqual(createTransition.__wbg_ptr, 0)
@@ -33,7 +33,7 @@ describe('PrivateKey', function () {
33
33
 
34
34
  const documentTransition = createTransition.toDocumentTransition()
35
35
 
36
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
36
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
37
37
 
38
38
  assert.equal(batchTransition.transitions.length, 2)
39
39
  })
@@ -44,7 +44,7 @@ describe('PrivateKey', function () {
44
44
 
45
45
  const documentTransition = createTransition.toDocumentTransition()
46
46
 
47
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
47
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
48
48
 
49
49
  assert.deepEqual(batchTransition.signature, new Uint8Array(0))
50
50
  })
@@ -55,7 +55,7 @@ describe('PrivateKey', function () {
55
55
 
56
56
  const documentTransition = createTransition.toDocumentTransition()
57
57
 
58
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
58
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
59
59
 
60
60
  assert.equal(batchTransition.signaturePublicKeyId, 1)
61
61
  })
@@ -68,7 +68,7 @@ describe('PrivateKey', function () {
68
68
  const documentTransition = createTransition.toDocumentTransition()
69
69
  const documentTransition2 = purchaseTransition.toDocumentTransition()
70
70
 
71
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition2], Array.from(documentInstance.getOwnerId()), 1, 1)
71
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition2], documentInstance.getOwnerId(), 1, 1)
72
72
 
73
73
  assert.deepEqual(batchTransition.allPurchasesAmount, BigInt(100))
74
74
  })
@@ -79,9 +79,9 @@ describe('PrivateKey', function () {
79
79
 
80
80
  const documentTransition = createTransition.toDocumentTransition()
81
81
 
82
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
82
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
83
83
 
84
- assert.deepEqual(batchTransition.ownerId, documentInstance.getOwnerId())
84
+ assert.deepEqual(batchTransition.ownerId.base58(), documentInstance.getOwnerId().base58())
85
85
  })
86
86
 
87
87
  it('should allow to get modified data ids', function () {
@@ -90,9 +90,9 @@ describe('PrivateKey', function () {
90
90
 
91
91
  const documentTransition = createTransition.toDocumentTransition()
92
92
 
93
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
93
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
94
94
 
95
- assert.deepEqual(batchTransition.modifiedDataIds, [Array.from(documentTransition.id), Array.from(documentTransition.id)])
95
+ assert.deepEqual(batchTransition.modifiedDataIds.map(id => id.base58()), [documentTransition.id.base58(), documentTransition.id.base58()])
96
96
  })
97
97
 
98
98
  it('should allow to get allConflictingIndexCollateralVotingFunds', function () {
@@ -101,7 +101,7 @@ describe('PrivateKey', function () {
101
101
 
102
102
  const documentTransition = createTransition.toDocumentTransition()
103
103
 
104
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
104
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
105
105
 
106
106
  assert.deepEqual(batchTransition.allConflictingIndexCollateralVotingFunds, undefined)
107
107
  })
@@ -8,7 +8,7 @@ let documentInstance
8
8
  let createTransition
9
9
  let replaceTransition
10
10
 
11
- describe('PrivateKey', function () {
11
+ describe('DocumentTransition', function () {
12
12
  before(async function () {
13
13
  wasm = initWasm()
14
14
 
@@ -35,13 +35,13 @@ describe('PrivateKey', function () {
35
35
  it('should allow to get dataContractId', function () {
36
36
  const documentTransition = createTransition.toDocumentTransition()
37
37
 
38
- assert.deepEqual(documentTransition.dataContractId, documentInstance.getDataContractId())
38
+ assert.deepEqual(documentTransition.dataContractId.base58(), documentInstance.getDataContractId().base58())
39
39
  })
40
40
 
41
41
  it('should allow to get id', function () {
42
42
  const documentTransition = createTransition.toDocumentTransition()
43
43
 
44
- assert.deepEqual(documentTransition.id, documentInstance.getId())
44
+ assert.deepEqual(documentTransition.id.base58(), documentInstance.getId().base58())
45
45
  })
46
46
 
47
47
  it('should allow to get documentTypeName', function () {
@@ -75,7 +75,7 @@ describe('PrivateKey', function () {
75
75
 
76
76
  documentTransition.dataContractId = new Uint8Array(32)
77
77
 
78
- assert.deepEqual(documentTransition.dataContractId, new Uint8Array(32))
78
+ assert.deepEqual(documentTransition.dataContractId.bytes(), new Uint8Array(32))
79
79
  })
80
80
 
81
81
  it('should allow to set identityContractNonce', function () {
@@ -37,7 +37,7 @@ describe('DocumentsTransitions', function () {
37
37
 
38
38
  const documentTransition = createTransition.toDocumentTransition()
39
39
 
40
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
40
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
41
41
 
42
42
  assert.notEqual(documentInstance.__wbg_ptr, 0)
43
43
  assert.notEqual(createTransition.__wbg_ptr, 0)
@@ -51,7 +51,7 @@ describe('DocumentsTransitions', function () {
51
51
 
52
52
  const documentTransition = createTransition.toDocumentTransition()
53
53
 
54
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
54
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
55
55
 
56
56
  const st = batchTransition.toStateTransition()
57
57
 
@@ -99,7 +99,7 @@ describe('DocumentsTransitions', function () {
99
99
 
100
100
  const documentTransition = deleteTransition.toDocumentTransition()
101
101
 
102
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
102
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
103
103
 
104
104
  assert.notEqual(documentInstance.__wbg_ptr, 0)
105
105
  assert.notEqual(deleteTransition.__wbg_ptr, 0)
@@ -113,7 +113,7 @@ describe('DocumentsTransitions', function () {
113
113
 
114
114
  const documentTransition = deleteTransition.toDocumentTransition()
115
115
 
116
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
116
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
117
117
 
118
118
  const st = batchTransition.toStateTransition()
119
119
 
@@ -161,7 +161,7 @@ describe('DocumentsTransitions', function () {
161
161
 
162
162
  const documentTransition = replaceTransition.toDocumentTransition()
163
163
 
164
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
164
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
165
165
 
166
166
  assert.notEqual(documentInstance.__wbg_ptr, 0)
167
167
  assert.notEqual(replaceTransition.__wbg_ptr, 0)
@@ -175,7 +175,7 @@ describe('DocumentsTransitions', function () {
175
175
 
176
176
  const documentTransition = replaceTransition.toDocumentTransition()
177
177
 
178
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
178
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
179
179
 
180
180
  const st = batchTransition.toStateTransition()
181
181
 
@@ -200,7 +200,7 @@ describe('DocumentsTransitions', function () {
200
200
  describe('document Transfer transition', function () {
201
201
  it('should allow to create ReplaceTransition from document', () => {
202
202
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
203
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
203
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
204
204
 
205
205
  assert.notEqual(documentInstance.__wbg_ptr, 0)
206
206
  assert.notEqual(transferTransition.__wbg_ptr, 0)
@@ -208,7 +208,7 @@ describe('DocumentsTransitions', function () {
208
208
 
209
209
  it('should allow to create Document Transition from Replace transition', () => {
210
210
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
211
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
211
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
212
212
 
213
213
  const documentTransition = transferTransition.toDocumentTransition()
214
214
 
@@ -219,11 +219,11 @@ describe('DocumentsTransitions', function () {
219
219
 
220
220
  it('should allow to create Document Batch Transition from Document Transitions', () => {
221
221
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
222
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
222
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
223
223
 
224
224
  const documentTransition = transferTransition.toDocumentTransition()
225
225
 
226
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
226
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
227
227
 
228
228
  assert.notEqual(documentInstance.__wbg_ptr, 0)
229
229
  assert.notEqual(transferTransition.__wbg_ptr, 0)
@@ -233,11 +233,11 @@ describe('DocumentsTransitions', function () {
233
233
 
234
234
  it('should allow to create state transitions from document and convert state transition to document batch', () => {
235
235
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
236
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
236
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
237
237
 
238
238
  const documentTransition = transferTransition.toDocumentTransition()
239
239
 
240
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
240
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
241
241
 
242
242
  const st = batchTransition.toStateTransition()
243
243
 
@@ -285,7 +285,7 @@ describe('DocumentsTransitions', function () {
285
285
 
286
286
  const documentTransition = updatePriceTransition.toDocumentTransition()
287
287
 
288
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
288
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
289
289
 
290
290
  assert.notEqual(documentInstance.__wbg_ptr, 0)
291
291
  assert.notEqual(updatePriceTransition.__wbg_ptr, 0)
@@ -299,7 +299,7 @@ describe('DocumentsTransitions', function () {
299
299
 
300
300
  const documentTransition = updatePriceTransition.toDocumentTransition()
301
301
 
302
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
302
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
303
303
 
304
304
  const st = batchTransition.toStateTransition()
305
305
 
@@ -347,7 +347,7 @@ describe('DocumentsTransitions', function () {
347
347
 
348
348
  const documentTransition = purchaseTransition.toDocumentTransition()
349
349
 
350
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
350
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
351
351
 
352
352
  assert.notEqual(documentInstance.__wbg_ptr, 0)
353
353
  assert.notEqual(purchaseTransition.__wbg_ptr, 0)
@@ -361,7 +361,7 @@ describe('DocumentsTransitions', function () {
361
361
 
362
362
  const documentTransition = purchaseTransition.toDocumentTransition()
363
363
 
364
- const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
364
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], documentInstance.getOwnerId(), 1, 1)
365
365
 
366
366
  const st = batchTransition.toStateTransition()
367
367
 
@@ -449,16 +449,16 @@ describe('DocumentsTransitions', function () {
449
449
  describe('document Transfer transition', function () {
450
450
  it('get base', () => {
451
451
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
452
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
452
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
453
453
 
454
454
  assert.equal(transferTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
455
455
  })
456
456
 
457
457
  it('get recipient', () => {
458
458
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
459
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
459
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
460
460
 
461
- assert.deepEqual(transferTransition.recipientId, documentInstance.getOwnerId())
461
+ assert.deepEqual(transferTransition.recipientId.base58(), documentInstance.getOwnerId().base58())
462
462
  })
463
463
  })
464
464
 
@@ -610,7 +610,7 @@ describe('DocumentsTransitions', function () {
610
610
  describe('document Transfer transition', function () {
611
611
  it('set base', () => {
612
612
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
613
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
613
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
614
614
 
615
615
  const newBase = new wasm.DocumentBaseTransitionWASM(
616
616
  documentInstance.getId(),
@@ -627,13 +627,13 @@ describe('DocumentsTransitions', function () {
627
627
 
628
628
  it('set recipient', () => {
629
629
  const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
630
- const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
630
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', documentInstance.getOwnerId())
631
631
 
632
632
  const newRecipient = new Uint8Array(32)
633
633
 
634
634
  transferTransition.recipientId = newRecipient
635
635
 
636
- assert.deepEqual(transferTransition.recipientId, newRecipient)
636
+ assert.deepEqual(transferTransition.recipientId.bytes(), newRecipient)
637
637
  })
638
638
  })
639
639
 
@@ -0,0 +1,84 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+
5
+ let wasm
6
+ let identifierBytes
7
+
8
+ describe('Identifier', function () {
9
+ before(async function () {
10
+ identifierBytes = Uint8Array.from([9, 40, 40, 237, 192, 129, 211, 186, 26, 84, 240, 67, 37, 155, 148, 19, 104, 242, 199, 24, 136, 27, 6, 169, 211, 71, 136, 59, 33, 191, 227, 19])
11
+ wasm = initWasm()
12
+ })
13
+
14
+ describe('serialization / deserialization', function () {
15
+ it('should allows to create Identifier from base58', function () {
16
+ const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
17
+
18
+ assert.deepEqual(identifier.bytes(), identifierBytes)
19
+ })
20
+
21
+ it('should allows to create Identifier from base64', function () {
22
+ const identifier = wasm.IdentifierWASM.fromBase64('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM=')
23
+
24
+ assert.deepEqual(identifier.bytes(), identifierBytes)
25
+ })
26
+
27
+ it('should allows to create Identifier from hex', function () {
28
+ const identifier = wasm.IdentifierWASM.fromHex('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313')
29
+
30
+ assert.deepEqual(identifier.bytes(), identifierBytes)
31
+ })
32
+
33
+ it('should allows to create Identifier from bytes', function () {
34
+ const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes)
35
+
36
+ assert.deepEqual(identifier.bytes(), identifierBytes)
37
+ })
38
+
39
+ it('should allows to create Identifier from Identifier', function () {
40
+ const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes)
41
+ const identifier2 = new wasm.IdentifierWASM(identifier)
42
+
43
+ assert.deepEqual(identifier2.bytes(), identifierBytes)
44
+ })
45
+
46
+ it('should allows to create Identifier from bytes in constructor', function () {
47
+ const identifier = new wasm.IdentifierWASM(identifierBytes)
48
+
49
+ assert.deepEqual(identifier.bytes(), identifierBytes)
50
+ })
51
+
52
+ it('should allows to create Identifier from base58 in constructor', function () {
53
+ const identifier = new wasm.IdentifierWASM('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
54
+
55
+ assert.deepEqual(identifier.bytes(), identifierBytes)
56
+ })
57
+ })
58
+
59
+ describe('getters', function () {
60
+ it('should allow to get identifier base58', function () {
61
+ const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
62
+
63
+ assert.equal(identifier.base58(), 'ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
64
+ })
65
+
66
+ it('should allow to get identifier base64', function () {
67
+ const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
68
+
69
+ assert.equal(identifier.base64(), 'CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM=')
70
+ })
71
+
72
+ it('should allow to get identifier hex', function () {
73
+ const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
74
+
75
+ assert.equal(identifier.hex(), '092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313')
76
+ })
77
+
78
+ it('should allow to get identifier bytes', function () {
79
+ const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
80
+
81
+ assert.deepEqual(identifier.bytes(), identifierBytes)
82
+ })
83
+ })
84
+ })
@@ -34,7 +34,7 @@ describe('Identity', function () {
34
34
  it('should get id buffer', function () {
35
35
  const identity = new wasm.IdentityWASM(identifier)
36
36
 
37
- assert.deepEqual(Array.from(identity.getId()), identifierBytes)
37
+ assert.deepEqual(identity.getId().bytes(), Uint8Array.from(identifierBytes))
38
38
  })
39
39
 
40
40
  it('should get balance', function () {