pshenmic-dpp 1.0.4 → 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 (152) hide show
  1. package/.github/workflows/build.yml +9 -1
  2. package/.github/workflows/publish.yml +9 -1
  3. package/Cargo.lock +222 -76
  4. package/Cargo.toml +28 -19
  5. package/README.md +75 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/index.d.ts +52 -0
  8. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  9. package/dist/wasm/pshenmic_dpp.js +5565 -966
  10. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  11. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  12. package/docs/AssetLockProof.md +107 -0
  13. package/docs/Building.md +50 -0
  14. package/docs/ChainLockProof.md +63 -0
  15. package/docs/CoreScript.md +17 -0
  16. package/docs/DataContract.md +192 -0
  17. package/docs/DataContractCreateTransition.md +84 -0
  18. package/docs/DataContractUpdateTransition.md +84 -0
  19. package/docs/Document.md +396 -0
  20. package/docs/DocumentBaseTransition.md +111 -0
  21. package/docs/DocumentCreateTransition.md +132 -0
  22. package/docs/DocumentDeleteTransition.md +82 -0
  23. package/docs/DocumentPurchaseTransition.md +109 -0
  24. package/docs/DocumentReplaceTransition.md +112 -0
  25. package/docs/DocumentTransferTransition.md +96 -0
  26. package/docs/DocumentTransition.md +125 -0
  27. package/docs/DocumentUpdatePriceTransition.md +109 -0
  28. package/docs/DocumentsBatch.md +133 -0
  29. package/docs/Enums.md +103 -0
  30. package/docs/Home.md +28 -0
  31. package/docs/Identifier.md +37 -0
  32. package/docs/Identity.md +140 -0
  33. package/docs/IdentityCreateTransition.md +155 -0
  34. package/docs/IdentityCreditTransfer.md +187 -0
  35. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  36. package/docs/IdentityPublicKey.md +348 -0
  37. package/docs/IdentityPublicKeyInCreation.md +141 -0
  38. package/docs/IdentityTopUpTransition.md +166 -0
  39. package/docs/IdentityUpdateTransition.md +234 -0
  40. package/docs/InstantAssetLockProof.md +117 -0
  41. package/docs/InstantLock.md +100 -0
  42. package/docs/OutPoint.md +80 -0
  43. package/docs/PrefundedVotingBalance.md +48 -0
  44. package/docs/PrivateKey.md +112 -0
  45. package/docs/TxOut.md +93 -0
  46. package/package.json +15 -8
  47. package/packages/asset_lock_proof/Cargo.toml +19 -0
  48. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  49. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  50. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  51. package/packages/asset_lock_proof/src/lib.rs +133 -0
  52. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  53. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  54. package/packages/cbor_conversation/Cargo.toml +2 -2
  55. package/packages/core_script/Cargo.toml +13 -0
  56. package/packages/core_script/src/lib.rs +69 -0
  57. package/packages/data_contract/Cargo.toml +4 -3
  58. package/packages/data_contract/src/lib.rs +209 -33
  59. package/packages/data_contract_transitions/Cargo.toml +2 -2
  60. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  61. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  62. package/packages/document/Cargo.toml +3 -2
  63. package/packages/document/src/lib.rs +14 -13
  64. package/packages/document/src/methods/mod.rs +373 -2
  65. package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
  66. package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
  67. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  68. package/packages/documents_batch/src/generators.rs +122 -0
  69. package/packages/documents_batch/src/lib.rs +195 -0
  70. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  71. package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
  72. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  73. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  74. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  75. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  76. package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
  77. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  78. package/packages/enums/Cargo.toml +4 -4
  79. package/packages/enums/src/batch/batch_enum.rs +75 -10
  80. package/packages/enums/src/keys/key_type.rs +46 -0
  81. package/packages/enums/src/keys/purpose.rs +55 -0
  82. package/packages/enums/src/keys/security_level.rs +46 -0
  83. package/packages/enums/src/lib.rs +3 -0
  84. package/packages/enums/src/lock_types/mod.rs +65 -0
  85. package/packages/enums/src/network/mod.rs +67 -0
  86. package/packages/enums/src/platform/mod.rs +68 -8
  87. package/packages/enums/src/withdrawal/mod.rs +72 -0
  88. package/packages/identifier/Cargo.toml +9 -0
  89. package/packages/identifier/src/lib.rs +105 -0
  90. package/packages/identity/Cargo.toml +5 -5
  91. package/packages/identity/src/lib.rs +31 -25
  92. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
  93. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  94. package/packages/identity_transitions/Cargo.toml +8 -4
  95. package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
  96. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  97. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  98. package/packages/identity_transitions/src/lib.rs +6 -1
  99. package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
  100. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  101. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  102. package/packages/mock_bls/Cargo.toml +1 -1
  103. package/packages/private_key/Cargo.toml +4 -3
  104. package/packages/private_key/src/lib.rs +44 -6
  105. package/packages/state_transition/Cargo.toml +6 -4
  106. package/packages/state_transition/src/lib.rs +102 -36
  107. package/packages/utils/Cargo.toml +3 -4
  108. package/packages/utils/src/lib.rs +17 -18
  109. package/scripts/build-js.sh +22 -5
  110. package/scripts/build.sh +27 -2
  111. package/src/lib.rs +8 -1
  112. package/tests/AssetLockProof.spec.js +80 -0
  113. package/tests/ChainLockProof.spec.js +69 -0
  114. package/tests/CoreScript.spec.js +37 -0
  115. package/tests/DataContract.spec.js +178 -0
  116. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  117. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  118. package/tests/Document.spec.js +238 -0
  119. package/tests/DocumentBatchTransition.spec.js +109 -0
  120. package/tests/DocumentTransition.spec.js +97 -0
  121. package/tests/DocumentsTransitions.spec.js +705 -0
  122. package/tests/Identifier.spec.js +84 -0
  123. package/tests/Identity.spec.js +113 -0
  124. package/tests/IdentityCreateTransition.spec.js +93 -0
  125. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  126. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  127. package/tests/IdentityPublicKey.spec.js +132 -0
  128. package/tests/IdentityTopUpTransition.spec.js +131 -0
  129. package/tests/IdentityUpdateTransition.spec.js +147 -0
  130. package/tests/InstantLockProof.spec.js +97 -0
  131. package/tests/OutPoint.spec.js +55 -0
  132. package/tests/PrivateKey.spec.js +73 -0
  133. package/tests/PublicKeyInCreation.spec.js +258 -0
  134. package/tests/TxOut.spec.js +76 -0
  135. package/tests/mocks/DataContract/DataContract.json +153 -0
  136. package/tests/mocks/DataContract/index.js +6 -0
  137. package/tests/mocks/Document/DataContract.json +23 -0
  138. package/tests/mocks/Document/document.json +3 -0
  139. package/tests/mocks/Document/document2.json +3 -0
  140. package/tests/mocks/Document/index.js +11 -0
  141. package/tests/mocks/Identity/index.js +7 -0
  142. package/tests/mocks/Locks/index.js +5 -0
  143. package/tests/mocks/PrivateKey/index.js +5 -0
  144. package/tests/mocks/PublicKey/index.js +14 -0
  145. package/tests/utils/hex.js +15 -0
  146. package/tests/utils/wasm.js +14 -0
  147. package/typings/index.d.ts +52 -0
  148. package/packages/document/src/methods/js.rs +0 -260
  149. package/packages/document/src/methods/rust.rs +0 -92
  150. package/packages/document_batch/src/generators.rs +0 -63
  151. package/packages/document_batch/src/lib.rs +0 -228
  152. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
