pshenmic-dpp 1.0.23-rc.6 → 1.0.23
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/README.md +4 -13
- package/dist/wasm/base122.d.ts +1 -0
- package/dist/wasm/base122.js +68 -0
- package/dist/wasm/index.d.ts +19 -2
- package/dist/wasm/index.js +7 -9
- package/dist/wasm/pshenmic_dpp.d.ts +427 -29
- package/dist/wasm/pshenmic_dpp.js +5660 -2943
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +164 -24
- package/package.json +4 -3
- package/tests/AssetLockProof.spec.cjs +0 -1
package/README.md
CHANGED
|
@@ -20,13 +20,13 @@ ___
|
|
|
20
20
|
|
|
21
21
|
**NOTE. If you want to use ES6 module without CJS, you need to run `yarn babel`**
|
|
22
22
|
|
|
23
|
-
### Build with binary instead
|
|
23
|
+
### Build with binary instead base122
|
|
24
24
|
`yarn build:raw`
|
|
25
|
-
Now you can import `.js` with
|
|
25
|
+
Now you can import `.js` with base122 buffer for WebAssembly module, or binary which smaller
|
|
26
26
|
___
|
|
27
27
|
## Why you need to use `pshenmic-dpp` instead `wasm-dpp`
|
|
28
28
|
|
|
29
|
-
- `pshenmic-dpp` weighs much less, currently taking up only
|
|
29
|
+
- `pshenmic-dpp` weighs much less, currently taking up only 3.9 mb in base122 format
|
|
30
30
|
- You can build only necessary modules by removing imports from `lib.rs` before building
|
|
31
31
|
- More accurately replicates `rs-dpp`
|
|
32
32
|
- Some sugar, like enums, which you can pass in string with any case or just use numbers
|
|
@@ -130,16 +130,7 @@ yarn tests
|
|
|
130
130
|
## Example
|
|
131
131
|
|
|
132
132
|
```js
|
|
133
|
-
import
|
|
134
|
-
import wasmBytes from "../wasm/pshenmic_dpp_bg"
|
|
135
|
-
|
|
136
|
-
let binaryString = atob(wasmBytes);
|
|
137
|
-
let bytes = new Uint8Array(binaryString.length);
|
|
138
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
139
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
wasm.initSync({module: bytes.buffer})
|
|
133
|
+
import wasm from pshenmic_dpp';
|
|
143
134
|
|
|
144
135
|
const document = new wasm.DocumentWASM(
|
|
145
136
|
{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function decodeBase122 (base122: Uint8Array | string): Uint8Array;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Original code: https://github.com/kevinAlbs/Base122
|
|
2
|
+
|
|
3
|
+
// Provides functions for encoding/decoding data to and from base-122.
|
|
4
|
+
|
|
5
|
+
const kIllegals = [
|
|
6
|
+
0, // null
|
|
7
|
+
10, // newline
|
|
8
|
+
13, // carriage return
|
|
9
|
+
34, // double quote
|
|
10
|
+
38, // ampersand
|
|
11
|
+
92 // backslash
|
|
12
|
+
]
|
|
13
|
+
const kShortened = 0b111 // Uses the illegal index to signify the last two-byte char encodes <= 7 bits.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Decodes base-122 encoded data back to the original data.
|
|
17
|
+
* @param {Uint8Array|String} rawData - The data to be decoded. This can be a Uint8Array
|
|
18
|
+
* with raw data bytes or a string of bytes (i.e. the type of argument to btoa())
|
|
19
|
+
* @returns {Uint8Array} The data in a regular array representing byte values.
|
|
20
|
+
*/
|
|
21
|
+
export function decodeBase122 (base122Data) {
|
|
22
|
+
const strData = typeof (base122Data) === 'string' ? base122Data : utf8DataToString(base122Data)
|
|
23
|
+
const decoded = []
|
|
24
|
+
const decodedIndex = 0
|
|
25
|
+
let curByte = 0
|
|
26
|
+
let bitOfByte = 0
|
|
27
|
+
|
|
28
|
+
function push7 (byte) {
|
|
29
|
+
byte <<= 1
|
|
30
|
+
// Align this byte to offset for current byte.
|
|
31
|
+
curByte |= (byte >>> bitOfByte)
|
|
32
|
+
bitOfByte += 7
|
|
33
|
+
if (bitOfByte >= 8) {
|
|
34
|
+
decoded.push(curByte)
|
|
35
|
+
bitOfByte -= 8
|
|
36
|
+
// Now, take the remainder, left shift by what has been taken.
|
|
37
|
+
curByte = (byte << (7 - bitOfByte)) & 255
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < strData.length; i++) {
|
|
42
|
+
const c = strData.charCodeAt(i)
|
|
43
|
+
// Check if this is a two-byte character.
|
|
44
|
+
if (c > 127) {
|
|
45
|
+
// Note, the charCodeAt will give the codePoint, thus
|
|
46
|
+
// 0b110xxxxx 0b10yyyyyy will give => xxxxxyyyyyy
|
|
47
|
+
const illegalIndex = (c >>> 8) & 7 // 7 = 0b111.
|
|
48
|
+
// We have to first check if this is a shortened two-byte character, i.e. if it only
|
|
49
|
+
// encodes <= 7 bits.
|
|
50
|
+
if (illegalIndex != kShortened) push7(kIllegals[illegalIndex])
|
|
51
|
+
// Always push the rest.
|
|
52
|
+
push7(c & 127)
|
|
53
|
+
} else {
|
|
54
|
+
// One byte characters can be pushed directly.
|
|
55
|
+
push7(c)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return new Uint8Array(decoded)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Converts a sequence of UTF-8 bytes to a string.
|
|
63
|
+
* @param {Uint8Array} data - The UTF-8 data.
|
|
64
|
+
* @returns {String} A string with each character representing a code point.
|
|
65
|
+
*/
|
|
66
|
+
function utf8DataToString (data) {
|
|
67
|
+
return new TextDecoder().decode(data)
|
|
68
|
+
}
|
package/dist/wasm/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import * as DPP from './pshenmic_dpp';
|
|
|
2
2
|
|
|
3
3
|
export * from './pshenmic_dpp'
|
|
4
4
|
|
|
5
|
+
export * from './base122'
|
|
6
|
+
|
|
5
7
|
export default dpp;
|
|
6
8
|
|
|
7
9
|
declare const dpp: DashPlatformProtocolWASM;
|
|
@@ -95,7 +97,22 @@ export class DashPlatformProtocolWASM {
|
|
|
95
97
|
SecurityLevel: typeof DPP.SecurityLevel
|
|
96
98
|
ActionGoalWASM: typeof DPP.ActionGoalWASM
|
|
97
99
|
// METHODS
|
|
98
|
-
cborToObject: typeof DPP.cborToObject
|
|
99
|
-
objectToCbor: typeof DPP.objectToCbor
|
|
100
100
|
initSync: typeof DPP.initSync
|
|
101
|
+
verifyVotePollVoteStateProof: typeof DPP.verifyVotePollVoteStateProof
|
|
102
|
+
verifyContract: typeof DPP.verifyContract
|
|
103
|
+
verifyDocumentsProof: typeof DPP.verifyDocumentsProof
|
|
104
|
+
verifyIdentifierByNonUniquePublicKeyHash: typeof DPP.verifyIdentifierByNonUniquePublicKeyHash
|
|
105
|
+
verifyIdentityBalance: typeof DPP.verifyIdentityBalance
|
|
106
|
+
verifyIdentityByIdentifier: typeof DPP.verifyIdentityByIdentifier
|
|
107
|
+
verifyIdentityByUniqueKeyHash: typeof DPP.verifyIdentityByUniqueKeyHash
|
|
108
|
+
verifyIdentityContractNonce: typeof DPP.verifyIdentityContractNonce
|
|
109
|
+
verifyIdentityKeysByIdentifier: typeof DPP.verifyIdentityKeysByIdentifier
|
|
110
|
+
verifyIdentityNonce: typeof DPP.verifyIdentityNonce
|
|
111
|
+
verifySignatureDigest: typeof DPP.verifySignatureDigest
|
|
112
|
+
verifyEpochsInfo: typeof DPP.verifyEpochsInfo
|
|
113
|
+
verifyTotalCredits: typeof DPP.verifyTotalCredits
|
|
114
|
+
verifyTokenBalancesForIdentities: typeof DPP.verifyTokenBalancesForIdentities
|
|
115
|
+
verifyTokenContractInfo: typeof DPP.verifyTokenContractInfo
|
|
116
|
+
verifyTokenTotalSupply: typeof DPP.verifyTokenTotalSupply
|
|
117
|
+
verifyTokensBalancesForIdentity: typeof DPP.verifyTokensBalancesForIdentity
|
|
101
118
|
}
|
package/dist/wasm/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import * as DPP from './pshenmic_dpp.js'
|
|
2
|
-
import {default as wasmBytes} from
|
|
1
|
+
import * as DPP from './pshenmic_dpp.js'
|
|
2
|
+
import { default as wasmBytes } from './pshenmic_dpp_bg.js'
|
|
3
|
+
import { decodeBase122 } from './base122.js'
|
|
3
4
|
|
|
5
|
+
export * from './base122.js'
|
|
4
6
|
export * from './pshenmic_dpp.js'
|
|
5
7
|
|
|
6
|
-
const
|
|
7
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
8
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
9
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
10
|
-
}
|
|
8
|
+
const bytes = new Uint8Array(decodeBase122(wasmBytes))
|
|
11
9
|
|
|
12
|
-
const dppInstance = DPP.initSync({ module: bytes
|
|
10
|
+
const dppInstance = DPP.initSync({ module: bytes })
|
|
13
11
|
|
|
14
|
-
export default DPP
|
|
12
|
+
export default DPP
|