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.
- package/.github/workflows/build.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/Cargo.lock +147 -49
- package/Cargo.toml +13 -7
- package/README.md +10 -1
- package/dist/wasm/index.d.ts +52 -0
- package/dist/wasm/pshenmic_dpp.d.ts +962 -0
- package/dist/wasm/pshenmic_dpp.js +3342 -875
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
- package/docs/AssetLockProof.md +107 -0
- package/docs/Building.md +50 -0
- package/docs/ChainLockProof.md +63 -0
- package/docs/CoreScript.md +17 -0
- package/docs/DataContract.md +192 -0
- package/docs/DataContractCreateTransition.md +84 -0
- package/docs/DataContractUpdateTransition.md +84 -0
- package/docs/Document.md +396 -0
- package/docs/DocumentBaseTransition.md +111 -0
- package/docs/DocumentCreateTransition.md +132 -0
- package/docs/DocumentDeleteTransition.md +82 -0
- package/docs/DocumentPurchaseTransition.md +109 -0
- package/docs/DocumentReplaceTransition.md +112 -0
- package/docs/DocumentTransferTransition.md +96 -0
- package/docs/DocumentTransition.md +125 -0
- package/docs/DocumentUpdatePriceTransition.md +109 -0
- package/docs/DocumentsBatch.md +133 -0
- package/docs/Enums.md +103 -0
- package/docs/Home.md +28 -0
- package/docs/Identifier.md +37 -0
- package/docs/Identity.md +140 -0
- package/docs/IdentityCreateTransition.md +155 -0
- package/docs/IdentityCreditTransfer.md +187 -0
- package/docs/IdentityCreditWithdrawalTransition.md +244 -0
- package/docs/IdentityPublicKey.md +348 -0
- package/docs/IdentityPublicKeyInCreation.md +141 -0
- package/docs/IdentityTopUpTransition.md +166 -0
- package/docs/IdentityUpdateTransition.md +234 -0
- package/docs/InstantAssetLockProof.md +117 -0
- package/docs/InstantLock.md +100 -0
- package/docs/OutPoint.md +80 -0
- package/docs/PrefundedVotingBalance.md +48 -0
- package/docs/PrivateKey.md +112 -0
- package/docs/TxOut.md +93 -0
- package/package.json +3 -3
- package/packages/asset_lock_proof/Cargo.toml +19 -0
- package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
- package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
- package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
- package/packages/asset_lock_proof/src/lib.rs +133 -0
- package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
- package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
- package/packages/cbor_conversation/Cargo.toml +1 -1
- package/packages/core_script/Cargo.toml +13 -0
- package/packages/core_script/src/lib.rs +69 -0
- package/packages/data_contract/Cargo.toml +2 -1
- package/packages/data_contract/src/lib.rs +34 -30
- package/packages/data_contract_transitions/Cargo.toml +1 -1
- package/packages/data_contract_transitions/src/create/mod.rs +3 -3
- package/packages/data_contract_transitions/src/update/mod.rs +3 -3
- package/packages/document/Cargo.toml +2 -1
- package/packages/document/src/lib.rs +13 -12
- package/packages/document/src/methods/mod.rs +41 -38
- package/packages/documents_batch/Cargo.toml +2 -1
- package/packages/documents_batch/src/document_base_transition/mod.rs +16 -20
- package/packages/documents_batch/src/document_transition/mod.rs +9 -9
- package/packages/documents_batch/src/lib.rs +23 -16
- package/packages/documents_batch/src/transitions/create/mod.rs +5 -2
- package/packages/documents_batch/src/transitions/transfer/mod.rs +9 -11
- package/packages/enums/Cargo.toml +1 -1
- package/packages/enums/src/batch/batch_enum.rs +2 -2
- package/packages/enums/src/lib.rs +2 -0
- package/packages/enums/src/lock_types/mod.rs +65 -0
- package/packages/enums/src/platform/mod.rs +2 -0
- package/packages/enums/src/withdrawal/mod.rs +72 -0
- package/packages/identifier/Cargo.toml +9 -0
- package/packages/identifier/src/lib.rs +105 -0
- package/packages/identity/Cargo.toml +2 -1
- package/packages/identity/src/lib.rs +13 -18
- package/packages/identity_public_key/Cargo.toml +1 -1
- package/packages/identity_transitions/Cargo.toml +7 -3
- package/packages/identity_transitions/src/create_transition/mod.rs +99 -36
- package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
- package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
- package/packages/identity_transitions/src/lib.rs +6 -1
- package/packages/identity_transitions/src/{create_transition/public_key_in_creation → public_key_in_creation}/mod.rs +67 -20
- package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
- package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
- package/packages/private_key/Cargo.toml +1 -1
- package/packages/state_transition/Cargo.toml +2 -1
- package/packages/state_transition/src/lib.rs +3 -2
- package/packages/utils/Cargo.toml +2 -2
- package/packages/utils/src/lib.rs +0 -3
- package/scripts/build-js.sh +16 -0
- package/scripts/build.sh +5 -1
- package/src/lib.rs +1 -0
- package/tests/AssetLockProof.spec.js +80 -0
- package/tests/ChainLockProof.spec.js +69 -0
- package/tests/CoreScript.spec.js +37 -0
- package/tests/DataContract.spec.js +17 -14
- package/tests/Document.spec.js +14 -8
- package/tests/DocumentBatchTransition.spec.js +11 -11
- package/tests/DocumentTransition.spec.js +4 -4
- package/tests/DocumentsTransitions.spec.js +22 -22
- package/tests/Identifier.spec.js +84 -0
- package/tests/Identity.spec.js +1 -1
- package/tests/IdentityCreateTransition.spec.js +93 -0
- package/tests/IdentityCreditTransferTransition.spec.js +146 -0
- package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
- package/tests/IdentityTopUpTransition.spec.js +131 -0
- package/tests/IdentityUpdateTransition.spec.js +147 -0
- package/tests/InstantLockProof.spec.js +97 -0
- package/tests/OutPoint.spec.js +55 -0
- package/tests/PublicKeyInCreation.spec.js +258 -0
- package/tests/TxOut.spec.js +76 -0
- package/tests/mocks/Locks/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +1 -1
- package/typings/index.d.ts +52 -0
|
@@ -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,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pshenmic-dpp",
|
|
3
|
-
"version": "1.0.
|
|
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"
|
|
@@ -27,6 +28,5 @@
|
|
|
27
28
|
"core-js": "^3.41.0",
|
|
28
29
|
"mocha": "^11.1.0",
|
|
29
30
|
"standard": "^17.1.2"
|
|
30
|
-
}
|
|
31
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
31
|
+
}
|
|
32
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
|
+
}
|