@@ -0,0 +1,48 @@
1
+ # PrefundedVotingBalanceWASM
2
+
3
+ This class allows to create PrefundedVotingBalance instance and interact.
4
+
5
+ `PrefundedVotingBalanceWASM` can be created only via constructor
6
+
7
+ Constructor arguments:
8
+ - `indexName -> String`
9
+ - `credits -> BigInt`
10
+
11
+ ___
12
+ ## Navigation
13
+
14
+ - [Example](#example)
15
+ - [Fields](#fields)
16
+ - [indexName](#indexname)
17
+ - [credits](#credits)
18
+ ___
19
+ ## Example
20
+
21
+ ```js
22
+ new PrefundedVotingBalanceWASM('value', BigInt(9999))
23
+ ```
24
+
25
+ ___
26
+
27
+ ## Fields
28
+ All fields only readable.
29
+
30
+ ### `indexName`
31
+ Contains index name with value for voting in `String`
32
+
33
+ ```js
34
+ const prefundedVotingBalance = new PrefundedVotingBalanceWASM('value', BigInt(9999))
35
+
36
+ prefundedVotingBalance.indexName // -> String
37
+ ```
38
+
39
+ ___
40
+
41
+ ### `credits`
42
+ Contains amount of credits for voting in `BigInt`
43
+
44
+ ```js
45
+ const prefundedVotingBalance = new PrefundedVotingBalanceWASM('value', BigInt(9999))
46
+
47
+ prefundedVotingBalance.credits // -> BigInt
48
+ ```
@@ -0,0 +1,112 @@
1
+ # PrivateKeyWASM
2
+
3
+ This class allows to create PrivateKey instance
4
+
5
+ ___
6
+
7
+ ## Navigation
8
+
9
+ - [Example](#example)
10
+ - [Static methods](#static-mehtods)
11
+ - [fromWIF](#fromwif)
12
+ - [fromBytes](#frombytes)
13
+ - [fromHex](#fromhex)
14
+ - [Getters methods](#getters-methods)
15
+ - [getWIF](#getwif)
16
+ - [getBytes](#getbytes)
17
+ - [getHex](#gethex)
18
+ - [getPublicKeyHash](#getpublickeyhash)
19
+
20
+ ___
21
+
22
+ ## Example
23
+
24
+ ```js
25
+ const pkey = PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
26
+ ```
27
+
28
+ ___
29
+
30
+ ## Static mehtods
31
+
32
+ ### `fromWIF`
33
+
34
+ Allows to create `PrivateKeyWASM` from WIF `String`
35
+
36
+ ```js
37
+ PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
38
+ ```
39
+
40
+ ___
41
+
42
+ ### `fromBytes`
43
+
44
+ Allows to create `PrivateKey` from bytes in `ArrayLike`
45
+
46
+ ```js
47
+ const bytes = [103, 173, 22, 105, 216, 130, 218, 37, 107, 111, 160, 94, 27, 10, 227, 132, 166, 172, 138, 237, 20, 110, 165, 54, 2, 184, 255, 14, 30, 156, 24, 233]
48
+
49
+ PrivateKeyWASM.fromBytes(bytes, 'Mainnet')
50
+ ```
51
+
52
+ ___
53
+
54
+ ### `fromHex`
55
+
56
+ Allows to create `PrivateKey` from bytes in Hex `String`
57
+
58
+ ```js
59
+ const hex = '67ad1669d882da256b6fa05e1b0ae384a6ac8aed146ea53602b8ff0e1e9c18e9'
60
+
61
+ PrivateKeyWASM.fromHex(hex, 'Mainnet')
62
+ ```
63
+
64
+ ___
65
+
66
+ ## Getters methods
67
+
68
+ ### `getWIF`
69
+
70
+ Allows to return PrivateKey WIF in `String`
71
+
72
+ ```js
73
+ const key = PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
74
+
75
+ key.getWIF() // -> WIF String
76
+ ```
77
+
78
+ ___
79
+
80
+ ### `getBytes`
81
+
82
+ Allows to return PrivateKey bytes in `ArrayLike`
83
+
84
+ ```js
85
+ const key = PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
86
+
87
+ key.getBytes() // -> ArrayLike
88
+ ```
89
+
90
+ ___
91
+
92
+ ### `getHex`
93
+
94
+ Allows to return PrivateKey bytes in hex `String`
95
+
96
+ ```js
97
+ const key = PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
98
+
99
+ key.getHex() // -> String
100
+ ```
101
+
102
+ ___
103
+
104
+ ### `getPublicKeyHash`
105
+
106
+ Allows to return PublicKey hash from PrivateKey in `String`
107
+
108
+ ```js
109
+ const key = PrivateKeyWASM.fromWIF('cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn')
110
+
111
+ key.getPublicKeyHash() // -> String
112
+ ```
package/docs/TxOut.md ADDED
@@ -0,0 +1,93 @@
1
+ # TxOutWASM
2
+
3
+ This class allows to create and interact with TxOut struct
4
+
5
+ `TxOutWASM` can be created only via constructor
6
+
7
+ Constructor arguments:
8
+
9
+ - `value -> BigInt`
10
+ - `scriptPublicKey -> String | ArrayLike`
11
+
12
+ ___
13
+
14
+ ## Navigation
15
+
16
+ - [Example](#Example)
17
+ - [Fields](#fields)
18
+ - [value](#value)
19
+ - [scriptPubKeyHex](#scriptpubkeyhex)
20
+ - [scriptPubKeyBytes](#scriptpubkeybytes)
21
+ - [Static](#static)
22
+ - [getScriptPubKeyASM](#getscriptpubkeyasm)
23
+
24
+ ___
25
+
26
+ ### Example
27
+
28
+ ```js
29
+ const out = new TxOutWASM(
30
+ BigInt(100),
31
+ '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'
32
+ )
33
+ ```
34
+
35
+ ___
36
+
37
+ ## Fields
38
+
39
+ All fields are readable and writable.
40
+
41
+ ### `value`
42
+
43
+ Allows to read and write value of TxOut in `BigInt`
44
+
45
+ ```js
46
+ const out = new TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
47
+
48
+ out.value = BigInt(101)
49
+
50
+ out.value // -> BigInt
51
+ ```
52
+
53
+ ___
54
+
55
+ ### `scriptPubKeyHex`
56
+
57
+ Allows to get script public key in HEX `String`
58
+
59
+ ```js
60
+ const out = new TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
61
+
62
+ out.scriptPubKeyHex = '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'
63
+
64
+ out.scriptPubKeyHex // -> String
65
+ ```
66
+
67
+ ___
68
+
69
+ ### `scriptPubKeyBytes`
70
+
71
+ Same as [scriptPubKeyHex](#scriptpubkeyhex) but in bytes
72
+
73
+ ```js
74
+ const out = new TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
75
+
76
+ out.scriptPubKeyBytes = []
77
+
78
+ out.scriptPubKeyBytes // -> Uint8Array
79
+ ```
80
+
81
+ ___
82
+
83
+ ## Static
84
+
85
+ ### `getScriptPubKeyASM`
86
+
87
+ Allows to get script in ASM `String`
88
+
89
+ ```js
90
+ const out = new TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac')
91
+
92
+ out.getScriptPubKeyASM() // -> String
93
+ ```
package/package.json CHANGED
@@ -1,25 +1,32 @@
1
1
  {
2
2
  "name": "pshenmic-dpp",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/wasm/pshenmic_dpp.js",
5
+ "types": "dist/wasm/index.d.ts",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/owl352/pshenmic-dpp"
8
9
  },
9
10
  "scripts": {
10
- "tsc": "tsc",
11
11
  "build:bin": "./scripts/build.sh",
12
12
  "build:js": "./scripts/build-js.sh",
13
13
  "build:full": "./scripts/build.sh && ./scripts/build-js.sh",
14
- "build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh"
14
+ "build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh",
15
+ "babel": "babel dist/wasm --out-dir dist/cjs/wasm",
16
+ "tests": "mocha ./tests/*.spec.js"
15
17
  },
16
18
  "author": "owl352",
17
19
  "license": "ISC",
18
20
  "description": "",
19
21
  "devDependencies": {
20
- "babel": "^6.23.0",
21
- "babel-cli": "^6.26.0",
22
- "typescript": "^5.8.2"
23
- },
24
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
22
+ "@babel/cli": "^7.27.0",
23
+ "@babel/core": "^7.26.10",
24
+ "@babel/plugin-transform-modules-commonjs": "^7.26.3",
25
+ "@babel/plugin-transform-runtime": "^7.26.10",
26
+ "@babel/preset-env": "^7.26.9",
27
+ "@scure/base": "^1.2.4",
28
+ "core-js": "^3.41.0",
29
+ "mocha": "^11.1.0",
30
+ "standard": "^17.1.2"
31
+ }
25
32
  }
@@ -0,0 +1,19 @@
1
+ [package]
2
+ name = "pshenmic_dpp_asset_lock_proof"
3
+ version.workspace = true
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
11
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
+ "state-transition-signing"
13
+ ]}
14
+ pshenmic_dpp_utils = {path = "../utils"}
15
+ pshenmic_dpp_enums = {path = "../enums"}
16
+ js-sys = "0.3.53"
17
+ web-sys = {version = "0.3.77", features = ["console"]}
18
+ serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
19
+ serde = { version = "1.0.197", features = ["derive"] }
@@ -0,0 +1,79 @@
1
+ use crate::outpoint::OutPointWASM;
2
+ use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof;
3
+ use serde::Deserialize;
4
+ use wasm_bindgen::prelude::wasm_bindgen;
5
+ use wasm_bindgen::{JsError, JsValue};
6
+
7
+ #[derive(Deserialize)]
8
+ #[serde(rename_all = "camelCase")]
9
+ struct ChainAssetLockProofParams {
10
+ core_chain_locked_height: u32,
11
+ out_point: Vec<u8>,
12
+ }
13
+
14
+ #[wasm_bindgen(js_name = "ChainAssetLockProofWASM")]
15
+ pub struct ChainAssetLockProofWASM(ChainAssetLockProof);
16
+
17
+ impl From<ChainAssetLockProofWASM> for ChainAssetLockProof {
18
+ fn from(chain_lock: ChainAssetLockProofWASM) -> Self {
19
+ chain_lock.0
20
+ }
21
+ }
22
+
23
+ impl From<ChainAssetLockProof> for ChainAssetLockProofWASM {
24
+ fn from(chain_lock: ChainAssetLockProof) -> Self {
25
+ ChainAssetLockProofWASM(chain_lock)
26
+ }
27
+ }
28
+
29
+ #[wasm_bindgen]
30
+ impl ChainAssetLockProofWASM {
31
+ #[wasm_bindgen(constructor)]
32
+ pub fn new(
33
+ core_chain_locked_height: u32,
34
+ out_point: &OutPointWASM,
35
+ ) -> Result<ChainAssetLockProofWASM, JsValue> {
36
+ Ok(ChainAssetLockProofWASM(ChainAssetLockProof {
37
+ core_chain_locked_height,
38
+ out_point: out_point.clone().into(),
39
+ }))
40
+ }
41
+
42
+ #[wasm_bindgen(js_name = "fromRawObject")]
43
+ pub fn from_raw_value(
44
+ raw_asset_lock_proof: JsValue,
45
+ ) -> Result<ChainAssetLockProofWASM, JsValue> {
46
+ let parameters: ChainAssetLockProofParams =
47
+ serde_wasm_bindgen::from_value(raw_asset_lock_proof)
48
+ .map_err(|err| JsError::from(err))?;
49
+
50
+ let out_point: [u8; 36] = parameters
51
+ .out_point
52
+ .try_into()
53
+ .map_err(|_| JsError::new("outPoint must be a 36 byte array"))?;
54
+
55
+ let rs_proof = ChainAssetLockProof::new(parameters.core_chain_locked_height, out_point);
56
+
57
+ Ok(ChainAssetLockProofWASM(rs_proof))
58
+ }
59
+
60
+ #[wasm_bindgen(setter = "coreChainLockedHeight")]
61
+ pub fn set_core_chain_locked_height(&mut self, core_chain_locked_height: u32) {
62
+ self.0.core_chain_locked_height = core_chain_locked_height;
63
+ }
64
+
65
+ #[wasm_bindgen(setter = "outPoint")]
66
+ pub fn set_out_point(&mut self, outpoint: &OutPointWASM) {
67
+ self.0.out_point = outpoint.clone().into();
68
+ }
69
+
70
+ #[wasm_bindgen(getter = "coreChainLockedHeight")]
71
+ pub fn get_core_chain_locked_height(self) -> u32 {
72
+ self.0.core_chain_locked_height
73
+ }
74
+
75
+ #[wasm_bindgen(getter = "outPoint")]
76
+ pub fn get_out_point(self) -> OutPointWASM {
77
+ self.0.out_point.into()
78
+ }
79
+ }
@@ -0,0 +1,111 @@
1
+ use crate::outpoint::OutPointWASM;
2
+ use dpp::dashcore::bls_sig_utils::BLSSignature;
3
+ use dpp::dashcore::hash_types::CycleHash;
4
+ use dpp::dashcore::hashes::hex::FromHex;
5
+ use dpp::dashcore::secp256k1::hashes::hex::Case::Lower;
6
+ use dpp::dashcore::secp256k1::hashes::hex::DisplayHex;
7
+ use dpp::dashcore::{InstantLock, Txid};
8
+ use std::str::FromStr;
9
+ use wasm_bindgen::JsValue;
10
+ use wasm_bindgen::prelude::wasm_bindgen;
11
+
12
+ #[wasm_bindgen(js_name = "InstantLockWASM")]
13
+ #[derive(Clone)]
14
+ pub struct InstantLockWASM(InstantLock);
15
+
16
+ impl From<InstantLockWASM> for InstantLock {
17
+ fn from(value: InstantLockWASM) -> Self {
18
+ value.0
19
+ }
20
+ }
21
+
22
+ impl From<InstantLock> for InstantLockWASM {
23
+ fn from(value: InstantLock) -> Self {
24
+ InstantLockWASM(value)
25
+ }
26
+ }
27
+
28
+ #[wasm_bindgen]
29
+ impl InstantLockWASM {
30
+ #[wasm_bindgen(constructor)]
31
+ pub fn new(
32
+ version: u8,
33
+ js_inputs: &js_sys::Array,
34
+ txid: String,
35
+ cycle_hash: String,
36
+ bls_signature: String,
37
+ ) -> Result<InstantLockWASM, JsValue> {
38
+ let inputs = OutPointWASM::vec_from_js_value(js_inputs)?;
39
+
40
+ Ok(InstantLockWASM(InstantLock {
41
+ version,
42
+ inputs: inputs.iter().map(|input| input.clone().into()).collect(),
43
+ txid: Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?,
44
+ cyclehash: CycleHash::from_str(&cycle_hash)
45
+ .map_err(|err| JsValue::from(err.to_string()))?,
46
+ signature: BLSSignature::from_hex(&bls_signature)
47
+ .map_err(|err| JsValue::from(err.to_string()))?,
48
+ }))
49
+ }
50
+
51
+ #[wasm_bindgen(getter = "version")]
52
+ pub fn get_version(&self) -> u8 {
53
+ self.0.version
54
+ }
55
+
56
+ #[wasm_bindgen(getter = "inputs")]
57
+ pub fn get_inputs(&self) -> Vec<OutPointWASM> {
58
+ self.0
59
+ .inputs
60
+ .iter()
61
+ .map(|input| input.clone().into())
62
+ .collect()
63
+ }
64
+
65
+ #[wasm_bindgen(getter = "txid")]
66
+ pub fn get_txid(&self) -> String {
67
+ self.0.txid.to_hex()
68
+ }
69
+
70
+ #[wasm_bindgen(getter = "cyclehash")]
71
+ pub fn get_cycle_hash(&self) -> String {
72
+ self.0.cyclehash.to_string()
73
+ }
74
+
75
+ #[wasm_bindgen(getter = "blsSignature")]
76
+ pub fn get_bls_signature(&self) -> String {
77
+ self.0.signature.to_bytes().to_hex_string(Lower)
78
+ }
79
+
80
+ #[wasm_bindgen(setter = "version")]
81
+ pub fn set_version(&mut self, v: u8) {
82
+ self.0.version = v;
83
+ }
84
+
85
+ #[wasm_bindgen(setter = "inputs")]
86
+ pub fn set_inputs(&mut self, inputs: &js_sys::Array) -> Result<(), JsValue> {
87
+ let inputs = OutPointWASM::vec_from_js_value(inputs)?;
88
+ self.0.inputs = inputs.iter().map(|input| input.clone().into()).collect();
89
+ Ok(())
90
+ }
91
+
92
+ #[wasm_bindgen(setter = "txid")]
93
+ pub fn set_txid(&mut self, txid: String) -> Result<(), JsValue> {
94
+ self.0.txid = Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?;
95
+ Ok(())
96
+ }
97
+
98
+ #[wasm_bindgen(setter = "cyclehash")]
99
+ pub fn set_cycle_hash(&mut self, cycle_hash: String) -> Result<(), JsValue> {
100
+ self.0.cyclehash =
101
+ CycleHash::from_str(&cycle_hash).map_err(|err| JsValue::from(err.to_string()))?;
102
+ Ok(())
103
+ }
104
+
105
+ #[wasm_bindgen(setter = "blsSignature")]
106
+ pub fn set_bls_signature(&mut self, bls_signature: String) -> Result<(), JsValue> {
107
+ self.0.signature =
108
+ BLSSignature::from_hex(&bls_signature).map_err(|err| JsValue::from(err.to_string()))?;
109
+ Ok(())
110
+ }
111
+ }
@@ -0,0 +1,115 @@
1
+ mod instant_lock;
2
+
3
+ use crate::instant::instant_lock::InstantLockWASM;
4
+ use crate::outpoint::OutPointWASM;
5
+ use crate::tx_out::TxOutWASM;
6
+ use dpp::dashcore::consensus::deserialize;
7
+ use dpp::dashcore::{InstantLock, Transaction};
8
+ use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof;
9
+ use pshenmic_dpp_utils::WithJsError;
10
+ use serde::{Deserialize, Serialize};
11
+ use wasm_bindgen::JsValue;
12
+ use wasm_bindgen::prelude::wasm_bindgen;
13
+
14
+ #[derive(Deserialize)]
15
+ #[serde(rename_all = "camelCase")]
16
+ struct InstantAssetLockProofRAW {
17
+ instant_lock: Vec<u8>,
18
+ transaction: Vec<u8>,
19
+ output_index: u32,
20
+ }
21
+
22
+ #[wasm_bindgen(js_name = "InstantAssetLockProofWASM")]
23
+ pub struct InstantAssetLockProofWASM(InstantAssetLockProof);
24
+
25
+ impl From<InstantAssetLockProofWASM> for InstantAssetLockProof {
26
+ fn from(proof: InstantAssetLockProofWASM) -> Self {
27
+ proof.0
28
+ }
29
+ }
30
+
31
+ impl From<InstantAssetLockProof> for InstantAssetLockProofWASM {
32
+ fn from(proof: InstantAssetLockProof) -> Self {
33
+ InstantAssetLockProofWASM(proof)
34
+ }
35
+ }
36
+
37
+ #[wasm_bindgen]
38
+ impl InstantAssetLockProofWASM {
39
+ #[wasm_bindgen(constructor)]
40
+ pub fn new(
41
+ instant_lock: Vec<u8>,
42
+ transaction: Vec<u8>,
43
+ output_index: u32,
44
+ ) -> Result<InstantAssetLockProofWASM, JsValue> {
45
+ let instant_lock: InstantLock =
46
+ deserialize(instant_lock.as_slice()).map_err(|err| JsValue::from(err.to_string()))?;
47
+ let transaction: Transaction =
48
+ deserialize(transaction.as_slice()).map_err(|err| JsValue::from(err.to_string()))?;
49
+
50
+ Ok(InstantAssetLockProofWASM(InstantAssetLockProof {
51
+ instant_lock,
52
+ transaction,
53
+ output_index,
54
+ }))
55
+ }
56
+
57
+ #[wasm_bindgen(js_name = "fromObject")]
58
+ pub fn from_object(value: JsValue) -> Result<InstantAssetLockProofWASM, JsValue> {
59
+ let parameters: InstantAssetLockProofRAW =
60
+ serde_wasm_bindgen::from_value(value).map_err(|err| JsValue::from(err.to_string()))?;
61
+
62
+ InstantAssetLockProofWASM::new(
63
+ parameters.instant_lock,
64
+ parameters.transaction,
65
+ parameters.output_index,
66
+ )
67
+ }
68
+
69
+ #[wasm_bindgen(js_name = "toObject")]
70
+ pub fn to_object(&self) -> Result<JsValue, JsValue> {
71
+ let serializer = serde_wasm_bindgen::Serializer::json_compatible();
72
+
73
+ self.0
74
+ .to_object()
75
+ .with_js_error()?
76
+ .serialize(&serializer)
77
+ .map_err(JsValue::from)
78
+ }
79
+
80
+ #[wasm_bindgen(js_name = "getOutput")]
81
+ pub fn get_output(&self) -> Option<TxOutWASM> {
82
+ match self.0.output() {
83
+ Some(output) => Some(output.clone().into()),
84
+ None => None,
85
+ }
86
+ }
87
+
88
+ #[wasm_bindgen(js_name = "getOutPoint")]
89
+ pub fn get_out_point(&self) -> Option<OutPointWASM> {
90
+ match self.0.out_point() {
91
+ Some(output) => Some(output.clone().into()),
92
+ None => None,
93
+ }
94
+ }
95
+
96
+ #[wasm_bindgen(getter = "outputIndex")]
97
+ pub fn get_output_index(&self) -> u32 {
98
+ self.0.output_index()
99
+ }
100
+
101
+ #[wasm_bindgen(getter = "instantLock")]
102
+ pub fn get_instant_lock(&self) -> InstantLockWASM {
103
+ self.0.instant_lock.clone().into()
104
+ }
105
+
106
+ #[wasm_bindgen(setter = "outputIndex")]
107
+ pub fn set_output_index(&mut self, output_index: u32) {
108
+ self.0.output_index = output_index;
109
+ }
110
+
111
+ #[wasm_bindgen(setter = "instantLock")]
112
+ pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWASM) {
113
+ self.0.instant_lock = instant_lock.clone().into();
114
+ }
115
+ }