pshenmic-dpp 1.1.0-dev.3 → 1.1.0-dev.4
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 +26 -4
- package/dist/wasm/base122.js +2 -3
- package/dist/wasm/index.d.ts +3 -3
- package/dist/wasm/index.js +5 -4
- package/dist/wasm/initAsync.d.ts +6 -0
- package/dist/wasm/initAsync.js +20 -0
- package/dist/wasm/initInterface.d.ts +5 -0
- package/dist/wasm/initInterface.js +45 -0
- package/dist/wasm/initWASM.d.ts +2 -0
- package/dist/wasm/initWASM.js +28 -0
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_zipped.js +1 -0
- package/package.json +16 -10
- package/tests/AssetLockProof.spec.cjs +1 -1
- package/tests/AsyncImportTest.spec.cjs +930 -0
- package/tests/Identifier.spec.cjs +1 -1
package/README.md
CHANGED
|
@@ -18,18 +18,23 @@ ___
|
|
|
18
18
|
### Build JS
|
|
19
19
|
`yarn build:full`
|
|
20
20
|
|
|
21
|
-
**NOTE. If you want to use ES6 module without CJS, you need to run `yarn babel`**
|
|
22
|
-
|
|
23
21
|
### Build with binary instead base122
|
|
24
22
|
`yarn build:raw`
|
|
25
23
|
Now you can import `.js` with base122 buffer for WebAssembly module, or binary which smaller
|
|
26
24
|
___
|
|
27
25
|
## Why you need to use `pshenmic-dpp` instead `wasm-dpp`
|
|
28
26
|
|
|
29
|
-
- `pshenmic-dpp` weighs much less, currently taking up only
|
|
27
|
+
- `pshenmic-dpp` weighs much less, currently taking up only 1.4mb(\*) or 2.2mb(\*) in base122 format with GZIP
|
|
30
28
|
- You can build only necessary modules by removing imports from `lib.rs` before building
|
|
31
29
|
- More accurately replicates `rs-dpp`
|
|
32
30
|
- Some sugar, like enums, which you can pass in string with any case or just use numbers
|
|
31
|
+
|
|
32
|
+
**(\*)** \- This module contains 2 builds for wasm js layer:
|
|
33
|
+
- JS without bundling or GZIP (2.2mb)
|
|
34
|
+
- Bundled JS with GZIP (1.4mb)
|
|
35
|
+
|
|
36
|
+
These variations can be imported depending on requirements.
|
|
37
|
+
In both cases, the binary wasm data will be compressed using gzip.
|
|
33
38
|
___
|
|
34
39
|
|
|
35
40
|
## Current features
|
|
@@ -129,8 +134,9 @@ yarn tests
|
|
|
129
134
|
|
|
130
135
|
## Example
|
|
131
136
|
|
|
137
|
+
This example show how to synchronously import module with size 2.2mb
|
|
132
138
|
```js
|
|
133
|
-
import wasm from pshenmic_dpp';
|
|
139
|
+
import wasm from 'pshenmic_dpp';
|
|
134
140
|
|
|
135
141
|
const document = new wasm.DocumentWASM(
|
|
136
142
|
{
|
|
@@ -169,3 +175,19 @@ st.sign(privKey, pubKey)
|
|
|
169
175
|
console.log(st.toBytes())
|
|
170
176
|
console.log(st.hash(false))
|
|
171
177
|
```
|
|
178
|
+
|
|
179
|
+
This example show how to asynchronously import module with size 1.4mb
|
|
180
|
+
```js
|
|
181
|
+
const {default: initWASM} = require('pshenmic-dpp/initAsync')
|
|
182
|
+
|
|
183
|
+
async function main() {
|
|
184
|
+
let wasm = await initWASM()
|
|
185
|
+
|
|
186
|
+
const dataContractIdentifier = new wasm.IdentifierWASM('6QMfQTdKpC3Y9uWBcTwXeY3KdzRLDqASUsDnQ4MEc9XC')
|
|
187
|
+
const ownerIdentifier = new wasm.IdentifierWASM('B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH')
|
|
188
|
+
|
|
189
|
+
const documentInstance = new wasm.DocumentWASM(document, 'documentTypeName', BigInt(1), dataContractIdentifier, ownerIdentifier)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
main().catch(console.error)
|
|
193
|
+
```
|
package/dist/wasm/base122.js
CHANGED
|
@@ -18,10 +18,9 @@ const kShortened = 0b111 // Uses the illegal index to signify the last two-byte
|
|
|
18
18
|
* with raw data bytes or a string of bytes (i.e. the type of argument to btoa())
|
|
19
19
|
* @returns {Uint8Array} The data in a regular array representing byte values.
|
|
20
20
|
*/
|
|
21
|
-
export function
|
|
21
|
+
export function decode (base122Data) {
|
|
22
22
|
const strData = typeof (base122Data) === 'string' ? base122Data : utf8DataToString(base122Data)
|
|
23
23
|
const decoded = []
|
|
24
|
-
const decodedIndex = 0
|
|
25
24
|
let curByte = 0
|
|
26
25
|
let bitOfByte = 0
|
|
27
26
|
|
|
@@ -47,7 +46,7 @@ export function decodeBase122 (base122Data) {
|
|
|
47
46
|
const illegalIndex = (c >>> 8) & 7 // 7 = 0b111.
|
|
48
47
|
// We have to first check if this is a shortened two-byte character, i.e. if it only
|
|
49
48
|
// encodes <= 7 bits.
|
|
50
|
-
if (illegalIndex
|
|
49
|
+
if (illegalIndex !== kShortened) push7(kIllegals[illegalIndex])
|
|
51
50
|
// Always push the rest.
|
|
52
51
|
push7(c & 127)
|
|
53
52
|
} else {
|
package/dist/wasm/index.d.ts
CHANGED
package/dist/wasm/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as DPP from './pshenmic_dpp.js'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import wasmBytes from './pshenmic_dpp_bg.js'
|
|
3
|
+
import { decode } from './base122.js'
|
|
4
|
+
import { decompressSync } from 'fflate'
|
|
4
5
|
|
|
5
6
|
export * from './base122.js'
|
|
6
7
|
export * from './pshenmic_dpp.js'
|
|
7
8
|
|
|
8
|
-
const bytes = new Uint8Array(
|
|
9
|
+
const bytes = new Uint8Array(decode(wasmBytes))
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
DPP.initSync({ module: decompressSync(bytes) })
|
|
11
12
|
|
|
12
13
|
export default DPP
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import initWASM from './initWASM.js'
|
|
2
|
+
import initWASMInterface from './initInterface.js'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line
|
|
5
|
+
let dpp
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Asynchronously initialization for compressed module (reduced size)
|
|
9
|
+
* @returns {Promise<*>}
|
|
10
|
+
*/
|
|
11
|
+
async function initModule () {
|
|
12
|
+
const wasm = await initWASM()
|
|
13
|
+
const wasmInterface = await initWASMInterface()
|
|
14
|
+
|
|
15
|
+
dpp = wasmInterface.initSync(wasm)
|
|
16
|
+
|
|
17
|
+
return wasmInterface
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default initModule
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import wasmInterfaceBytes from './pshenmic_dpp_zipped.js'
|
|
2
|
+
import { decode } from './base122.js'
|
|
3
|
+
|
|
4
|
+
export * from './base122.js'
|
|
5
|
+
|
|
6
|
+
const isNode = () =>
|
|
7
|
+
typeof process !== 'undefined' &&
|
|
8
|
+
!!process.versions &&
|
|
9
|
+
!!process.versions.node
|
|
10
|
+
|
|
11
|
+
const interfaceBytes = new Uint8Array(decode(wasmInterfaceBytes))
|
|
12
|
+
const interfaceBlob = new Blob([interfaceBytes])
|
|
13
|
+
|
|
14
|
+
async function initInterface () {
|
|
15
|
+
const decompressionStream = new DecompressionStream('gzip')
|
|
16
|
+
const decompressedStream = interfaceBlob.stream().pipeThrough(decompressionStream)
|
|
17
|
+
const decompressedResponse = new Response(decompressedStream)
|
|
18
|
+
const moduleText = await decompressedResponse.text()
|
|
19
|
+
|
|
20
|
+
let module
|
|
21
|
+
if (isNode()) {
|
|
22
|
+
const vm = await import('vm')
|
|
23
|
+
|
|
24
|
+
const context = vm.createContext({
|
|
25
|
+
crypto,
|
|
26
|
+
TextDecoder
|
|
27
|
+
})
|
|
28
|
+
const vmModule = new vm.Script(moduleText)
|
|
29
|
+
|
|
30
|
+
vmModule.runInContext(context)
|
|
31
|
+
|
|
32
|
+
module = context['pshenmic-dpp']
|
|
33
|
+
} else {
|
|
34
|
+
const blob = new Blob([moduleText], { type: 'application/javascript' })
|
|
35
|
+
const moduleUrl = URL.createObjectURL(blob)
|
|
36
|
+
|
|
37
|
+
module = await import(moduleUrl)
|
|
38
|
+
|
|
39
|
+
URL.revokeObjectURL(moduleUrl)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return module
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default initInterface
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import wasmBytes from './pshenmic_dpp_bg.js'
|
|
2
|
+
import { decode } from './base122.js'
|
|
3
|
+
|
|
4
|
+
export * from './base122.js'
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
const isNode = () =>
|
|
8
|
+
typeof process !== 'undefined' &&
|
|
9
|
+
!!process.versions &&
|
|
10
|
+
!!process.versions.node
|
|
11
|
+
|
|
12
|
+
const interfaceBytes = new Uint8Array(decode(wasmBytes))
|
|
13
|
+
const interfaceBlob = new Blob([interfaceBytes])
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Convert wasm bin string to Uint8Array with decompression via DecompressionStream
|
|
17
|
+
* @returns {Promise<ArrayBuffer>}
|
|
18
|
+
*/
|
|
19
|
+
async function initWASM () {
|
|
20
|
+
const decompressionStream = new DecompressionStream('gzip')
|
|
21
|
+
const decompressedStream = interfaceBlob.stream().pipeThrough(decompressionStream)
|
|
22
|
+
const decompressedResponse = new Response(decompressedStream)
|
|
23
|
+
const module = await decompressedResponse.arrayBuffer()
|
|
24
|
+
|
|
25
|
+
return module
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default initWASM
|