@icp-sdk/core 4.2.3 → 5.0.0-beta.1
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/lib/cjs/agent/actor.d.ts +203 -0
- package/lib/cjs/agent/actor.d.ts.map +1 -0
- package/lib/cjs/agent/actor.js +341 -0
- package/lib/cjs/agent/actor.js.map +1 -0
- package/lib/cjs/agent/agent/api.d.ts +216 -0
- package/lib/cjs/agent/agent/api.d.ts.map +1 -0
- package/lib/cjs/agent/agent/api.js +39 -0
- package/lib/cjs/agent/agent/api.js.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +51 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +190 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/index.js +1159 -0
- package/lib/cjs/agent/agent/http/index.js.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.js +135 -0
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
- package/lib/cjs/agent/agent/http/types.d.ts +81 -0
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/types.js +43 -0
- package/lib/cjs/agent/agent/http/types.js.map +1 -0
- package/lib/cjs/agent/agent/index.d.ts +3 -0
- package/lib/cjs/agent/agent/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/index.js +19 -0
- package/lib/cjs/agent/agent/index.js.map +1 -0
- package/lib/cjs/agent/auth.d.ts +91 -0
- package/lib/cjs/agent/auth.d.ts.map +1 -0
- package/lib/cjs/agent/auth.js +65 -0
- package/lib/cjs/agent/auth.js.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts +61 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.js +239 -0
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
- package/lib/cjs/agent/cbor.d.ts +26 -0
- package/lib/cjs/agent/cbor.d.ts.map +1 -0
- package/lib/cjs/agent/cbor.js +93 -0
- package/lib/cjs/agent/cbor.js.map +1 -0
- package/lib/cjs/agent/certificate.d.ts +286 -0
- package/lib/cjs/agent/certificate.d.ts.map +1 -0
- package/lib/cjs/agent/certificate.js +762 -0
- package/lib/cjs/agent/certificate.js.map +1 -0
- package/lib/cjs/agent/constants.d.ts +18 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -0
- package/lib/cjs/agent/constants.js +22 -0
- package/lib/cjs/agent/constants.js.map +1 -0
- package/lib/cjs/agent/der.d.ts +34 -0
- package/lib/cjs/agent/der.d.ts.map +1 -0
- package/lib/cjs/agent/der.js +175 -0
- package/lib/cjs/agent/der.js.map +1 -0
- package/lib/cjs/agent/errors.d.ts +386 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -0
- package/lib/cjs/agent/errors.js +745 -0
- package/lib/cjs/agent/errors.js.map +1 -0
- package/lib/cjs/agent/fetch_candid.d.ts +9 -0
- package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
- package/lib/cjs/agent/fetch_candid.js +69 -0
- package/lib/cjs/agent/fetch_candid.js.map +1 -0
- package/lib/cjs/agent/index.d.ts +125 -1
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +142 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +24 -0
- package/lib/cjs/agent/observable.d.ts.map +1 -0
- package/lib/cjs/agent/observable.js +34 -0
- package/lib/cjs/agent/observable.js.map +1 -0
- package/lib/cjs/agent/polling/backoff.d.ts +50 -0
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
- package/lib/cjs/agent/polling/backoff.js +90 -0
- package/lib/cjs/agent/polling/backoff.js.map +1 -0
- package/lib/cjs/agent/polling/index.d.ts +63 -0
- package/lib/cjs/agent/polling/index.d.ts.map +1 -0
- package/lib/cjs/agent/polling/index.js +183 -0
- package/lib/cjs/agent/polling/index.js.map +1 -0
- package/lib/cjs/agent/polling/strategy.d.ts +52 -0
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
- package/lib/cjs/agent/polling/strategy.js +104 -0
- package/lib/cjs/agent/polling/strategy.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +16 -0
- package/lib/cjs/agent/public_key.d.ts.map +1 -0
- package/lib/cjs/agent/public_key.js +52 -0
- package/lib/cjs/agent/public_key.js.map +1 -0
- package/lib/cjs/agent/request_id.d.ts +24 -0
- package/lib/cjs/agent/request_id.d.ts.map +1 -0
- package/lib/cjs/agent/request_id.js +88 -0
- package/lib/cjs/agent/request_id.js.map +1 -0
- package/lib/cjs/agent/subnetStatus/index.d.ts +70 -0
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/subnetStatus/index.js +224 -0
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -0
- package/lib/cjs/agent/utils/bls.d.ts +10 -0
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
- package/lib/cjs/agent/utils/bls.js +20 -0
- package/lib/cjs/agent/utils/bls.js.map +1 -0
- package/lib/cjs/agent/utils/buffer.d.ts +22 -0
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/agent/utils/buffer.js +55 -0
- package/lib/cjs/agent/utils/buffer.js.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.js +148 -0
- package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
- package/lib/cjs/agent/utils/leb.d.ts +3 -0
- package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
- package/lib/cjs/agent/utils/leb.js +17 -0
- package/lib/cjs/agent/utils/leb.js.map +1 -0
- package/lib/cjs/agent/utils/random.d.ts +6 -0
- package/lib/cjs/agent/utils/random.d.ts.map +1 -0
- package/lib/cjs/agent/utils/random.js +29 -0
- package/lib/cjs/agent/utils/random.js.map +1 -0
- package/lib/cjs/agent/utils/readState.d.ts +84 -0
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -0
- package/lib/cjs/agent/utils/readState.js +149 -0
- package/lib/cjs/agent/utils/readState.js.map +1 -0
- package/lib/cjs/candid/candid-core.d.ts +72 -0
- package/lib/cjs/candid/candid-core.d.ts.map +1 -0
- package/lib/cjs/candid/candid-core.js +251 -0
- package/lib/cjs/candid/candid-core.js.map +1 -0
- package/lib/cjs/candid/candid-ui.d.ts +35 -0
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
- package/lib/cjs/candid/candid-ui.js +317 -0
- package/lib/cjs/candid/candid-ui.js.map +1 -0
- package/lib/cjs/candid/idl.d.ts +579 -0
- package/lib/cjs/candid/idl.d.ts.map +1 -0
- package/lib/cjs/candid/idl.js +2228 -0
- package/lib/cjs/candid/idl.js.map +1 -0
- package/lib/cjs/candid/index.d.ts +30 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +52 -1
- package/lib/cjs/candid/index.js.map +1 -1
- package/lib/cjs/candid/types.d.ts +6 -0
- package/lib/cjs/candid/types.d.ts.map +1 -0
- package/lib/cjs/candid/types.js +4 -0
- package/lib/cjs/candid/types.js.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.js +30 -0
- package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +86 -0
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/candid/utils/buffer.js +191 -0
- package/lib/cjs/candid/utils/buffer.js.map +1 -0
- package/lib/cjs/candid/utils/hash.d.ts +7 -0
- package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
- package/lib/cjs/candid/utils/hash.js +33 -0
- package/lib/cjs/candid/utils/hash.js.map +1 -0
- package/lib/cjs/candid/utils/leb128.d.ts +65 -0
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
- package/lib/cjs/candid/utils/leb128.js +228 -0
- package/lib/cjs/candid/utils/leb128.js.map +1 -0
- package/lib/cjs/identity/identity/delegation.d.ts +164 -0
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
- package/lib/cjs/identity/identity/delegation.js +302 -0
- package/lib/cjs/identity/identity/delegation.js.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.js +117 -0
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
- package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ed25519.js +200 -0
- package/lib/cjs/identity/identity/ed25519.js.map +1 -0
- package/lib/cjs/identity/identity/partial.d.ts +34 -0
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
- package/lib/cjs/identity/identity/partial.js +54 -0
- package/lib/cjs/identity/identity/partial.js.map +1 -0
- package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/cjs/identity/identity/webauthn.js +197 -0
- package/lib/cjs/identity/identity/webauthn.js.map +1 -0
- package/lib/cjs/identity/index.d.ts +38 -1
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +44 -1
- package/lib/cjs/identity/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/der.js +165 -0
- package/lib/cjs/identity/secp256k1/der.js.map +1 -0
- package/lib/cjs/identity/secp256k1/index.d.ts +51 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +51 -1
- package/lib/cjs/identity/secp256k1/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/pem.js +75 -0
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/cjs/principal/index.d.ts +18 -1
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +22 -1
- package/lib/cjs/principal/index.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +50 -0
- package/lib/cjs/principal/principal.d.ts.map +1 -0
- package/lib/cjs/principal/principal.js +148 -0
- package/lib/cjs/principal/principal.js.map +1 -0
- package/lib/cjs/principal/utils/base32.d.ts +10 -0
- package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
- package/lib/cjs/principal/utils/base32.js +90 -0
- package/lib/cjs/principal/utils/base32.js.map +1 -0
- package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
- package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/cjs/principal/utils/getCrc.js +53 -0
- package/lib/cjs/principal/utils/getCrc.js.map +1 -0
- package/lib/esm/agent/actor.d.ts +203 -0
- package/lib/esm/agent/actor.d.ts.map +1 -0
- package/lib/esm/agent/actor.js +337 -0
- package/lib/esm/agent/actor.js.map +1 -0
- package/lib/esm/agent/agent/api.d.ts +216 -0
- package/lib/esm/agent/agent/api.d.ts.map +1 -0
- package/lib/esm/agent/agent/api.js +34 -0
- package/lib/esm/agent/agent/api.js.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +48 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +190 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/index.js +1117 -0
- package/lib/esm/agent/agent/http/index.js.map +1 -0
- package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/transforms.js +128 -0
- package/lib/esm/agent/agent/http/transforms.js.map +1 -0
- package/lib/esm/agent/agent/http/types.d.ts +81 -0
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/types.js +39 -0
- package/lib/esm/agent/agent/http/types.js.map +1 -0
- package/lib/esm/agent/agent/index.d.ts +3 -0
- package/lib/esm/agent/agent/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/index.js +3 -0
- package/lib/esm/agent/agent/index.js.map +1 -0
- package/lib/esm/agent/auth.d.ts +91 -0
- package/lib/esm/agent/auth.d.ts.map +1 -0
- package/lib/esm/agent/auth.js +59 -0
- package/lib/esm/agent/auth.js.map +1 -0
- package/lib/esm/agent/canister-env/index.d.ts +111 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +111 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +61 -0
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/canisterStatus/index.js +199 -0
- package/lib/esm/agent/canisterStatus/index.js.map +1 -0
- package/lib/esm/agent/cbor.d.ts +26 -0
- package/lib/esm/agent/cbor.d.ts.map +1 -0
- package/lib/esm/agent/cbor.js +54 -0
- package/lib/esm/agent/cbor.js.map +1 -0
- package/lib/esm/agent/certificate.d.ts +286 -0
- package/lib/esm/agent/certificate.d.ts.map +1 -0
- package/lib/esm/agent/certificate.js +712 -0
- package/lib/esm/agent/certificate.js.map +1 -0
- package/lib/esm/agent/constants.d.ts +18 -0
- package/lib/esm/agent/constants.d.ts.map +1 -0
- package/lib/esm/agent/constants.js +19 -0
- package/lib/esm/agent/constants.js.map +1 -0
- package/lib/esm/agent/der.d.ts +34 -0
- package/lib/esm/agent/der.d.ts.map +1 -0
- package/lib/esm/agent/der.js +166 -0
- package/lib/esm/agent/der.js.map +1 -0
- package/lib/esm/agent/errors.d.ts +386 -0
- package/lib/esm/agent/errors.d.ts.map +1 -0
- package/lib/esm/agent/errors.js +689 -0
- package/lib/esm/agent/errors.js.map +1 -0
- package/lib/esm/agent/fetch_candid.d.ts +9 -0
- package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
- package/lib/esm/agent/fetch_candid.js +33 -0
- package/lib/esm/agent/fetch_candid.js.map +1 -0
- package/lib/esm/agent/index.d.ts +125 -1
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +125 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +24 -0
- package/lib/esm/agent/observable.d.ts.map +1 -0
- package/lib/esm/agent/observable.js +29 -0
- package/lib/esm/agent/observable.js.map +1 -0
- package/lib/esm/agent/polling/backoff.d.ts +50 -0
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
- package/lib/esm/agent/polling/backoff.js +85 -0
- package/lib/esm/agent/polling/backoff.js.map +1 -0
- package/lib/esm/agent/polling/index.d.ts +63 -0
- package/lib/esm/agent/polling/index.d.ts.map +1 -0
- package/lib/esm/agent/polling/index.js +144 -0
- package/lib/esm/agent/polling/index.js.map +1 -0
- package/lib/esm/agent/polling/strategy.d.ts +52 -0
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
- package/lib/esm/agent/polling/strategy.js +94 -0
- package/lib/esm/agent/polling/strategy.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +16 -0
- package/lib/esm/agent/public_key.d.ts.map +1 -0
- package/lib/esm/agent/public_key.js +48 -0
- package/lib/esm/agent/public_key.js.map +1 -0
- package/lib/esm/agent/request_id.d.ts +24 -0
- package/lib/esm/agent/request_id.d.ts.map +1 -0
- package/lib/esm/agent/request_id.js +83 -0
- package/lib/esm/agent/request_id.js.map +1 -0
- package/lib/esm/agent/subnetStatus/index.d.ts +70 -0
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/subnetStatus/index.js +183 -0
- package/lib/esm/agent/subnetStatus/index.js.map +1 -0
- package/lib/esm/agent/utils/bls.d.ts +10 -0
- package/lib/esm/agent/utils/bls.d.ts.map +1 -0
- package/lib/esm/agent/utils/bls.js +17 -0
- package/lib/esm/agent/utils/bls.js.map +1 -0
- package/lib/esm/agent/utils/buffer.d.ts +22 -0
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
- package/lib/esm/agent/utils/buffer.js +50 -0
- package/lib/esm/agent/utils/buffer.js.map +1 -0
- package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableMap.js +144 -0
- package/lib/esm/agent/utils/expirableMap.js.map +1 -0
- package/lib/esm/agent/utils/leb.d.ts +3 -0
- package/lib/esm/agent/utils/leb.d.ts.map +1 -0
- package/lib/esm/agent/utils/leb.js +12 -0
- package/lib/esm/agent/utils/leb.js.map +1 -0
- package/lib/esm/agent/utils/random.d.ts +6 -0
- package/lib/esm/agent/utils/random.d.ts.map +1 -0
- package/lib/esm/agent/utils/random.js +25 -0
- package/lib/esm/agent/utils/random.js.map +1 -0
- package/lib/esm/agent/utils/readState.d.ts +84 -0
- package/lib/esm/agent/utils/readState.d.ts.map +1 -0
- package/lib/esm/agent/utils/readState.js +107 -0
- package/lib/esm/agent/utils/readState.js.map +1 -0
- package/lib/esm/candid/candid-core.d.ts +72 -0
- package/lib/esm/candid/candid-core.d.ts.map +1 -0
- package/lib/esm/candid/candid-core.js +241 -0
- package/lib/esm/candid/candid-core.js.map +1 -0
- package/lib/esm/candid/candid-ui.d.ts +35 -0
- package/lib/esm/candid/candid-ui.d.ts.map +1 -0
- package/lib/esm/candid/candid-ui.js +272 -0
- package/lib/esm/candid/candid-ui.js.map +1 -0
- package/lib/esm/candid/idl.d.ts +579 -0
- package/lib/esm/candid/idl.d.ts.map +1 -0
- package/lib/esm/candid/idl.js +2189 -0
- package/lib/esm/candid/idl.js.map +1 -0
- package/lib/esm/candid/index.d.ts +30 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +29 -1
- package/lib/esm/candid/index.js.map +1 -1
- package/lib/esm/candid/types.d.ts +6 -0
- package/lib/esm/candid/types.d.ts.map +1 -0
- package/lib/esm/candid/types.js +3 -0
- package/lib/esm/candid/types.js.map +1 -0
- package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
- package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/esm/candid/utils/bigint-math.js +26 -0
- package/lib/esm/candid/utils/bigint-math.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +86 -0
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
- package/lib/esm/candid/utils/buffer.js +182 -0
- package/lib/esm/candid/utils/buffer.js.map +1 -0
- package/lib/esm/candid/utils/hash.d.ts +7 -0
- package/lib/esm/candid/utils/hash.d.ts.map +1 -0
- package/lib/esm/candid/utils/hash.js +30 -0
- package/lib/esm/candid/utils/hash.js.map +1 -0
- package/lib/esm/candid/utils/leb128.d.ts +65 -0
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
- package/lib/esm/candid/utils/leb128.js +216 -0
- package/lib/esm/candid/utils/leb128.js.map +1 -0
- package/lib/esm/identity/identity/delegation.d.ts +164 -0
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
- package/lib/esm/identity/identity/delegation.js +294 -0
- package/lib/esm/identity/identity/delegation.js.map +1 -0
- package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/esm/identity/identity/ecdsa.js +112 -0
- package/lib/esm/identity/identity/ecdsa.js.map +1 -0
- package/lib/esm/identity/identity/ed25519.d.ts +67 -0
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/esm/identity/identity/ed25519.js +195 -0
- package/lib/esm/identity/identity/ed25519.js.map +1 -0
- package/lib/esm/identity/identity/partial.d.ts +34 -0
- package/lib/esm/identity/identity/partial.d.ts.map +1 -0
- package/lib/esm/identity/identity/partial.js +50 -0
- package/lib/esm/identity/identity/partial.js.map +1 -0
- package/lib/esm/identity/identity/webauthn.d.ts +51 -0
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/esm/identity/identity/webauthn.js +192 -0
- package/lib/esm/identity/identity/webauthn.js.map +1 -0
- package/lib/esm/identity/index.d.ts +38 -1
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +38 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +33 -0
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/der.js +156 -0
- package/lib/esm/identity/secp256k1/der.js.map +1 -0
- package/lib/esm/identity/secp256k1/index.d.ts +51 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +51 -1
- package/lib/esm/identity/secp256k1/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/pem.js +39 -0
- package/lib/esm/identity/secp256k1/pem.js.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/esm/principal/index.d.ts +18 -1
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +18 -1
- package/lib/esm/principal/index.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +50 -0
- package/lib/esm/principal/principal.d.ts.map +1 -0
- package/lib/esm/principal/principal.js +144 -0
- package/lib/esm/principal/principal.js.map +1 -0
- package/lib/esm/principal/utils/base32.d.ts +10 -0
- package/lib/esm/principal/utils/base32.d.ts.map +1 -0
- package/lib/esm/principal/utils/base32.js +86 -0
- package/lib/esm/principal/utils/base32.js.map +1 -0
- package/lib/esm/principal/utils/getCrc.d.ts +6 -0
- package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/esm/principal/utils/getCrc.js +50 -0
- package/lib/esm/principal/utils/getCrc.js.map +1 -0
- package/package.json +17 -11
- package/src/agent/actor.ts +576 -0
- package/src/agent/agent/api.ts +262 -0
- package/src/agent/agent/http/index.ts +1518 -0
- package/src/agent/agent/http/transforms.ts +158 -0
- package/src/agent/agent/http/types.ts +126 -0
- package/src/agent/agent/index.ts +2 -0
- package/src/agent/auth.ts +147 -0
- package/src/agent/canister-env/index.ts +192 -1
- package/src/agent/canisterStatus/index.ts +267 -0
- package/src/agent/cbor.ts +63 -0
- package/src/agent/certificate.ts +1060 -0
- package/src/agent/constants.ts +24 -0
- package/src/agent/der.ts +170 -0
- package/src/agent/errors.ts +881 -0
- package/src/agent/fetch_candid.ts +37 -0
- package/src/agent/index.ts +131 -1
- package/src/agent/observable.ts +49 -0
- package/src/agent/polling/backoff.ts +130 -0
- package/src/agent/polling/index.ts +250 -0
- package/src/agent/polling/strategy.ts +144 -0
- package/src/agent/public_key.ts +65 -0
- package/src/agent/request_id.ts +92 -0
- package/src/agent/subnetStatus/index.ts +270 -0
- package/src/agent/utils/bls.ts +18 -0
- package/src/agent/utils/buffer.ts +60 -0
- package/src/agent/utils/expirableMap.ts +163 -0
- package/src/agent/utils/leb.ts +14 -0
- package/src/agent/utils/random.ts +30 -0
- package/src/agent/utils/readState.ts +180 -0
- package/src/candid/candid-core.ts +276 -0
- package/src/candid/candid-ui.ts +289 -0
- package/src/candid/idl.ts +2556 -0
- package/src/candid/index.ts +35 -1
- package/src/candid/types.ts +7 -0
- package/src/candid/utils/bigint-math.ts +26 -0
- package/src/candid/utils/buffer.ts +221 -0
- package/src/candid/utils/hash.ts +31 -0
- package/src/candid/utils/leb128.ts +234 -0
- package/src/identity/identity/delegation.ts +411 -0
- package/src/identity/identity/ecdsa.ts +158 -0
- package/src/identity/identity/ed25519.ts +239 -0
- package/src/identity/identity/partial.ts +60 -0
- package/src/identity/identity/webauthn.ts +265 -0
- package/src/identity/index.ts +39 -1
- package/src/identity/secp256k1/der.ts +156 -0
- package/src/identity/secp256k1/index.ts +52 -1
- package/src/identity/secp256k1/pem.ts +40 -0
- package/src/identity/secp256k1/secp256k1.ts +270 -0
- package/src/package.json +4 -0
- package/src/principal/index.ts +19 -1
- package/src/principal/principal.ts +171 -0
- package/src/principal/utils/base32.ts +101 -0
- package/src/principal/utils/getCrc.ts +52 -0
|
@@ -0,0 +1,2189 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { Principal as PrincipalId } from '../principal/index.js';
|
|
4
|
+
import { concat, PipeArrayBuffer as Pipe, uint8ToDataView } from "./utils/buffer.js";
|
|
5
|
+
import { idlLabelToId } from "./utils/hash.js";
|
|
6
|
+
import { lebDecode, lebEncode, readIntLE, readUIntLE, safeRead, safeReadUint8, slebDecode, slebEncode, writeIntLE, writeUIntLE, } from "./utils/leb128.js";
|
|
7
|
+
import { iexp2 } from "./utils/bigint-math.js";
|
|
8
|
+
/**
|
|
9
|
+
* This module provides a combinator library to create serializers/deserializers
|
|
10
|
+
* between JavaScript values and IDL used by canisters on the Internet Computer,
|
|
11
|
+
* as documented at https://github.com/dfinity/candid/blob/119703ba342d2fef6ab4972d2541b9fe36ae8e36/spec/Candid.md
|
|
12
|
+
*/
|
|
13
|
+
var IDLTypeIds;
|
|
14
|
+
(function (IDLTypeIds) {
|
|
15
|
+
IDLTypeIds[IDLTypeIds["Null"] = -1] = "Null";
|
|
16
|
+
IDLTypeIds[IDLTypeIds["Bool"] = -2] = "Bool";
|
|
17
|
+
IDLTypeIds[IDLTypeIds["Nat"] = -3] = "Nat";
|
|
18
|
+
IDLTypeIds[IDLTypeIds["Int"] = -4] = "Int";
|
|
19
|
+
IDLTypeIds[IDLTypeIds["Float32"] = -13] = "Float32";
|
|
20
|
+
IDLTypeIds[IDLTypeIds["Float64"] = -14] = "Float64";
|
|
21
|
+
IDLTypeIds[IDLTypeIds["Text"] = -15] = "Text";
|
|
22
|
+
IDLTypeIds[IDLTypeIds["Reserved"] = -16] = "Reserved";
|
|
23
|
+
IDLTypeIds[IDLTypeIds["Empty"] = -17] = "Empty";
|
|
24
|
+
IDLTypeIds[IDLTypeIds["Opt"] = -18] = "Opt";
|
|
25
|
+
IDLTypeIds[IDLTypeIds["Vector"] = -19] = "Vector";
|
|
26
|
+
IDLTypeIds[IDLTypeIds["Record"] = -20] = "Record";
|
|
27
|
+
IDLTypeIds[IDLTypeIds["Variant"] = -21] = "Variant";
|
|
28
|
+
IDLTypeIds[IDLTypeIds["Func"] = -22] = "Func";
|
|
29
|
+
IDLTypeIds[IDLTypeIds["Service"] = -23] = "Service";
|
|
30
|
+
IDLTypeIds[IDLTypeIds["Principal"] = -24] = "Principal";
|
|
31
|
+
})(IDLTypeIds || (IDLTypeIds = {}));
|
|
32
|
+
const magicNumber = 'DIDL';
|
|
33
|
+
const magicNumberBytes = new TextEncoder().encode(magicNumber);
|
|
34
|
+
const toReadableString_max = 400; // will not display arguments after 400chars. Makes sure 2mb blobs don't get inside the error
|
|
35
|
+
function zipWith(xs, ys, f) {
|
|
36
|
+
return xs.map((x, i) => f(x, ys[i]));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An IDL Type Table, which precedes the data in the stream.
|
|
40
|
+
*/
|
|
41
|
+
class TypeTable {
|
|
42
|
+
constructor() {
|
|
43
|
+
// List of types. Needs to be an array as the index needs to be stable.
|
|
44
|
+
this._typs = [];
|
|
45
|
+
this._idx = new Map();
|
|
46
|
+
this._idxRefCount = new Map();
|
|
47
|
+
}
|
|
48
|
+
has(obj) {
|
|
49
|
+
return this._idx.has(obj.name);
|
|
50
|
+
}
|
|
51
|
+
add(type, buf) {
|
|
52
|
+
const idx = this._typs.length;
|
|
53
|
+
this._idx.set(type.name, idx);
|
|
54
|
+
this._idxRefCount.set(idx, 1);
|
|
55
|
+
this._typs.push(buf);
|
|
56
|
+
}
|
|
57
|
+
merge(obj, knot) {
|
|
58
|
+
const idx = this._idx.get(obj.name);
|
|
59
|
+
const knotIdx = this._idx.get(knot);
|
|
60
|
+
if (idx === undefined) {
|
|
61
|
+
throw new Error('Missing type index for ' + obj);
|
|
62
|
+
}
|
|
63
|
+
if (knotIdx === undefined) {
|
|
64
|
+
throw new Error('Missing type index for ' + knot);
|
|
65
|
+
}
|
|
66
|
+
// Point the recursive placeholder (obj) to the concrete type bytes
|
|
67
|
+
this._typs[idx] = this._typs[knotIdx];
|
|
68
|
+
// Merge mappings so BOTH names point to the same index
|
|
69
|
+
// This avoids losing lookups for the concrete type name (e.g. "opt nat8")
|
|
70
|
+
// which may still be referenced elsewhere in the type table build.
|
|
71
|
+
const idxRefCount = this._getIdxRefCount(idx);
|
|
72
|
+
const knotRefCount = this._getIdxRefCount(knotIdx);
|
|
73
|
+
this._idxRefCount.set(idx, idxRefCount + knotRefCount);
|
|
74
|
+
// Re-point the knot name to the resolved index and mark the old index as unused
|
|
75
|
+
this._idx.set(knot, idx);
|
|
76
|
+
this._idxRefCount.set(knotIdx, 0);
|
|
77
|
+
// Remove unused trailing entries if possible
|
|
78
|
+
this._compactFromEnd();
|
|
79
|
+
}
|
|
80
|
+
_getIdxRefCount(idx) {
|
|
81
|
+
return this._idxRefCount.get(idx) || 0;
|
|
82
|
+
}
|
|
83
|
+
_compactFromEnd() {
|
|
84
|
+
// Remove unused entries from the end of the array
|
|
85
|
+
while (this._typs.length > 0) {
|
|
86
|
+
const lastIndex = this._typs.length - 1;
|
|
87
|
+
if (this._getIdxRefCount(lastIndex) > 0) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
this._typs.pop();
|
|
91
|
+
this._idxRefCount.delete(lastIndex);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
encode() {
|
|
95
|
+
const len = lebEncode(this._typs.length);
|
|
96
|
+
const buf = concat(...this._typs);
|
|
97
|
+
return concat(len, buf);
|
|
98
|
+
}
|
|
99
|
+
indexOf(typeName) {
|
|
100
|
+
if (!this._idx.has(typeName)) {
|
|
101
|
+
throw new Error('Missing type index for ' + typeName);
|
|
102
|
+
}
|
|
103
|
+
return slebEncode(this._idx.get(typeName) || 0);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export class Visitor {
|
|
107
|
+
visitType(_t, _data) {
|
|
108
|
+
throw new Error('Not implemented');
|
|
109
|
+
}
|
|
110
|
+
visitPrimitive(t, data) {
|
|
111
|
+
return this.visitType(t, data);
|
|
112
|
+
}
|
|
113
|
+
visitEmpty(t, data) {
|
|
114
|
+
return this.visitPrimitive(t, data);
|
|
115
|
+
}
|
|
116
|
+
visitBool(t, data) {
|
|
117
|
+
return this.visitPrimitive(t, data);
|
|
118
|
+
}
|
|
119
|
+
visitNull(t, data) {
|
|
120
|
+
return this.visitPrimitive(t, data);
|
|
121
|
+
}
|
|
122
|
+
visitReserved(t, data) {
|
|
123
|
+
return this.visitPrimitive(t, data);
|
|
124
|
+
}
|
|
125
|
+
visitText(t, data) {
|
|
126
|
+
return this.visitPrimitive(t, data);
|
|
127
|
+
}
|
|
128
|
+
visitNumber(t, data) {
|
|
129
|
+
return this.visitPrimitive(t, data);
|
|
130
|
+
}
|
|
131
|
+
visitInt(t, data) {
|
|
132
|
+
return this.visitNumber(t, data);
|
|
133
|
+
}
|
|
134
|
+
visitNat(t, data) {
|
|
135
|
+
return this.visitNumber(t, data);
|
|
136
|
+
}
|
|
137
|
+
visitFloat(t, data) {
|
|
138
|
+
return this.visitPrimitive(t, data);
|
|
139
|
+
}
|
|
140
|
+
visitFixedInt(t, data) {
|
|
141
|
+
return this.visitNumber(t, data);
|
|
142
|
+
}
|
|
143
|
+
visitFixedNat(t, data) {
|
|
144
|
+
return this.visitNumber(t, data);
|
|
145
|
+
}
|
|
146
|
+
visitPrincipal(t, data) {
|
|
147
|
+
return this.visitPrimitive(t, data);
|
|
148
|
+
}
|
|
149
|
+
visitConstruct(t, data) {
|
|
150
|
+
return this.visitType(t, data);
|
|
151
|
+
}
|
|
152
|
+
visitVec(t, _ty, data) {
|
|
153
|
+
return this.visitConstruct(t, data);
|
|
154
|
+
}
|
|
155
|
+
visitOpt(t, _ty, data) {
|
|
156
|
+
return this.visitConstruct(t, data);
|
|
157
|
+
}
|
|
158
|
+
visitRecord(t, _fields, data) {
|
|
159
|
+
return this.visitConstruct(t, data);
|
|
160
|
+
}
|
|
161
|
+
visitTuple(t, components, data) {
|
|
162
|
+
const fields = components.map((ty, i) => [`_${i}_`, ty]);
|
|
163
|
+
return this.visitRecord(t, fields, data);
|
|
164
|
+
}
|
|
165
|
+
visitVariant(t, _fields, data) {
|
|
166
|
+
return this.visitConstruct(t, data);
|
|
167
|
+
}
|
|
168
|
+
visitRec(_t, ty, data) {
|
|
169
|
+
return this.visitConstruct(ty, data);
|
|
170
|
+
}
|
|
171
|
+
visitFunc(t, data) {
|
|
172
|
+
return this.visitConstruct(t, data);
|
|
173
|
+
}
|
|
174
|
+
visitService(t, data) {
|
|
175
|
+
return this.visitConstruct(t, data);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// We try to use hard-to-accidentally-pick names to avoid potential collisions with other types.
|
|
179
|
+
var IdlTypeName;
|
|
180
|
+
(function (IdlTypeName) {
|
|
181
|
+
IdlTypeName["EmptyClass"] = "__IDL_EmptyClass__";
|
|
182
|
+
IdlTypeName["UnknownClass"] = "__IDL_UnknownClass__";
|
|
183
|
+
IdlTypeName["BoolClass"] = "__IDL_BoolClass__";
|
|
184
|
+
IdlTypeName["NullClass"] = "__IDL_NullClass__";
|
|
185
|
+
IdlTypeName["ReservedClass"] = "__IDL_ReservedClass__";
|
|
186
|
+
IdlTypeName["TextClass"] = "__IDL_TextClass__";
|
|
187
|
+
IdlTypeName["IntClass"] = "__IDL_IntClass__";
|
|
188
|
+
IdlTypeName["NatClass"] = "__IDL_NatClass__";
|
|
189
|
+
IdlTypeName["FloatClass"] = "__IDL_FloatClass__";
|
|
190
|
+
IdlTypeName["FixedIntClass"] = "__IDL_FixedIntClass__";
|
|
191
|
+
IdlTypeName["FixedNatClass"] = "__IDL_FixedNatClass__";
|
|
192
|
+
IdlTypeName["VecClass"] = "__IDL_VecClass__";
|
|
193
|
+
IdlTypeName["OptClass"] = "__IDL_OptClass__";
|
|
194
|
+
IdlTypeName["RecordClass"] = "__IDL_RecordClass__";
|
|
195
|
+
IdlTypeName["TupleClass"] = "__IDL_TupleClass__";
|
|
196
|
+
IdlTypeName["VariantClass"] = "__IDL_VariantClass__";
|
|
197
|
+
IdlTypeName["RecClass"] = "__IDL_RecClass__";
|
|
198
|
+
IdlTypeName["PrincipalClass"] = "__IDL_PrincipalClass__";
|
|
199
|
+
IdlTypeName["FuncClass"] = "__IDL_FuncClass__";
|
|
200
|
+
IdlTypeName["ServiceClass"] = "__IDL_ServiceClass__";
|
|
201
|
+
})(IdlTypeName || (IdlTypeName = {}));
|
|
202
|
+
/**
|
|
203
|
+
* Represents an IDL type.
|
|
204
|
+
*/
|
|
205
|
+
export class Type {
|
|
206
|
+
/* Display type name */
|
|
207
|
+
display() {
|
|
208
|
+
return this.name;
|
|
209
|
+
}
|
|
210
|
+
valueToString(x) {
|
|
211
|
+
return toReadableString(x);
|
|
212
|
+
}
|
|
213
|
+
/* Implement `T` in the IDL spec, only needed for non-primitive types */
|
|
214
|
+
buildTypeTable(typeTable) {
|
|
215
|
+
if (!typeTable.has(this)) {
|
|
216
|
+
this._buildTypeTableImpl(typeTable);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export class PrimitiveType extends Type {
|
|
221
|
+
checkType(t) {
|
|
222
|
+
if (this.name !== t.name) {
|
|
223
|
+
throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);
|
|
224
|
+
}
|
|
225
|
+
return t;
|
|
226
|
+
}
|
|
227
|
+
_buildTypeTableImpl(_typeTable) {
|
|
228
|
+
// No type table encoding for Primitive types.
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export class ConstructType extends Type {
|
|
233
|
+
checkType(t) {
|
|
234
|
+
if (t instanceof RecClass) {
|
|
235
|
+
const ty = t.getType();
|
|
236
|
+
if (typeof ty === 'undefined') {
|
|
237
|
+
throw new Error('type mismatch with uninitialized type');
|
|
238
|
+
}
|
|
239
|
+
return ty;
|
|
240
|
+
}
|
|
241
|
+
throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);
|
|
242
|
+
}
|
|
243
|
+
encodeType(typeTable) {
|
|
244
|
+
return typeTable.indexOf(this.name);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Represents an IDL Empty, a type which has no inhabitants.
|
|
249
|
+
* Since no values exist for this type, it cannot be serialised or deserialised.
|
|
250
|
+
* Result types like `Result<Text, Empty>` should always succeed.
|
|
251
|
+
*/
|
|
252
|
+
export class EmptyClass extends PrimitiveType {
|
|
253
|
+
get typeName() {
|
|
254
|
+
return IdlTypeName.EmptyClass;
|
|
255
|
+
}
|
|
256
|
+
static [Symbol.hasInstance](instance) {
|
|
257
|
+
return instance.typeName === IdlTypeName.EmptyClass;
|
|
258
|
+
}
|
|
259
|
+
accept(v, d) {
|
|
260
|
+
return v.visitEmpty(this, d);
|
|
261
|
+
}
|
|
262
|
+
covariant(x) {
|
|
263
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
264
|
+
}
|
|
265
|
+
encodeValue() {
|
|
266
|
+
throw new Error('Empty cannot appear as a function argument');
|
|
267
|
+
}
|
|
268
|
+
valueToString() {
|
|
269
|
+
throw new Error('Empty cannot appear as a value');
|
|
270
|
+
}
|
|
271
|
+
encodeType() {
|
|
272
|
+
return slebEncode(IDLTypeIds.Empty);
|
|
273
|
+
}
|
|
274
|
+
decodeValue() {
|
|
275
|
+
throw new Error('Empty cannot appear as an output');
|
|
276
|
+
}
|
|
277
|
+
get name() {
|
|
278
|
+
return 'empty';
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Represents an IDL Unknown, a placeholder type for deserialization only.
|
|
283
|
+
* When decoding a value as Unknown, all fields will be retained but the names are only available in
|
|
284
|
+
* hashed form.
|
|
285
|
+
* A deserialized unknown will offer it's actual type by calling the `type()` function.
|
|
286
|
+
* Unknown cannot be serialized and attempting to do so will throw an error.
|
|
287
|
+
*/
|
|
288
|
+
export class UnknownClass extends Type {
|
|
289
|
+
get typeName() {
|
|
290
|
+
return IdlTypeName.UnknownClass;
|
|
291
|
+
}
|
|
292
|
+
static [Symbol.hasInstance](instance) {
|
|
293
|
+
return instance.typeName === IdlTypeName.UnknownClass;
|
|
294
|
+
}
|
|
295
|
+
checkType(_t) {
|
|
296
|
+
throw new Error('Method not implemented for unknown.');
|
|
297
|
+
}
|
|
298
|
+
accept(v, d) {
|
|
299
|
+
throw v.visitType(this, d);
|
|
300
|
+
}
|
|
301
|
+
covariant(x) {
|
|
302
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
303
|
+
}
|
|
304
|
+
encodeValue() {
|
|
305
|
+
throw new Error('Unknown cannot appear as a function argument');
|
|
306
|
+
}
|
|
307
|
+
valueToString() {
|
|
308
|
+
throw new Error('Unknown cannot appear as a value');
|
|
309
|
+
}
|
|
310
|
+
encodeType() {
|
|
311
|
+
throw new Error('Unknown cannot be serialized');
|
|
312
|
+
}
|
|
313
|
+
decodeValue(b, t) {
|
|
314
|
+
let decodedValue = t.decodeValue(b, t);
|
|
315
|
+
if (Object(decodedValue) !== decodedValue) {
|
|
316
|
+
// decodedValue is primitive. Box it, otherwise we cannot add the type() function.
|
|
317
|
+
// The type() function is important for primitives because otherwise we cannot tell apart the
|
|
318
|
+
// different number types.
|
|
319
|
+
decodedValue = Object(decodedValue);
|
|
320
|
+
}
|
|
321
|
+
let typeFunc;
|
|
322
|
+
if (t instanceof RecClass) {
|
|
323
|
+
typeFunc = () => t.getType();
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
typeFunc = () => t;
|
|
327
|
+
}
|
|
328
|
+
// Do not use 'decodedValue.type = typeFunc' because this would lead to an enumerable property
|
|
329
|
+
// 'type' which means it would be serialized if the value would be candid encoded again.
|
|
330
|
+
// This in turn leads to problems if the decoded value is a variant because these values are
|
|
331
|
+
// only allowed to have a single property.
|
|
332
|
+
Object.defineProperty(decodedValue, 'type', {
|
|
333
|
+
value: typeFunc,
|
|
334
|
+
writable: true,
|
|
335
|
+
enumerable: false,
|
|
336
|
+
configurable: true,
|
|
337
|
+
});
|
|
338
|
+
return decodedValue;
|
|
339
|
+
}
|
|
340
|
+
_buildTypeTableImpl() {
|
|
341
|
+
throw new Error('Unknown cannot be serialized');
|
|
342
|
+
}
|
|
343
|
+
get name() {
|
|
344
|
+
return 'Unknown';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Represents an IDL Bool
|
|
349
|
+
*/
|
|
350
|
+
export class BoolClass extends PrimitiveType {
|
|
351
|
+
get typeName() {
|
|
352
|
+
return IdlTypeName.BoolClass;
|
|
353
|
+
}
|
|
354
|
+
static [Symbol.hasInstance](instance) {
|
|
355
|
+
return instance.typeName === IdlTypeName.BoolClass;
|
|
356
|
+
}
|
|
357
|
+
accept(v, d) {
|
|
358
|
+
return v.visitBool(this, d);
|
|
359
|
+
}
|
|
360
|
+
covariant(x) {
|
|
361
|
+
if (typeof x === 'boolean')
|
|
362
|
+
return true;
|
|
363
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
364
|
+
}
|
|
365
|
+
encodeValue(x) {
|
|
366
|
+
return new Uint8Array([x ? 1 : 0]);
|
|
367
|
+
}
|
|
368
|
+
encodeType() {
|
|
369
|
+
return slebEncode(IDLTypeIds.Bool);
|
|
370
|
+
}
|
|
371
|
+
decodeValue(b, t) {
|
|
372
|
+
this.checkType(t);
|
|
373
|
+
switch (safeReadUint8(b)) {
|
|
374
|
+
case 0:
|
|
375
|
+
return false;
|
|
376
|
+
case 1:
|
|
377
|
+
return true;
|
|
378
|
+
default:
|
|
379
|
+
throw new Error('Boolean value out of range');
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
get name() {
|
|
383
|
+
return 'bool';
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Represents an IDL Null
|
|
388
|
+
*/
|
|
389
|
+
export class NullClass extends PrimitiveType {
|
|
390
|
+
get typeName() {
|
|
391
|
+
return IdlTypeName.NullClass;
|
|
392
|
+
}
|
|
393
|
+
static [Symbol.hasInstance](instance) {
|
|
394
|
+
return instance.typeName === IdlTypeName.NullClass;
|
|
395
|
+
}
|
|
396
|
+
accept(v, d) {
|
|
397
|
+
return v.visitNull(this, d);
|
|
398
|
+
}
|
|
399
|
+
covariant(x) {
|
|
400
|
+
if (x === null)
|
|
401
|
+
return true;
|
|
402
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
403
|
+
}
|
|
404
|
+
encodeValue() {
|
|
405
|
+
return new Uint8Array(0);
|
|
406
|
+
}
|
|
407
|
+
encodeType() {
|
|
408
|
+
return slebEncode(IDLTypeIds.Null);
|
|
409
|
+
}
|
|
410
|
+
decodeValue(_b, t) {
|
|
411
|
+
this.checkType(t);
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
get name() {
|
|
415
|
+
return 'null';
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Represents an IDL Reserved
|
|
420
|
+
*/
|
|
421
|
+
export class ReservedClass extends PrimitiveType {
|
|
422
|
+
get typeName() {
|
|
423
|
+
return IdlTypeName.ReservedClass;
|
|
424
|
+
}
|
|
425
|
+
static [Symbol.hasInstance](instance) {
|
|
426
|
+
return instance.typeName === IdlTypeName.ReservedClass;
|
|
427
|
+
}
|
|
428
|
+
accept(v, d) {
|
|
429
|
+
return v.visitReserved(this, d);
|
|
430
|
+
}
|
|
431
|
+
covariant(_x) {
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
encodeValue() {
|
|
435
|
+
return new Uint8Array(0);
|
|
436
|
+
}
|
|
437
|
+
encodeType() {
|
|
438
|
+
return slebEncode(IDLTypeIds.Reserved);
|
|
439
|
+
}
|
|
440
|
+
decodeValue(b, t) {
|
|
441
|
+
if (t.name !== this.name) {
|
|
442
|
+
t.decodeValue(b, t);
|
|
443
|
+
}
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
get name() {
|
|
447
|
+
return 'reserved';
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Represents an IDL Text
|
|
452
|
+
*/
|
|
453
|
+
export class TextClass extends PrimitiveType {
|
|
454
|
+
get typeName() {
|
|
455
|
+
return IdlTypeName.TextClass;
|
|
456
|
+
}
|
|
457
|
+
static [Symbol.hasInstance](instance) {
|
|
458
|
+
return instance.typeName === IdlTypeName.TextClass;
|
|
459
|
+
}
|
|
460
|
+
accept(v, d) {
|
|
461
|
+
return v.visitText(this, d);
|
|
462
|
+
}
|
|
463
|
+
covariant(x) {
|
|
464
|
+
if (typeof x === 'string')
|
|
465
|
+
return true;
|
|
466
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
467
|
+
}
|
|
468
|
+
encodeValue(x) {
|
|
469
|
+
const buf = new TextEncoder().encode(x);
|
|
470
|
+
const len = lebEncode(buf.byteLength);
|
|
471
|
+
return concat(len, buf);
|
|
472
|
+
}
|
|
473
|
+
encodeType() {
|
|
474
|
+
return slebEncode(IDLTypeIds.Text);
|
|
475
|
+
}
|
|
476
|
+
decodeValue(b, t) {
|
|
477
|
+
this.checkType(t);
|
|
478
|
+
const len = lebDecode(b);
|
|
479
|
+
const buf = safeRead(b, Number(len));
|
|
480
|
+
const decoder = new TextDecoder('utf8', { fatal: true });
|
|
481
|
+
return decoder.decode(buf);
|
|
482
|
+
}
|
|
483
|
+
get name() {
|
|
484
|
+
return 'text';
|
|
485
|
+
}
|
|
486
|
+
valueToString(x) {
|
|
487
|
+
return '"' + x + '"';
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Represents an IDL Int
|
|
492
|
+
*/
|
|
493
|
+
export class IntClass extends PrimitiveType {
|
|
494
|
+
get typeName() {
|
|
495
|
+
return IdlTypeName.IntClass;
|
|
496
|
+
}
|
|
497
|
+
static [Symbol.hasInstance](instance) {
|
|
498
|
+
return instance.typeName === IdlTypeName.IntClass;
|
|
499
|
+
}
|
|
500
|
+
accept(v, d) {
|
|
501
|
+
return v.visitInt(this, d);
|
|
502
|
+
}
|
|
503
|
+
covariant(x) {
|
|
504
|
+
// We allow encoding of JavaScript plain numbers.
|
|
505
|
+
// But we will always decode to bigint.
|
|
506
|
+
if (typeof x === 'bigint' || Number.isInteger(x))
|
|
507
|
+
return true;
|
|
508
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
509
|
+
}
|
|
510
|
+
encodeValue(x) {
|
|
511
|
+
return slebEncode(x);
|
|
512
|
+
}
|
|
513
|
+
encodeType() {
|
|
514
|
+
return slebEncode(IDLTypeIds.Int);
|
|
515
|
+
}
|
|
516
|
+
decodeValue(b, t) {
|
|
517
|
+
this.checkType(t);
|
|
518
|
+
return slebDecode(b);
|
|
519
|
+
}
|
|
520
|
+
get name() {
|
|
521
|
+
return 'int';
|
|
522
|
+
}
|
|
523
|
+
valueToString(x) {
|
|
524
|
+
return x.toString();
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Represents an IDL Nat
|
|
529
|
+
*/
|
|
530
|
+
export class NatClass extends PrimitiveType {
|
|
531
|
+
get typeName() {
|
|
532
|
+
return IdlTypeName.NatClass;
|
|
533
|
+
}
|
|
534
|
+
static [Symbol.hasInstance](instance) {
|
|
535
|
+
return instance.typeName === IdlTypeName.NatClass;
|
|
536
|
+
}
|
|
537
|
+
accept(v, d) {
|
|
538
|
+
return v.visitNat(this, d);
|
|
539
|
+
}
|
|
540
|
+
covariant(x) {
|
|
541
|
+
// We allow encoding of JavaScript plain numbers.
|
|
542
|
+
// But we will always decode to bigint.
|
|
543
|
+
if ((typeof x === 'bigint' && x >= BigInt(0)) || (Number.isInteger(x) && x >= 0))
|
|
544
|
+
return true;
|
|
545
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
546
|
+
}
|
|
547
|
+
encodeValue(x) {
|
|
548
|
+
return lebEncode(x);
|
|
549
|
+
}
|
|
550
|
+
encodeType() {
|
|
551
|
+
return slebEncode(IDLTypeIds.Nat);
|
|
552
|
+
}
|
|
553
|
+
decodeValue(b, t) {
|
|
554
|
+
this.checkType(t);
|
|
555
|
+
return lebDecode(b);
|
|
556
|
+
}
|
|
557
|
+
get name() {
|
|
558
|
+
return 'nat';
|
|
559
|
+
}
|
|
560
|
+
valueToString(x) {
|
|
561
|
+
return x.toString();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Represents an IDL Float
|
|
566
|
+
*/
|
|
567
|
+
export class FloatClass extends PrimitiveType {
|
|
568
|
+
get typeName() {
|
|
569
|
+
return IdlTypeName.FloatClass;
|
|
570
|
+
}
|
|
571
|
+
static [Symbol.hasInstance](instance) {
|
|
572
|
+
return instance.typeName === IdlTypeName.FloatClass;
|
|
573
|
+
}
|
|
574
|
+
constructor(_bits) {
|
|
575
|
+
super();
|
|
576
|
+
this._bits = _bits;
|
|
577
|
+
if (_bits !== 32 && _bits !== 64) {
|
|
578
|
+
throw new Error('not a valid float type');
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
accept(v, d) {
|
|
582
|
+
return v.visitFloat(this, d);
|
|
583
|
+
}
|
|
584
|
+
covariant(x) {
|
|
585
|
+
if (typeof x === 'number' || x instanceof Number)
|
|
586
|
+
return true;
|
|
587
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
588
|
+
}
|
|
589
|
+
encodeValue(x) {
|
|
590
|
+
const buf = new ArrayBuffer(this._bits / 8);
|
|
591
|
+
const view = new DataView(buf);
|
|
592
|
+
if (this._bits === 32) {
|
|
593
|
+
view.setFloat32(0, x, true);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
view.setFloat64(0, x, true);
|
|
597
|
+
}
|
|
598
|
+
return new Uint8Array(buf);
|
|
599
|
+
}
|
|
600
|
+
encodeType() {
|
|
601
|
+
const opcode = this._bits === 32 ? IDLTypeIds.Float32 : IDLTypeIds.Float64;
|
|
602
|
+
return slebEncode(opcode);
|
|
603
|
+
}
|
|
604
|
+
decodeValue(b, t) {
|
|
605
|
+
this.checkType(t);
|
|
606
|
+
const bytes = safeRead(b, this._bits / 8);
|
|
607
|
+
const view = uint8ToDataView(bytes);
|
|
608
|
+
if (this._bits === 32) {
|
|
609
|
+
return view.getFloat32(0, true);
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
return view.getFloat64(0, true);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
get name() {
|
|
616
|
+
return 'float' + this._bits;
|
|
617
|
+
}
|
|
618
|
+
valueToString(x) {
|
|
619
|
+
return x.toString();
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Represents an IDL fixed-width Int(n)
|
|
624
|
+
*/
|
|
625
|
+
export class FixedIntClass extends PrimitiveType {
|
|
626
|
+
get typeName() {
|
|
627
|
+
return IdlTypeName.FixedIntClass;
|
|
628
|
+
}
|
|
629
|
+
static [Symbol.hasInstance](instance) {
|
|
630
|
+
return instance.typeName === IdlTypeName.FixedIntClass;
|
|
631
|
+
}
|
|
632
|
+
constructor(_bits) {
|
|
633
|
+
super();
|
|
634
|
+
this._bits = _bits;
|
|
635
|
+
}
|
|
636
|
+
accept(v, d) {
|
|
637
|
+
return v.visitFixedInt(this, d);
|
|
638
|
+
}
|
|
639
|
+
covariant(x) {
|
|
640
|
+
const min = iexp2(this._bits - 1) * BigInt(-1);
|
|
641
|
+
const max = iexp2(this._bits - 1) - BigInt(1);
|
|
642
|
+
let ok = false;
|
|
643
|
+
if (typeof x === 'bigint') {
|
|
644
|
+
ok = x >= min && x <= max;
|
|
645
|
+
}
|
|
646
|
+
else if (Number.isInteger(x)) {
|
|
647
|
+
const v = BigInt(x);
|
|
648
|
+
ok = v >= min && v <= max;
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
ok = false;
|
|
652
|
+
}
|
|
653
|
+
if (ok)
|
|
654
|
+
return true;
|
|
655
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
656
|
+
}
|
|
657
|
+
encodeValue(x) {
|
|
658
|
+
return writeIntLE(x, this._bits / 8);
|
|
659
|
+
}
|
|
660
|
+
encodeType() {
|
|
661
|
+
const offset = Math.log2(this._bits) - 3;
|
|
662
|
+
return slebEncode(-9 - offset);
|
|
663
|
+
}
|
|
664
|
+
decodeValue(b, t) {
|
|
665
|
+
this.checkType(t);
|
|
666
|
+
const num = readIntLE(b, this._bits / 8);
|
|
667
|
+
if (this._bits <= 32) {
|
|
668
|
+
return Number(num);
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
return num;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
get name() {
|
|
675
|
+
return `int${this._bits}`;
|
|
676
|
+
}
|
|
677
|
+
valueToString(x) {
|
|
678
|
+
return x.toString();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Represents an IDL fixed-width Nat(n)
|
|
683
|
+
*/
|
|
684
|
+
export class FixedNatClass extends PrimitiveType {
|
|
685
|
+
get typeName() {
|
|
686
|
+
return IdlTypeName.FixedNatClass;
|
|
687
|
+
}
|
|
688
|
+
static [Symbol.hasInstance](instance) {
|
|
689
|
+
return instance.typeName === IdlTypeName.FixedNatClass;
|
|
690
|
+
}
|
|
691
|
+
constructor(_bits) {
|
|
692
|
+
super();
|
|
693
|
+
this._bits = _bits;
|
|
694
|
+
}
|
|
695
|
+
accept(v, d) {
|
|
696
|
+
return v.visitFixedNat(this, d);
|
|
697
|
+
}
|
|
698
|
+
covariant(x) {
|
|
699
|
+
const max = iexp2(this._bits);
|
|
700
|
+
let ok = false;
|
|
701
|
+
if (typeof x === 'bigint' && x >= BigInt(0)) {
|
|
702
|
+
ok = x < max;
|
|
703
|
+
}
|
|
704
|
+
else if (Number.isInteger(x) && x >= 0) {
|
|
705
|
+
const v = BigInt(x);
|
|
706
|
+
ok = v < max;
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
ok = false;
|
|
710
|
+
}
|
|
711
|
+
if (ok)
|
|
712
|
+
return true;
|
|
713
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
714
|
+
}
|
|
715
|
+
encodeValue(x) {
|
|
716
|
+
return writeUIntLE(x, this._bits / 8);
|
|
717
|
+
}
|
|
718
|
+
encodeType() {
|
|
719
|
+
const offset = Math.log2(this._bits) - 3;
|
|
720
|
+
return slebEncode(-5 - offset);
|
|
721
|
+
}
|
|
722
|
+
decodeValue(b, t) {
|
|
723
|
+
this.checkType(t);
|
|
724
|
+
const num = readUIntLE(b, this._bits / 8);
|
|
725
|
+
if (this._bits <= 32) {
|
|
726
|
+
return Number(num);
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
return num;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
get name() {
|
|
733
|
+
return `nat${this._bits}`;
|
|
734
|
+
}
|
|
735
|
+
valueToString(x) {
|
|
736
|
+
return x.toString();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Represents an IDL Array
|
|
741
|
+
*
|
|
742
|
+
* Arrays of fixed-sized nat/int type (e.g. nat8), are encoded from and decoded to TypedArrays (e.g. Uint8Array).
|
|
743
|
+
* Arrays of float or other non-primitive types are encoded/decoded as untyped array in Javascript.
|
|
744
|
+
* @param {Type} t
|
|
745
|
+
*/
|
|
746
|
+
export class VecClass extends ConstructType {
|
|
747
|
+
get typeName() {
|
|
748
|
+
return IdlTypeName.VecClass;
|
|
749
|
+
}
|
|
750
|
+
static [Symbol.hasInstance](instance) {
|
|
751
|
+
return instance.typeName === IdlTypeName.VecClass;
|
|
752
|
+
}
|
|
753
|
+
constructor(_type) {
|
|
754
|
+
super();
|
|
755
|
+
this._type = _type;
|
|
756
|
+
// If true, this vector is really a blob and we can just use memcpy.
|
|
757
|
+
//
|
|
758
|
+
// NOTE:
|
|
759
|
+
// With support of encoding/dencoding of TypedArrays, this optimization is
|
|
760
|
+
// only used when plain array of bytes are passed as encoding input in order
|
|
761
|
+
// to be backward compatible.
|
|
762
|
+
this._blobOptimization = false;
|
|
763
|
+
if (_type instanceof FixedNatClass && _type._bits === 8) {
|
|
764
|
+
this._blobOptimization = true;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
accept(v, d) {
|
|
768
|
+
return v.visitVec(this, this._type, d);
|
|
769
|
+
}
|
|
770
|
+
covariant(x) {
|
|
771
|
+
// Special case for ArrayBuffer
|
|
772
|
+
const bits = this._type instanceof FixedNatClass
|
|
773
|
+
? this._type._bits
|
|
774
|
+
: this._type instanceof FixedIntClass
|
|
775
|
+
? this._type._bits
|
|
776
|
+
: 0;
|
|
777
|
+
if ((ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) ||
|
|
778
|
+
(Array.isArray(x) &&
|
|
779
|
+
x.every((v, idx) => {
|
|
780
|
+
try {
|
|
781
|
+
return this._type.covariant(v);
|
|
782
|
+
}
|
|
783
|
+
catch (e) {
|
|
784
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nindex ${idx} -> ${e.message}`);
|
|
785
|
+
}
|
|
786
|
+
})))
|
|
787
|
+
return true;
|
|
788
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
789
|
+
}
|
|
790
|
+
encodeValue(x) {
|
|
791
|
+
const len = lebEncode(x.length);
|
|
792
|
+
if (this._blobOptimization) {
|
|
793
|
+
return concat(len, new Uint8Array(x));
|
|
794
|
+
}
|
|
795
|
+
if (ArrayBuffer.isView(x)) {
|
|
796
|
+
// Handle TypedArrays with endianness concerns
|
|
797
|
+
if (x instanceof Int16Array || x instanceof Uint16Array) {
|
|
798
|
+
const buffer = new DataView(new ArrayBuffer(x.length * 2));
|
|
799
|
+
for (let i = 0; i < x.length; i++) {
|
|
800
|
+
if (x instanceof Int16Array) {
|
|
801
|
+
buffer.setInt16(i * 2, x[i], true); // true = little-endian
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
buffer.setUint16(i * 2, x[i], true);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return concat(len, new Uint8Array(buffer.buffer));
|
|
808
|
+
}
|
|
809
|
+
else if (x instanceof Int32Array || x instanceof Uint32Array) {
|
|
810
|
+
const buffer = new DataView(new ArrayBuffer(x.length * 4));
|
|
811
|
+
for (let i = 0; i < x.length; i++) {
|
|
812
|
+
if (x instanceof Int32Array) {
|
|
813
|
+
buffer.setInt32(i * 4, x[i], true);
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
buffer.setUint32(i * 4, x[i], true);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return concat(len, new Uint8Array(buffer.buffer));
|
|
820
|
+
}
|
|
821
|
+
else if (x instanceof BigInt64Array || x instanceof BigUint64Array) {
|
|
822
|
+
const buffer = new DataView(new ArrayBuffer(x.length * 8));
|
|
823
|
+
for (let i = 0; i < x.length; i++) {
|
|
824
|
+
if (x instanceof BigInt64Array) {
|
|
825
|
+
buffer.setBigInt64(i * 8, x[i], true);
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
buffer.setBigUint64(i * 8, x[i], true);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return concat(len, new Uint8Array(buffer.buffer));
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
// For Uint8Array, Int8Array, etc. that don't have endianness concerns
|
|
835
|
+
return concat(len, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
const buf = new Pipe(new Uint8Array(len.byteLength + x.length), 0);
|
|
839
|
+
buf.write(len);
|
|
840
|
+
for (const d of x) {
|
|
841
|
+
const encoded = this._type.encodeValue(d);
|
|
842
|
+
buf.write(new Uint8Array(encoded));
|
|
843
|
+
}
|
|
844
|
+
return buf.buffer;
|
|
845
|
+
}
|
|
846
|
+
_buildTypeTableImpl(typeTable) {
|
|
847
|
+
this._type.buildTypeTable(typeTable);
|
|
848
|
+
const opCode = slebEncode(IDLTypeIds.Vector);
|
|
849
|
+
const buffer = this._type.encodeType(typeTable);
|
|
850
|
+
typeTable.add(this, concat(opCode, buffer));
|
|
851
|
+
}
|
|
852
|
+
decodeValue(b, t) {
|
|
853
|
+
const vec = this.checkType(t);
|
|
854
|
+
if (!(vec instanceof VecClass)) {
|
|
855
|
+
throw new Error('Not a vector type');
|
|
856
|
+
}
|
|
857
|
+
const len = Number(lebDecode(b));
|
|
858
|
+
if (this._type instanceof FixedNatClass) {
|
|
859
|
+
if (this._type._bits == 8) {
|
|
860
|
+
return new Uint8Array(b.read(len));
|
|
861
|
+
}
|
|
862
|
+
if (this._type._bits == 16) {
|
|
863
|
+
const bytes = b.read(len * 2);
|
|
864
|
+
// Check if we need to swap bytes for endianness
|
|
865
|
+
const u16 = new Uint16Array(bytes.buffer, bytes.byteOffset, len);
|
|
866
|
+
return u16;
|
|
867
|
+
}
|
|
868
|
+
if (this._type._bits == 32) {
|
|
869
|
+
const bytes = b.read(len * 4);
|
|
870
|
+
const u32 = new Uint32Array(bytes.buffer, bytes.byteOffset, len);
|
|
871
|
+
return u32;
|
|
872
|
+
}
|
|
873
|
+
if (this._type._bits == 64) {
|
|
874
|
+
return new BigUint64Array(b.read(len * 8).buffer);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (this._type instanceof FixedIntClass) {
|
|
878
|
+
if (this._type._bits == 8) {
|
|
879
|
+
return new Int8Array(b.read(len));
|
|
880
|
+
}
|
|
881
|
+
if (this._type._bits == 16) {
|
|
882
|
+
const bytes = b.read(len * 2);
|
|
883
|
+
// Create a DataView to properly handle endianness
|
|
884
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
885
|
+
// Create result array with correct endianness
|
|
886
|
+
const result = new Int16Array(len);
|
|
887
|
+
for (let i = 0; i < len; i++) {
|
|
888
|
+
// Read each value as little-endian (Candid wire format is little-endian)
|
|
889
|
+
result[i] = view.getInt16(i * 2, true);
|
|
890
|
+
}
|
|
891
|
+
return result;
|
|
892
|
+
}
|
|
893
|
+
if (this._type._bits == 32) {
|
|
894
|
+
const bytes = b.read(len * 4);
|
|
895
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
896
|
+
const result = new Int32Array(len);
|
|
897
|
+
for (let i = 0; i < len; i++) {
|
|
898
|
+
result[i] = view.getInt32(i * 4, true);
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
if (this._type._bits == 64) {
|
|
903
|
+
const bytes = b.read(len * 8);
|
|
904
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
905
|
+
const result = new BigInt64Array(len);
|
|
906
|
+
for (let i = 0; i < len; i++) {
|
|
907
|
+
result[i] = view.getBigInt64(i * 8, true);
|
|
908
|
+
}
|
|
909
|
+
return result;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
const rets = [];
|
|
913
|
+
for (let i = 0; i < len; i++) {
|
|
914
|
+
rets.push(this._type.decodeValue(b, vec._type));
|
|
915
|
+
}
|
|
916
|
+
return rets;
|
|
917
|
+
}
|
|
918
|
+
get name() {
|
|
919
|
+
return `vec ${this._type.name}`;
|
|
920
|
+
}
|
|
921
|
+
display() {
|
|
922
|
+
return `vec ${this._type.display()}`;
|
|
923
|
+
}
|
|
924
|
+
valueToString(x) {
|
|
925
|
+
const elements = x.map(e => this._type.valueToString(e));
|
|
926
|
+
return 'vec {' + elements.join('; ') + '}';
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Represents an IDL Option
|
|
931
|
+
* @param {Type} t
|
|
932
|
+
*/
|
|
933
|
+
export class OptClass extends ConstructType {
|
|
934
|
+
get typeName() {
|
|
935
|
+
return IdlTypeName.OptClass;
|
|
936
|
+
}
|
|
937
|
+
static [Symbol.hasInstance](instance) {
|
|
938
|
+
return instance.typeName === IdlTypeName.OptClass;
|
|
939
|
+
}
|
|
940
|
+
constructor(_type) {
|
|
941
|
+
super();
|
|
942
|
+
this._type = _type;
|
|
943
|
+
}
|
|
944
|
+
accept(v, d) {
|
|
945
|
+
return v.visitOpt(this, this._type, d);
|
|
946
|
+
}
|
|
947
|
+
covariant(x) {
|
|
948
|
+
try {
|
|
949
|
+
if (Array.isArray(x) && (x.length === 0 || (x.length === 1 && this._type.covariant(x[0]))))
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
catch (e) {
|
|
953
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)} \n\n-> ${e.message}`);
|
|
954
|
+
}
|
|
955
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
956
|
+
}
|
|
957
|
+
encodeValue(x) {
|
|
958
|
+
if (x.length === 0) {
|
|
959
|
+
return new Uint8Array([0]);
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
return concat(new Uint8Array([1]), this._type.encodeValue(x[0]));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
_buildTypeTableImpl(typeTable) {
|
|
966
|
+
this._type.buildTypeTable(typeTable);
|
|
967
|
+
const opCode = slebEncode(IDLTypeIds.Opt);
|
|
968
|
+
const buffer = this._type.encodeType(typeTable);
|
|
969
|
+
typeTable.add(this, concat(opCode, buffer));
|
|
970
|
+
}
|
|
971
|
+
decodeValue(b, t) {
|
|
972
|
+
if (t instanceof NullClass) {
|
|
973
|
+
return [];
|
|
974
|
+
}
|
|
975
|
+
if (t instanceof ReservedClass) {
|
|
976
|
+
return [];
|
|
977
|
+
}
|
|
978
|
+
let wireType = t;
|
|
979
|
+
// unfold wireType, if needed
|
|
980
|
+
if (t instanceof RecClass) {
|
|
981
|
+
const ty = t.getType();
|
|
982
|
+
if (typeof ty === 'undefined') {
|
|
983
|
+
throw new Error('type mismatch with uninitialized type');
|
|
984
|
+
}
|
|
985
|
+
else
|
|
986
|
+
wireType = ty;
|
|
987
|
+
}
|
|
988
|
+
if (wireType instanceof OptClass) {
|
|
989
|
+
switch (safeReadUint8(b)) {
|
|
990
|
+
case 0:
|
|
991
|
+
return [];
|
|
992
|
+
case 1: {
|
|
993
|
+
// Save the current state of the Pipe `b` to allow rollback in case of an error
|
|
994
|
+
const checkpoint = b.save();
|
|
995
|
+
try {
|
|
996
|
+
// Attempt to decode a value using the `_type` of the current instance
|
|
997
|
+
const v = this._type.decodeValue(b, wireType._type);
|
|
998
|
+
return [v];
|
|
999
|
+
}
|
|
1000
|
+
catch (e) {
|
|
1001
|
+
// If an error occurs during decoding, restore the Pipe `b` to its previous state
|
|
1002
|
+
b.restore(checkpoint);
|
|
1003
|
+
// Skip the value at the current wire type to advance the Pipe `b` position
|
|
1004
|
+
wireType._type.decodeValue(b, wireType._type);
|
|
1005
|
+
// Return an empty array to indicate a `none` value
|
|
1006
|
+
return [];
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
default:
|
|
1010
|
+
throw new Error('Not an option value');
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
else if (
|
|
1014
|
+
// this check corresponds to `not (null <: <t>)` in the spec
|
|
1015
|
+
this._type instanceof NullClass ||
|
|
1016
|
+
this._type instanceof OptClass ||
|
|
1017
|
+
this._type instanceof ReservedClass) {
|
|
1018
|
+
// null <: <t> :
|
|
1019
|
+
// skip value at wire type (to advance b) and return "null", i.e. []
|
|
1020
|
+
wireType.decodeValue(b, wireType);
|
|
1021
|
+
return [];
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
// not (null <: t) :
|
|
1025
|
+
// try constituent type
|
|
1026
|
+
const checkpoint = b.save();
|
|
1027
|
+
try {
|
|
1028
|
+
const v = this._type.decodeValue(b, t);
|
|
1029
|
+
return [v];
|
|
1030
|
+
}
|
|
1031
|
+
catch (e) {
|
|
1032
|
+
// decoding failed, but this is opt, so return "null", i.e. []
|
|
1033
|
+
b.restore(checkpoint);
|
|
1034
|
+
// skip value at wire type (to advance b)
|
|
1035
|
+
wireType.decodeValue(b, t);
|
|
1036
|
+
// return "null"
|
|
1037
|
+
return [];
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
get name() {
|
|
1042
|
+
return `opt ${this._type.name}`;
|
|
1043
|
+
}
|
|
1044
|
+
display() {
|
|
1045
|
+
return `opt ${this._type.display()}`;
|
|
1046
|
+
}
|
|
1047
|
+
valueToString(x) {
|
|
1048
|
+
if (x.length === 0) {
|
|
1049
|
+
return 'null';
|
|
1050
|
+
}
|
|
1051
|
+
else {
|
|
1052
|
+
return `opt ${this._type.valueToString(x[0])}`;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Represents an IDL Record
|
|
1058
|
+
* @param {object} [fields] - mapping of function name to Type
|
|
1059
|
+
*/
|
|
1060
|
+
export class RecordClass extends ConstructType {
|
|
1061
|
+
get typeName() {
|
|
1062
|
+
return IdlTypeName.RecordClass;
|
|
1063
|
+
}
|
|
1064
|
+
static [Symbol.hasInstance](instance) {
|
|
1065
|
+
// TupleClass extends RecordClass, so we need to check both here
|
|
1066
|
+
return (instance.typeName === IdlTypeName.RecordClass || instance.typeName === IdlTypeName.TupleClass);
|
|
1067
|
+
}
|
|
1068
|
+
constructor(fields = {}) {
|
|
1069
|
+
super();
|
|
1070
|
+
this._fields = Object.entries(fields).sort((a, b) => idlLabelToId(a[0]) - idlLabelToId(b[0]));
|
|
1071
|
+
}
|
|
1072
|
+
accept(v, d) {
|
|
1073
|
+
return v.visitRecord(this, this._fields, d);
|
|
1074
|
+
}
|
|
1075
|
+
tryAsTuple() {
|
|
1076
|
+
const res = [];
|
|
1077
|
+
for (let i = 0; i < this._fields.length; i++) {
|
|
1078
|
+
const [key, type] = this._fields[i];
|
|
1079
|
+
if (key !== `_${i}_`) {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1082
|
+
res.push(type);
|
|
1083
|
+
}
|
|
1084
|
+
return res;
|
|
1085
|
+
}
|
|
1086
|
+
covariant(x) {
|
|
1087
|
+
if (typeof x === 'object' &&
|
|
1088
|
+
this._fields.every(([k, t]) => {
|
|
1089
|
+
// eslint-disable-next-line
|
|
1090
|
+
if (!x.hasOwnProperty(k)) {
|
|
1091
|
+
throw new Error(`Record is missing key "${k}".`);
|
|
1092
|
+
}
|
|
1093
|
+
try {
|
|
1094
|
+
return t.covariant(x[k]);
|
|
1095
|
+
}
|
|
1096
|
+
catch (e) {
|
|
1097
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nfield ${k} -> ${e.message}`);
|
|
1098
|
+
}
|
|
1099
|
+
}))
|
|
1100
|
+
return true;
|
|
1101
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1102
|
+
}
|
|
1103
|
+
encodeValue(x) {
|
|
1104
|
+
const values = this._fields.map(([key]) => x[key]);
|
|
1105
|
+
const bufs = zipWith(this._fields, values, ([, c], d) => c.encodeValue(d));
|
|
1106
|
+
return concat(...bufs);
|
|
1107
|
+
}
|
|
1108
|
+
_buildTypeTableImpl(T) {
|
|
1109
|
+
this._fields.forEach(([_, value]) => value.buildTypeTable(T));
|
|
1110
|
+
const opCode = slebEncode(IDLTypeIds.Record);
|
|
1111
|
+
const len = lebEncode(this._fields.length);
|
|
1112
|
+
const fields = this._fields.map(([key, value]) => concat(lebEncode(idlLabelToId(key)), value.encodeType(T)));
|
|
1113
|
+
T.add(this, concat(opCode, len, concat(...fields)));
|
|
1114
|
+
}
|
|
1115
|
+
decodeValue(b, t) {
|
|
1116
|
+
const record = this.checkType(t);
|
|
1117
|
+
if (!(record instanceof RecordClass)) {
|
|
1118
|
+
throw new Error('Not a record type');
|
|
1119
|
+
}
|
|
1120
|
+
const x = {};
|
|
1121
|
+
let expectedRecordIdx = 0;
|
|
1122
|
+
let actualRecordIdx = 0;
|
|
1123
|
+
while (actualRecordIdx < record._fields.length) {
|
|
1124
|
+
const [hash, type] = record._fields[actualRecordIdx];
|
|
1125
|
+
if (expectedRecordIdx >= this._fields.length) {
|
|
1126
|
+
// skip unexpected left over fields present on the wire
|
|
1127
|
+
type.decodeValue(b, type);
|
|
1128
|
+
actualRecordIdx++;
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
const [expectKey, expectType] = this._fields[expectedRecordIdx];
|
|
1132
|
+
const expectedId = idlLabelToId(this._fields[expectedRecordIdx][0]);
|
|
1133
|
+
const actualId = idlLabelToId(hash);
|
|
1134
|
+
if (expectedId === actualId) {
|
|
1135
|
+
// the current field on the wire matches the expected field
|
|
1136
|
+
x[expectKey] = expectType.decodeValue(b, type);
|
|
1137
|
+
expectedRecordIdx++;
|
|
1138
|
+
actualRecordIdx++;
|
|
1139
|
+
}
|
|
1140
|
+
else if (actualId > expectedId) {
|
|
1141
|
+
// The expected field does not exist on the wire
|
|
1142
|
+
if (expectType instanceof OptClass || expectType instanceof ReservedClass) {
|
|
1143
|
+
x[expectKey] = [];
|
|
1144
|
+
expectedRecordIdx++;
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
throw new Error('Cannot find required field ' + expectKey);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
// The field on the wire does not exist in the output type, so we can skip it
|
|
1152
|
+
type.decodeValue(b, type);
|
|
1153
|
+
actualRecordIdx++;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
// initialize left over expected optional fields
|
|
1157
|
+
for (const [expectKey, expectType] of this._fields.slice(expectedRecordIdx)) {
|
|
1158
|
+
if (expectType instanceof OptClass || expectType instanceof ReservedClass) {
|
|
1159
|
+
// TODO this assumes null value in opt is represented as []
|
|
1160
|
+
x[expectKey] = [];
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
throw new Error('Cannot find required field ' + expectKey);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return x;
|
|
1167
|
+
}
|
|
1168
|
+
get fieldsAsObject() {
|
|
1169
|
+
const fields = {};
|
|
1170
|
+
for (const [name, ty] of this._fields) {
|
|
1171
|
+
fields[idlLabelToId(name)] = ty;
|
|
1172
|
+
}
|
|
1173
|
+
return fields;
|
|
1174
|
+
}
|
|
1175
|
+
get name() {
|
|
1176
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.name);
|
|
1177
|
+
return `record {${fields.join('; ')}}`;
|
|
1178
|
+
}
|
|
1179
|
+
display() {
|
|
1180
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.display());
|
|
1181
|
+
return `record {${fields.join('; ')}}`;
|
|
1182
|
+
}
|
|
1183
|
+
valueToString(x) {
|
|
1184
|
+
const values = this._fields.map(([key]) => x[key]);
|
|
1185
|
+
const fields = zipWith(this._fields, values, ([k, c], d) => k + '=' + c.valueToString(d));
|
|
1186
|
+
return `record {${fields.join('; ')}}`;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Represents Tuple, a syntactic sugar for Record.
|
|
1191
|
+
* @param {Type} components
|
|
1192
|
+
*/
|
|
1193
|
+
export class TupleClass extends RecordClass {
|
|
1194
|
+
get typeName() {
|
|
1195
|
+
return IdlTypeName.TupleClass;
|
|
1196
|
+
}
|
|
1197
|
+
static [Symbol.hasInstance](instance) {
|
|
1198
|
+
return instance.typeName === IdlTypeName.TupleClass;
|
|
1199
|
+
}
|
|
1200
|
+
constructor(_components) {
|
|
1201
|
+
const x = {};
|
|
1202
|
+
_components.forEach((e, i) => (x['_' + i + '_'] = e));
|
|
1203
|
+
super(x);
|
|
1204
|
+
this._components = _components;
|
|
1205
|
+
}
|
|
1206
|
+
accept(v, d) {
|
|
1207
|
+
return v.visitTuple(this, this._components, d);
|
|
1208
|
+
}
|
|
1209
|
+
covariant(x) {
|
|
1210
|
+
// `>=` because tuples can be covariant when encoded.
|
|
1211
|
+
if (Array.isArray(x) &&
|
|
1212
|
+
x.length >= this._fields.length &&
|
|
1213
|
+
this._components.every((t, i) => {
|
|
1214
|
+
try {
|
|
1215
|
+
return t.covariant(x[i]);
|
|
1216
|
+
}
|
|
1217
|
+
catch (e) {
|
|
1218
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nindex ${i} -> ${e.message}`);
|
|
1219
|
+
}
|
|
1220
|
+
}))
|
|
1221
|
+
return true;
|
|
1222
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1223
|
+
}
|
|
1224
|
+
encodeValue(x) {
|
|
1225
|
+
const bufs = zipWith(this._components, x, (c, d) => c.encodeValue(d));
|
|
1226
|
+
return concat(...bufs);
|
|
1227
|
+
}
|
|
1228
|
+
decodeValue(b, t) {
|
|
1229
|
+
const tuple = this.checkType(t);
|
|
1230
|
+
if (!(tuple instanceof TupleClass)) {
|
|
1231
|
+
throw new Error('not a tuple type');
|
|
1232
|
+
}
|
|
1233
|
+
if (tuple._components.length < this._components.length) {
|
|
1234
|
+
throw new Error('tuple mismatch');
|
|
1235
|
+
}
|
|
1236
|
+
const res = [];
|
|
1237
|
+
for (const [i, wireType] of tuple._components.entries()) {
|
|
1238
|
+
if (i >= this._components.length) {
|
|
1239
|
+
// skip value
|
|
1240
|
+
wireType.decodeValue(b, wireType);
|
|
1241
|
+
}
|
|
1242
|
+
else {
|
|
1243
|
+
res.push(this._components[i].decodeValue(b, wireType));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return res;
|
|
1247
|
+
}
|
|
1248
|
+
display() {
|
|
1249
|
+
const fields = this._components.map(value => value.display());
|
|
1250
|
+
return `record {${fields.join('; ')}}`;
|
|
1251
|
+
}
|
|
1252
|
+
valueToString(values) {
|
|
1253
|
+
const fields = zipWith(this._components, values, (c, d) => c.valueToString(d));
|
|
1254
|
+
return `record {${fields.join('; ')}}`;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Represents an IDL Variant
|
|
1259
|
+
* @param {object} [fields] - mapping of function name to Type
|
|
1260
|
+
*/
|
|
1261
|
+
export class VariantClass extends ConstructType {
|
|
1262
|
+
get typeName() {
|
|
1263
|
+
return IdlTypeName.VariantClass;
|
|
1264
|
+
}
|
|
1265
|
+
static [Symbol.hasInstance](instance) {
|
|
1266
|
+
return instance.typeName === IdlTypeName.VariantClass;
|
|
1267
|
+
}
|
|
1268
|
+
constructor(fields = {}) {
|
|
1269
|
+
super();
|
|
1270
|
+
this._fields = Object.entries(fields).sort((a, b) => idlLabelToId(a[0]) - idlLabelToId(b[0]));
|
|
1271
|
+
}
|
|
1272
|
+
accept(v, d) {
|
|
1273
|
+
return v.visitVariant(this, this._fields, d);
|
|
1274
|
+
}
|
|
1275
|
+
covariant(x) {
|
|
1276
|
+
if (typeof x === 'object' &&
|
|
1277
|
+
Object.entries(x).length === 1 &&
|
|
1278
|
+
this._fields.every(([k, v]) => {
|
|
1279
|
+
try {
|
|
1280
|
+
// eslint-disable-next-line
|
|
1281
|
+
return !x.hasOwnProperty(k) || v.covariant(x[k]);
|
|
1282
|
+
}
|
|
1283
|
+
catch (e) {
|
|
1284
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nvariant ${k} -> ${e.message}`);
|
|
1285
|
+
}
|
|
1286
|
+
}))
|
|
1287
|
+
return true;
|
|
1288
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1289
|
+
}
|
|
1290
|
+
encodeValue(x) {
|
|
1291
|
+
for (let i = 0; i < this._fields.length; i++) {
|
|
1292
|
+
const [name, type] = this._fields[i];
|
|
1293
|
+
// eslint-disable-next-line
|
|
1294
|
+
if (x.hasOwnProperty(name)) {
|
|
1295
|
+
const idx = lebEncode(i);
|
|
1296
|
+
const buf = type.encodeValue(x[name]);
|
|
1297
|
+
return concat(idx, buf);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
throw Error('Variant has no data: ' + x);
|
|
1301
|
+
}
|
|
1302
|
+
_buildTypeTableImpl(typeTable) {
|
|
1303
|
+
this._fields.forEach(([, type]) => {
|
|
1304
|
+
type.buildTypeTable(typeTable);
|
|
1305
|
+
});
|
|
1306
|
+
const opCode = slebEncode(IDLTypeIds.Variant);
|
|
1307
|
+
const len = lebEncode(this._fields.length);
|
|
1308
|
+
const fields = this._fields.map(([key, value]) => concat(lebEncode(idlLabelToId(key)), value.encodeType(typeTable)));
|
|
1309
|
+
typeTable.add(this, concat(opCode, len, ...fields));
|
|
1310
|
+
}
|
|
1311
|
+
decodeValue(b, t) {
|
|
1312
|
+
const variant = this.checkType(t);
|
|
1313
|
+
if (!(variant instanceof VariantClass)) {
|
|
1314
|
+
throw new Error('Not a variant type');
|
|
1315
|
+
}
|
|
1316
|
+
const idx = Number(lebDecode(b));
|
|
1317
|
+
if (idx >= variant._fields.length) {
|
|
1318
|
+
throw Error('Invalid variant index: ' + idx);
|
|
1319
|
+
}
|
|
1320
|
+
const [wireHash, wireType] = variant._fields[idx];
|
|
1321
|
+
for (const [key, expectType] of this._fields) {
|
|
1322
|
+
if (idlLabelToId(wireHash) === idlLabelToId(key)) {
|
|
1323
|
+
const value = expectType.decodeValue(b, wireType);
|
|
1324
|
+
return { [key]: value };
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
throw new Error('Cannot find field hash ' + wireHash);
|
|
1328
|
+
}
|
|
1329
|
+
get name() {
|
|
1330
|
+
const fields = this._fields.map(([key, type]) => key + ':' + type.name);
|
|
1331
|
+
return `variant {${fields.join('; ')}}`;
|
|
1332
|
+
}
|
|
1333
|
+
display() {
|
|
1334
|
+
const fields = this._fields.map(([key, type]) => key + (type.name === 'null' ? '' : `:${type.display()}`));
|
|
1335
|
+
return `variant {${fields.join('; ')}}`;
|
|
1336
|
+
}
|
|
1337
|
+
valueToString(x) {
|
|
1338
|
+
for (const [name, type] of this._fields) {
|
|
1339
|
+
// eslint-disable-next-line
|
|
1340
|
+
if (x.hasOwnProperty(name)) {
|
|
1341
|
+
const value = type.valueToString(x[name]);
|
|
1342
|
+
if (value === 'null') {
|
|
1343
|
+
return `variant {${name}}`;
|
|
1344
|
+
}
|
|
1345
|
+
else {
|
|
1346
|
+
return `variant {${name}=${value}}`;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
throw new Error('Variant has no data: ' + x);
|
|
1351
|
+
}
|
|
1352
|
+
get alternativesAsObject() {
|
|
1353
|
+
const alternatives = {};
|
|
1354
|
+
for (const [name, ty] of this._fields) {
|
|
1355
|
+
alternatives[idlLabelToId(name)] = ty;
|
|
1356
|
+
}
|
|
1357
|
+
return alternatives;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Represents a reference to an IDL type, used for defining recursive data
|
|
1362
|
+
* types.
|
|
1363
|
+
*/
|
|
1364
|
+
export class RecClass extends ConstructType {
|
|
1365
|
+
constructor() {
|
|
1366
|
+
super(...arguments);
|
|
1367
|
+
this._id = RecClass._counter++;
|
|
1368
|
+
}
|
|
1369
|
+
get typeName() {
|
|
1370
|
+
return IdlTypeName.RecClass;
|
|
1371
|
+
}
|
|
1372
|
+
static { this._counter = 0; }
|
|
1373
|
+
static [Symbol.hasInstance](instance) {
|
|
1374
|
+
return instance.typeName === IdlTypeName.RecClass;
|
|
1375
|
+
}
|
|
1376
|
+
accept(v, d) {
|
|
1377
|
+
if (!this._type) {
|
|
1378
|
+
throw Error('Recursive type uninitialized.');
|
|
1379
|
+
}
|
|
1380
|
+
return v.visitRec(this, this._type, d);
|
|
1381
|
+
}
|
|
1382
|
+
fill(t) {
|
|
1383
|
+
this._type = t;
|
|
1384
|
+
}
|
|
1385
|
+
getType() {
|
|
1386
|
+
return this._type;
|
|
1387
|
+
}
|
|
1388
|
+
covariant(x) {
|
|
1389
|
+
if (this._type ? this._type.covariant(x) : false)
|
|
1390
|
+
return true;
|
|
1391
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1392
|
+
}
|
|
1393
|
+
encodeValue(x) {
|
|
1394
|
+
if (!this._type) {
|
|
1395
|
+
throw Error('Recursive type uninitialized.');
|
|
1396
|
+
}
|
|
1397
|
+
return this._type.encodeValue(x);
|
|
1398
|
+
}
|
|
1399
|
+
_buildTypeTableImpl(typeTable) {
|
|
1400
|
+
if (!this._type) {
|
|
1401
|
+
throw Error('Recursive type uninitialized.');
|
|
1402
|
+
}
|
|
1403
|
+
typeTable.add(this, new Uint8Array([]));
|
|
1404
|
+
this._type.buildTypeTable(typeTable);
|
|
1405
|
+
typeTable.merge(this, this._type.name);
|
|
1406
|
+
}
|
|
1407
|
+
decodeValue(b, t) {
|
|
1408
|
+
if (!this._type) {
|
|
1409
|
+
throw Error('Recursive type uninitialized.');
|
|
1410
|
+
}
|
|
1411
|
+
return this._type.decodeValue(b, t);
|
|
1412
|
+
}
|
|
1413
|
+
get name() {
|
|
1414
|
+
return `rec_${this._id}`;
|
|
1415
|
+
}
|
|
1416
|
+
display() {
|
|
1417
|
+
if (!this._type) {
|
|
1418
|
+
throw Error('Recursive type uninitialized.');
|
|
1419
|
+
}
|
|
1420
|
+
return `μ${this.name}.${this._type.name}`;
|
|
1421
|
+
}
|
|
1422
|
+
valueToString(x) {
|
|
1423
|
+
if (!this._type) {
|
|
1424
|
+
throw Error('Recursive type uninitialized.');
|
|
1425
|
+
}
|
|
1426
|
+
return this._type.valueToString(x);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
function decodePrincipalId(b) {
|
|
1430
|
+
const x = safeReadUint8(b);
|
|
1431
|
+
if (x !== 1) {
|
|
1432
|
+
throw new Error('Cannot decode principal');
|
|
1433
|
+
}
|
|
1434
|
+
const len = Number(lebDecode(b));
|
|
1435
|
+
return PrincipalId.fromUint8Array(new Uint8Array(safeRead(b, len)));
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Represents an IDL principal reference
|
|
1439
|
+
*/
|
|
1440
|
+
export class PrincipalClass extends PrimitiveType {
|
|
1441
|
+
get typeName() {
|
|
1442
|
+
return IdlTypeName.PrincipalClass;
|
|
1443
|
+
}
|
|
1444
|
+
static [Symbol.hasInstance](instance) {
|
|
1445
|
+
return instance.typeName === IdlTypeName.PrincipalClass;
|
|
1446
|
+
}
|
|
1447
|
+
accept(v, d) {
|
|
1448
|
+
return v.visitPrincipal(this, d);
|
|
1449
|
+
}
|
|
1450
|
+
covariant(x) {
|
|
1451
|
+
if (x && x._isPrincipal)
|
|
1452
|
+
return true;
|
|
1453
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1454
|
+
}
|
|
1455
|
+
encodeValue(x) {
|
|
1456
|
+
const buf = x.toUint8Array();
|
|
1457
|
+
const len = lebEncode(buf.byteLength);
|
|
1458
|
+
return concat(new Uint8Array([1]), len, buf);
|
|
1459
|
+
}
|
|
1460
|
+
encodeType() {
|
|
1461
|
+
return slebEncode(IDLTypeIds.Principal);
|
|
1462
|
+
}
|
|
1463
|
+
decodeValue(b, t) {
|
|
1464
|
+
this.checkType(t);
|
|
1465
|
+
return decodePrincipalId(b);
|
|
1466
|
+
}
|
|
1467
|
+
get name() {
|
|
1468
|
+
return 'principal';
|
|
1469
|
+
}
|
|
1470
|
+
valueToString(x) {
|
|
1471
|
+
return `${this.name} "${x.toText()}"`;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Represents an IDL function reference.
|
|
1476
|
+
* @param argTypes Argument types.
|
|
1477
|
+
* @param retTypes Return types.
|
|
1478
|
+
* @param annotations Function annotations.
|
|
1479
|
+
*/
|
|
1480
|
+
export class FuncClass extends ConstructType {
|
|
1481
|
+
get typeName() {
|
|
1482
|
+
return IdlTypeName.FuncClass;
|
|
1483
|
+
}
|
|
1484
|
+
static [Symbol.hasInstance](instance) {
|
|
1485
|
+
return instance.typeName === IdlTypeName.FuncClass;
|
|
1486
|
+
}
|
|
1487
|
+
static argsToString(types, v) {
|
|
1488
|
+
if (types.length !== v.length) {
|
|
1489
|
+
throw new Error('arity mismatch');
|
|
1490
|
+
}
|
|
1491
|
+
return '(' + types.map((t, i) => t.valueToString(v[i])).join(', ') + ')';
|
|
1492
|
+
}
|
|
1493
|
+
constructor(argTypes, retTypes, annotations = []) {
|
|
1494
|
+
super();
|
|
1495
|
+
this.argTypes = argTypes;
|
|
1496
|
+
this.retTypes = retTypes;
|
|
1497
|
+
this.annotations = annotations;
|
|
1498
|
+
}
|
|
1499
|
+
accept(v, d) {
|
|
1500
|
+
return v.visitFunc(this, d);
|
|
1501
|
+
}
|
|
1502
|
+
covariant(x) {
|
|
1503
|
+
if (Array.isArray(x) && x.length === 2 && x[0] && x[0]._isPrincipal && typeof x[1] === 'string')
|
|
1504
|
+
return true;
|
|
1505
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1506
|
+
}
|
|
1507
|
+
encodeValue([principal, methodName]) {
|
|
1508
|
+
const buf = principal.toUint8Array();
|
|
1509
|
+
const len = lebEncode(buf.byteLength);
|
|
1510
|
+
const canister = concat(new Uint8Array([1]), len, buf);
|
|
1511
|
+
const method = new TextEncoder().encode(methodName);
|
|
1512
|
+
const methodLen = lebEncode(method.byteLength);
|
|
1513
|
+
return concat(new Uint8Array([1]), canister, methodLen, method);
|
|
1514
|
+
}
|
|
1515
|
+
_buildTypeTableImpl(T) {
|
|
1516
|
+
this.argTypes.forEach(arg => arg.buildTypeTable(T));
|
|
1517
|
+
this.retTypes.forEach(arg => arg.buildTypeTable(T));
|
|
1518
|
+
const opCode = slebEncode(IDLTypeIds.Func);
|
|
1519
|
+
const argLen = lebEncode(this.argTypes.length);
|
|
1520
|
+
const args = concat(...this.argTypes.map(arg => arg.encodeType(T)));
|
|
1521
|
+
const retLen = lebEncode(this.retTypes.length);
|
|
1522
|
+
const rets = concat(...this.retTypes.map(arg => arg.encodeType(T)));
|
|
1523
|
+
const annLen = lebEncode(this.annotations.length);
|
|
1524
|
+
const anns = concat(...this.annotations.map(a => this.encodeAnnotation(a)));
|
|
1525
|
+
T.add(this, concat(opCode, argLen, args, retLen, rets, annLen, anns));
|
|
1526
|
+
}
|
|
1527
|
+
decodeValue(b, t) {
|
|
1528
|
+
const tt = t instanceof RecClass ? (t.getType() ?? t) : t;
|
|
1529
|
+
if (!subtype(tt, this)) {
|
|
1530
|
+
throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${tt.display()}`);
|
|
1531
|
+
}
|
|
1532
|
+
const x = safeReadUint8(b);
|
|
1533
|
+
if (x !== 1) {
|
|
1534
|
+
throw new Error('Cannot decode function reference');
|
|
1535
|
+
}
|
|
1536
|
+
const canister = decodePrincipalId(b);
|
|
1537
|
+
const mLen = Number(lebDecode(b));
|
|
1538
|
+
const buf = safeRead(b, mLen);
|
|
1539
|
+
const decoder = new TextDecoder('utf8', { fatal: true });
|
|
1540
|
+
const method = decoder.decode(buf);
|
|
1541
|
+
return [canister, method];
|
|
1542
|
+
}
|
|
1543
|
+
get name() {
|
|
1544
|
+
const args = this.argTypes.map(arg => arg.name).join(', ');
|
|
1545
|
+
const rets = this.retTypes.map(arg => arg.name).join(', ');
|
|
1546
|
+
const annon = ' ' + this.annotations.join(' ');
|
|
1547
|
+
return `(${args}) -> (${rets})${annon}`;
|
|
1548
|
+
}
|
|
1549
|
+
valueToString([principal, str]) {
|
|
1550
|
+
return `func "${principal.toText()}".${str}`;
|
|
1551
|
+
}
|
|
1552
|
+
display() {
|
|
1553
|
+
const args = this.argTypes.map(arg => arg.display()).join(', ');
|
|
1554
|
+
const rets = this.retTypes.map(arg => arg.display()).join(', ');
|
|
1555
|
+
const annon = ' ' + this.annotations.join(' ');
|
|
1556
|
+
return `(${args}) → (${rets})${annon}`;
|
|
1557
|
+
}
|
|
1558
|
+
encodeAnnotation(ann) {
|
|
1559
|
+
if (ann === 'query') {
|
|
1560
|
+
return new Uint8Array([1]);
|
|
1561
|
+
}
|
|
1562
|
+
else if (ann === 'oneway') {
|
|
1563
|
+
return new Uint8Array([2]);
|
|
1564
|
+
}
|
|
1565
|
+
else if (ann === 'composite_query') {
|
|
1566
|
+
return new Uint8Array([3]);
|
|
1567
|
+
}
|
|
1568
|
+
else {
|
|
1569
|
+
throw new Error('Illegal function annotation');
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
export class ServiceClass extends ConstructType {
|
|
1574
|
+
get typeName() {
|
|
1575
|
+
return IdlTypeName.ServiceClass;
|
|
1576
|
+
}
|
|
1577
|
+
static [Symbol.hasInstance](instance) {
|
|
1578
|
+
return instance.typeName === IdlTypeName.ServiceClass;
|
|
1579
|
+
}
|
|
1580
|
+
constructor(fields) {
|
|
1581
|
+
super();
|
|
1582
|
+
this._fields = Object.entries(fields).sort((a, b) => {
|
|
1583
|
+
if (a[0] < b[0]) {
|
|
1584
|
+
return -1;
|
|
1585
|
+
}
|
|
1586
|
+
if (a[0] > b[0]) {
|
|
1587
|
+
return 1;
|
|
1588
|
+
}
|
|
1589
|
+
return 0;
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
accept(v, d) {
|
|
1593
|
+
return v.visitService(this, d);
|
|
1594
|
+
}
|
|
1595
|
+
covariant(x) {
|
|
1596
|
+
if (x && x._isPrincipal)
|
|
1597
|
+
return true;
|
|
1598
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1599
|
+
}
|
|
1600
|
+
encodeValue(x) {
|
|
1601
|
+
const buf = x.toUint8Array();
|
|
1602
|
+
const len = lebEncode(buf.length);
|
|
1603
|
+
return concat(new Uint8Array([1]), len, buf);
|
|
1604
|
+
}
|
|
1605
|
+
_buildTypeTableImpl(T) {
|
|
1606
|
+
this._fields.forEach(([_, func]) => func.buildTypeTable(T));
|
|
1607
|
+
const opCode = slebEncode(IDLTypeIds.Service);
|
|
1608
|
+
const len = lebEncode(this._fields.length);
|
|
1609
|
+
const meths = this._fields.map(([label, func]) => {
|
|
1610
|
+
const labelBuf = new TextEncoder().encode(label);
|
|
1611
|
+
const labelLen = lebEncode(labelBuf.length);
|
|
1612
|
+
return concat(labelLen, labelBuf, func.encodeType(T));
|
|
1613
|
+
});
|
|
1614
|
+
T.add(this, concat(opCode, len, ...meths));
|
|
1615
|
+
}
|
|
1616
|
+
decodeValue(b, t) {
|
|
1617
|
+
const tt = t instanceof RecClass ? (t.getType() ?? t) : t;
|
|
1618
|
+
if (!subtype(tt, this)) {
|
|
1619
|
+
throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${tt.display()}`);
|
|
1620
|
+
}
|
|
1621
|
+
return decodePrincipalId(b);
|
|
1622
|
+
}
|
|
1623
|
+
get name() {
|
|
1624
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.name);
|
|
1625
|
+
return `service {${fields.join('; ')}}`;
|
|
1626
|
+
}
|
|
1627
|
+
valueToString(x) {
|
|
1628
|
+
return `service "${x.toText()}"`;
|
|
1629
|
+
}
|
|
1630
|
+
fieldsAsObject() {
|
|
1631
|
+
const fields = {};
|
|
1632
|
+
for (const [name, ty] of this._fields) {
|
|
1633
|
+
fields[name] = ty;
|
|
1634
|
+
}
|
|
1635
|
+
return fields;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Takes an unknown value and returns a string representation of it.
|
|
1640
|
+
* @param x - unknown value
|
|
1641
|
+
* @returns {string} string representation of the value
|
|
1642
|
+
*/
|
|
1643
|
+
function toReadableString(x) {
|
|
1644
|
+
const str = JSON.stringify(x, (_key, value) => typeof value === 'bigint' ? `BigInt(${value})` : value);
|
|
1645
|
+
return str && str.length > toReadableString_max
|
|
1646
|
+
? str.substring(0, toReadableString_max - 3) + '...'
|
|
1647
|
+
: str;
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Encode a array of values
|
|
1651
|
+
* @param argTypes - array of Types
|
|
1652
|
+
* @param args - array of values
|
|
1653
|
+
* @returns {Uint8Array} serialised value
|
|
1654
|
+
*/
|
|
1655
|
+
export function encode(argTypes, args) {
|
|
1656
|
+
if (args.length < argTypes.length) {
|
|
1657
|
+
throw Error('Wrong number of message arguments');
|
|
1658
|
+
}
|
|
1659
|
+
const typeTable = new TypeTable();
|
|
1660
|
+
argTypes.forEach(t => t.buildTypeTable(typeTable));
|
|
1661
|
+
const table = typeTable.encode();
|
|
1662
|
+
const len = lebEncode(args.length);
|
|
1663
|
+
const typs = concat(...argTypes.map(t => t.encodeType(typeTable)));
|
|
1664
|
+
const vals = concat(...zipWith(argTypes, args, (t, x) => {
|
|
1665
|
+
try {
|
|
1666
|
+
t.covariant(x);
|
|
1667
|
+
}
|
|
1668
|
+
catch (e) {
|
|
1669
|
+
const err = new Error(e.message + '\n\n');
|
|
1670
|
+
throw err;
|
|
1671
|
+
}
|
|
1672
|
+
return t.encodeValue(x);
|
|
1673
|
+
}));
|
|
1674
|
+
return concat(magicNumberBytes, table, len, typs, vals);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Decode a binary value
|
|
1678
|
+
* @param retTypes - Types expected in the buffer.
|
|
1679
|
+
* @param bytes - hex-encoded string, or buffer.
|
|
1680
|
+
* @returns Value deserialised to JS type
|
|
1681
|
+
*/
|
|
1682
|
+
export function decode(retTypes, bytes) {
|
|
1683
|
+
const b = new Pipe(bytes);
|
|
1684
|
+
if (bytes.byteLength < magicNumber.length) {
|
|
1685
|
+
throw new Error('Message length smaller than magic number');
|
|
1686
|
+
}
|
|
1687
|
+
const magicBuffer = safeRead(b, magicNumber.length);
|
|
1688
|
+
const magic = new TextDecoder().decode(magicBuffer);
|
|
1689
|
+
if (magic !== magicNumber) {
|
|
1690
|
+
throw new Error('Wrong magic number: ' + JSON.stringify(magic));
|
|
1691
|
+
}
|
|
1692
|
+
function readTypeTable(pipe) {
|
|
1693
|
+
const typeTable = [];
|
|
1694
|
+
const len = Number(lebDecode(pipe));
|
|
1695
|
+
for (let i = 0; i < len; i++) {
|
|
1696
|
+
const ty = Number(slebDecode(pipe));
|
|
1697
|
+
switch (ty) {
|
|
1698
|
+
case IDLTypeIds.Opt:
|
|
1699
|
+
case IDLTypeIds.Vector: {
|
|
1700
|
+
const t = Number(slebDecode(pipe));
|
|
1701
|
+
typeTable.push([ty, t]);
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
case IDLTypeIds.Record:
|
|
1705
|
+
case IDLTypeIds.Variant: {
|
|
1706
|
+
const fields = [];
|
|
1707
|
+
let objectLength = Number(lebDecode(pipe));
|
|
1708
|
+
let prevHash;
|
|
1709
|
+
while (objectLength--) {
|
|
1710
|
+
const hash = Number(lebDecode(pipe));
|
|
1711
|
+
if (hash >= Math.pow(2, 32)) {
|
|
1712
|
+
throw new Error('field id out of 32-bit range');
|
|
1713
|
+
}
|
|
1714
|
+
if (typeof prevHash === 'number' && prevHash >= hash) {
|
|
1715
|
+
throw new Error('field id collision or not sorted');
|
|
1716
|
+
}
|
|
1717
|
+
prevHash = hash;
|
|
1718
|
+
const t = Number(slebDecode(pipe));
|
|
1719
|
+
fields.push([hash, t]);
|
|
1720
|
+
}
|
|
1721
|
+
typeTable.push([ty, fields]);
|
|
1722
|
+
break;
|
|
1723
|
+
}
|
|
1724
|
+
case IDLTypeIds.Func: {
|
|
1725
|
+
const args = [];
|
|
1726
|
+
let argLength = Number(lebDecode(pipe));
|
|
1727
|
+
while (argLength--) {
|
|
1728
|
+
args.push(Number(slebDecode(pipe)));
|
|
1729
|
+
}
|
|
1730
|
+
const returnValues = [];
|
|
1731
|
+
let returnValuesLength = Number(lebDecode(pipe));
|
|
1732
|
+
while (returnValuesLength--) {
|
|
1733
|
+
returnValues.push(Number(slebDecode(pipe)));
|
|
1734
|
+
}
|
|
1735
|
+
const annotations = [];
|
|
1736
|
+
let annotationLength = Number(lebDecode(pipe));
|
|
1737
|
+
while (annotationLength--) {
|
|
1738
|
+
const annotation = Number(lebDecode(pipe));
|
|
1739
|
+
switch (annotation) {
|
|
1740
|
+
case 1: {
|
|
1741
|
+
annotations.push('query');
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1744
|
+
case 2: {
|
|
1745
|
+
annotations.push('oneway');
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
case 3: {
|
|
1749
|
+
annotations.push('composite_query');
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
default:
|
|
1753
|
+
throw new Error('unknown annotation');
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
typeTable.push([ty, [args, returnValues, annotations]]);
|
|
1757
|
+
break;
|
|
1758
|
+
}
|
|
1759
|
+
case IDLTypeIds.Service: {
|
|
1760
|
+
let servLength = Number(lebDecode(pipe));
|
|
1761
|
+
const methods = [];
|
|
1762
|
+
while (servLength--) {
|
|
1763
|
+
const nameLength = Number(lebDecode(pipe));
|
|
1764
|
+
const funcName = new TextDecoder().decode(safeRead(pipe, nameLength));
|
|
1765
|
+
const funcType = slebDecode(pipe);
|
|
1766
|
+
methods.push([funcName, funcType]);
|
|
1767
|
+
}
|
|
1768
|
+
typeTable.push([ty, methods]);
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
default:
|
|
1772
|
+
throw new Error('Illegal op_code: ' + ty);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
const rawList = [];
|
|
1776
|
+
const length = Number(lebDecode(pipe));
|
|
1777
|
+
for (let i = 0; i < length; i++) {
|
|
1778
|
+
rawList.push(Number(slebDecode(pipe)));
|
|
1779
|
+
}
|
|
1780
|
+
return [typeTable, rawList];
|
|
1781
|
+
}
|
|
1782
|
+
const [rawTable, rawTypes] = readTypeTable(b);
|
|
1783
|
+
if (rawTypes.length < retTypes.length) {
|
|
1784
|
+
throw new Error('Wrong number of return values');
|
|
1785
|
+
}
|
|
1786
|
+
const table = rawTable.map(_ => Rec());
|
|
1787
|
+
function getType(t) {
|
|
1788
|
+
if (t < -24) {
|
|
1789
|
+
throw new Error('future value not supported');
|
|
1790
|
+
}
|
|
1791
|
+
if (t < 0) {
|
|
1792
|
+
switch (t) {
|
|
1793
|
+
case -1:
|
|
1794
|
+
return Null;
|
|
1795
|
+
case -2:
|
|
1796
|
+
return Bool;
|
|
1797
|
+
case -3:
|
|
1798
|
+
return Nat;
|
|
1799
|
+
case -4:
|
|
1800
|
+
return Int;
|
|
1801
|
+
case -5:
|
|
1802
|
+
return Nat8;
|
|
1803
|
+
case -6:
|
|
1804
|
+
return Nat16;
|
|
1805
|
+
case -7:
|
|
1806
|
+
return Nat32;
|
|
1807
|
+
case -8:
|
|
1808
|
+
return Nat64;
|
|
1809
|
+
case -9:
|
|
1810
|
+
return Int8;
|
|
1811
|
+
case -10:
|
|
1812
|
+
return Int16;
|
|
1813
|
+
case -11:
|
|
1814
|
+
return Int32;
|
|
1815
|
+
case -12:
|
|
1816
|
+
return Int64;
|
|
1817
|
+
case -13:
|
|
1818
|
+
return Float32;
|
|
1819
|
+
case -14:
|
|
1820
|
+
return Float64;
|
|
1821
|
+
case -15:
|
|
1822
|
+
return Text;
|
|
1823
|
+
case -16:
|
|
1824
|
+
return Reserved;
|
|
1825
|
+
case -17:
|
|
1826
|
+
return Empty;
|
|
1827
|
+
case -24:
|
|
1828
|
+
return Principal;
|
|
1829
|
+
default:
|
|
1830
|
+
throw new Error('Illegal op_code: ' + t);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
if (t >= rawTable.length) {
|
|
1834
|
+
throw new Error('type index out of range');
|
|
1835
|
+
}
|
|
1836
|
+
return table[t];
|
|
1837
|
+
}
|
|
1838
|
+
function buildType(entry) {
|
|
1839
|
+
switch (entry[0]) {
|
|
1840
|
+
case IDLTypeIds.Vector: {
|
|
1841
|
+
const ty = getType(entry[1]);
|
|
1842
|
+
return Vec(ty);
|
|
1843
|
+
}
|
|
1844
|
+
case IDLTypeIds.Opt: {
|
|
1845
|
+
const ty = getType(entry[1]);
|
|
1846
|
+
return Opt(ty);
|
|
1847
|
+
}
|
|
1848
|
+
case IDLTypeIds.Record: {
|
|
1849
|
+
const fields = {};
|
|
1850
|
+
for (const [hash, ty] of entry[1]) {
|
|
1851
|
+
const name = `_${hash}_`;
|
|
1852
|
+
fields[name] = getType(ty);
|
|
1853
|
+
}
|
|
1854
|
+
const record = Record(fields);
|
|
1855
|
+
const tuple = record.tryAsTuple();
|
|
1856
|
+
if (Array.isArray(tuple)) {
|
|
1857
|
+
return Tuple(...tuple);
|
|
1858
|
+
}
|
|
1859
|
+
else {
|
|
1860
|
+
return record;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
case IDLTypeIds.Variant: {
|
|
1864
|
+
const fields = {};
|
|
1865
|
+
for (const [hash, ty] of entry[1]) {
|
|
1866
|
+
const name = `_${hash}_`;
|
|
1867
|
+
fields[name] = getType(ty);
|
|
1868
|
+
}
|
|
1869
|
+
return Variant(fields);
|
|
1870
|
+
}
|
|
1871
|
+
case IDLTypeIds.Func: {
|
|
1872
|
+
const [args, returnValues, annotations] = entry[1];
|
|
1873
|
+
return Func(args.map((t) => getType(t)), returnValues.map((t) => getType(t)), annotations);
|
|
1874
|
+
}
|
|
1875
|
+
case IDLTypeIds.Service: {
|
|
1876
|
+
const rec = {};
|
|
1877
|
+
const methods = entry[1];
|
|
1878
|
+
for (const [name, typeRef] of methods) {
|
|
1879
|
+
let type = getType(typeRef);
|
|
1880
|
+
if (type instanceof RecClass) {
|
|
1881
|
+
// unpack reference type
|
|
1882
|
+
type = type.getType();
|
|
1883
|
+
}
|
|
1884
|
+
if (!(type instanceof FuncClass)) {
|
|
1885
|
+
throw new Error('Illegal service definition: services can only contain functions');
|
|
1886
|
+
}
|
|
1887
|
+
rec[name] = type;
|
|
1888
|
+
}
|
|
1889
|
+
return Service(rec);
|
|
1890
|
+
}
|
|
1891
|
+
default:
|
|
1892
|
+
throw new Error('Illegal op_code: ' + entry[0]);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
rawTable.forEach((entry, i) => {
|
|
1896
|
+
// Process function type first, so that we can construct the correct service type
|
|
1897
|
+
if (entry[0] === IDLTypeIds.Func) {
|
|
1898
|
+
const t = buildType(entry);
|
|
1899
|
+
table[i].fill(t);
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
rawTable.forEach((entry, i) => {
|
|
1903
|
+
if (entry[0] !== IDLTypeIds.Func) {
|
|
1904
|
+
const t = buildType(entry);
|
|
1905
|
+
table[i].fill(t);
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
resetSubtypeCache();
|
|
1909
|
+
const types = rawTypes.map(t => getType(t));
|
|
1910
|
+
try {
|
|
1911
|
+
const output = retTypes.map((t, i) => {
|
|
1912
|
+
return t.decodeValue(b, types[i]);
|
|
1913
|
+
});
|
|
1914
|
+
// skip unused values
|
|
1915
|
+
for (let ind = retTypes.length; ind < types.length; ind++) {
|
|
1916
|
+
types[ind].decodeValue(b, types[ind]);
|
|
1917
|
+
}
|
|
1918
|
+
if (b.byteLength > 0) {
|
|
1919
|
+
throw new Error('decode: Left-over bytes');
|
|
1920
|
+
}
|
|
1921
|
+
return output;
|
|
1922
|
+
}
|
|
1923
|
+
finally {
|
|
1924
|
+
resetSubtypeCache();
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
// Export Types instances.
|
|
1928
|
+
export const Empty = new EmptyClass();
|
|
1929
|
+
export const Reserved = new ReservedClass();
|
|
1930
|
+
/**
|
|
1931
|
+
* Client-only type for deserializing unknown data. Not supported by Candid, and its use is discouraged.
|
|
1932
|
+
*/
|
|
1933
|
+
export const Unknown = new UnknownClass();
|
|
1934
|
+
export const Bool = new BoolClass();
|
|
1935
|
+
export const Null = new NullClass();
|
|
1936
|
+
export const Text = new TextClass();
|
|
1937
|
+
export const Int = new IntClass();
|
|
1938
|
+
export const Nat = new NatClass();
|
|
1939
|
+
export const Float32 = new FloatClass(32);
|
|
1940
|
+
export const Float64 = new FloatClass(64);
|
|
1941
|
+
export const Int8 = new FixedIntClass(8);
|
|
1942
|
+
export const Int16 = new FixedIntClass(16);
|
|
1943
|
+
export const Int32 = new FixedIntClass(32);
|
|
1944
|
+
export const Int64 = new FixedIntClass(64);
|
|
1945
|
+
export const Nat8 = new FixedNatClass(8);
|
|
1946
|
+
export const Nat16 = new FixedNatClass(16);
|
|
1947
|
+
export const Nat32 = new FixedNatClass(32);
|
|
1948
|
+
export const Nat64 = new FixedNatClass(64);
|
|
1949
|
+
export const Principal = new PrincipalClass();
|
|
1950
|
+
/**
|
|
1951
|
+
*
|
|
1952
|
+
* @param types array of any types
|
|
1953
|
+
* @returns TupleClass from those types
|
|
1954
|
+
*/
|
|
1955
|
+
export function Tuple(...types) {
|
|
1956
|
+
return new TupleClass(types);
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
*
|
|
1960
|
+
* @param t IDL Type
|
|
1961
|
+
* @returns VecClass from that type
|
|
1962
|
+
*/
|
|
1963
|
+
export function Vec(t) {
|
|
1964
|
+
return new VecClass(t);
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
*
|
|
1968
|
+
* @param t IDL Type
|
|
1969
|
+
* @returns OptClass of Type
|
|
1970
|
+
*/
|
|
1971
|
+
export function Opt(t) {
|
|
1972
|
+
return new OptClass(t);
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
*
|
|
1976
|
+
* @param t Record of string and IDL Type
|
|
1977
|
+
* @returns RecordClass of string and Type
|
|
1978
|
+
*/
|
|
1979
|
+
export function Record(t) {
|
|
1980
|
+
return new RecordClass(t);
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
*
|
|
1984
|
+
* @param fields Record of string and IDL Type
|
|
1985
|
+
* @returns VariantClass
|
|
1986
|
+
*/
|
|
1987
|
+
export function Variant(fields) {
|
|
1988
|
+
return new VariantClass(fields);
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
*
|
|
1992
|
+
* @returns new RecClass
|
|
1993
|
+
*/
|
|
1994
|
+
export function Rec() {
|
|
1995
|
+
return new RecClass();
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
*
|
|
1999
|
+
* @param args array of IDL Types
|
|
2000
|
+
* @param ret array of IDL Types
|
|
2001
|
+
* @param annotations array of strings, [] by default
|
|
2002
|
+
* @returns new FuncClass
|
|
2003
|
+
*/
|
|
2004
|
+
export function Func(args, ret, annotations = []) {
|
|
2005
|
+
return new FuncClass(args, ret, annotations);
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
*
|
|
2009
|
+
* @param t Record of string and FuncClass
|
|
2010
|
+
* @returns ServiceClass
|
|
2011
|
+
*/
|
|
2012
|
+
export function Service(t) {
|
|
2013
|
+
return new ServiceClass(t);
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* The list of relations between types we assume to hold. Uses the types .name property as key
|
|
2017
|
+
*/
|
|
2018
|
+
class Relations {
|
|
2019
|
+
constructor(relations = new Map()) {
|
|
2020
|
+
this.rels = relations;
|
|
2021
|
+
}
|
|
2022
|
+
copy() {
|
|
2023
|
+
const copy = new Map();
|
|
2024
|
+
for (const [key, value] of this.rels.entries()) {
|
|
2025
|
+
const valCopy = new Map(value);
|
|
2026
|
+
copy.set(key, valCopy);
|
|
2027
|
+
}
|
|
2028
|
+
return new Relations(copy);
|
|
2029
|
+
}
|
|
2030
|
+
/// Returns whether we know for sure that a relation holds or doesn't (`true` or `false`), or
|
|
2031
|
+
/// if we don't know yet (`undefined`)
|
|
2032
|
+
known(t1, t2) {
|
|
2033
|
+
return this.rels.get(t1.name)?.get(t2.name);
|
|
2034
|
+
}
|
|
2035
|
+
addNegative(t1, t2) {
|
|
2036
|
+
this.addNames(t1.name, t2.name, false);
|
|
2037
|
+
}
|
|
2038
|
+
add(t1, t2) {
|
|
2039
|
+
this.addNames(t1.name, t2.name, true);
|
|
2040
|
+
}
|
|
2041
|
+
display() {
|
|
2042
|
+
let result = '';
|
|
2043
|
+
for (const [t1, v] of this.rels) {
|
|
2044
|
+
for (const [t2, known] of v) {
|
|
2045
|
+
const subty = known ? ':<' : '!<:';
|
|
2046
|
+
result += `${t1} ${subty} ${t2}\n`;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
return result;
|
|
2050
|
+
}
|
|
2051
|
+
addNames(t1, t2, isSubtype) {
|
|
2052
|
+
const t1Map = this.rels.get(t1);
|
|
2053
|
+
if (t1Map == undefined) {
|
|
2054
|
+
const newMap = new Map();
|
|
2055
|
+
newMap.set(t2, isSubtype);
|
|
2056
|
+
this.rels.set(t1, newMap);
|
|
2057
|
+
}
|
|
2058
|
+
else {
|
|
2059
|
+
t1Map.set(t2, isSubtype);
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
/// `subtypeCache` holds subtyping relations we've previously computed while decoding a message
|
|
2064
|
+
let subtypeCache = new Relations();
|
|
2065
|
+
/** Resets the global subtyping cache */
|
|
2066
|
+
export function resetSubtypeCache() {
|
|
2067
|
+
subtypeCache = new Relations();
|
|
2068
|
+
}
|
|
2069
|
+
function eqFunctionAnnotations(t1, t2) {
|
|
2070
|
+
const t1Annotations = new Set(t1.annotations);
|
|
2071
|
+
const t2Annotations = new Set(t2.annotations);
|
|
2072
|
+
if (t1Annotations.size !== t2Annotations.size) {
|
|
2073
|
+
return false;
|
|
2074
|
+
}
|
|
2075
|
+
for (const a of t1Annotations) {
|
|
2076
|
+
if (!t2Annotations.has(a))
|
|
2077
|
+
return false;
|
|
2078
|
+
}
|
|
2079
|
+
return true;
|
|
2080
|
+
}
|
|
2081
|
+
function canBeOmmitted(t) {
|
|
2082
|
+
return t instanceof OptClass || t instanceof NullClass || t instanceof ReservedClass;
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Subtyping on Candid types t1 <: t2 (Exported for testing)
|
|
2086
|
+
* @param t1 The potential subtype
|
|
2087
|
+
* @param t2 The potential supertype
|
|
2088
|
+
*/
|
|
2089
|
+
export function subtype(t1, t2) {
|
|
2090
|
+
const relations = subtypeCache.copy();
|
|
2091
|
+
const isSubtype = subtype_(relations, t1, t2);
|
|
2092
|
+
if (isSubtype) {
|
|
2093
|
+
subtypeCache.add(t1, t2);
|
|
2094
|
+
}
|
|
2095
|
+
else {
|
|
2096
|
+
subtypeCache.addNegative(t1, t2);
|
|
2097
|
+
}
|
|
2098
|
+
return isSubtype;
|
|
2099
|
+
}
|
|
2100
|
+
function subtype_(relations, t1, t2) {
|
|
2101
|
+
if (t1.name === t2.name)
|
|
2102
|
+
return true;
|
|
2103
|
+
const known = relations.known(t1, t2);
|
|
2104
|
+
if (known !== undefined)
|
|
2105
|
+
return known;
|
|
2106
|
+
relations.add(t1, t2);
|
|
2107
|
+
if (t2 instanceof ReservedClass)
|
|
2108
|
+
return true;
|
|
2109
|
+
if (t1 instanceof EmptyClass)
|
|
2110
|
+
return true;
|
|
2111
|
+
if (t1 instanceof NatClass && t2 instanceof IntClass)
|
|
2112
|
+
return true;
|
|
2113
|
+
if (t1 instanceof VecClass && t2 instanceof VecClass)
|
|
2114
|
+
return subtype_(relations, t1._type, t2._type);
|
|
2115
|
+
if (t2 instanceof OptClass)
|
|
2116
|
+
return true;
|
|
2117
|
+
if (t1 instanceof RecordClass && t2 instanceof RecordClass) {
|
|
2118
|
+
const t1Object = t1.fieldsAsObject;
|
|
2119
|
+
for (const [label, ty2] of t2._fields) {
|
|
2120
|
+
const ty1 = t1Object[idlLabelToId(label)];
|
|
2121
|
+
if (!ty1) {
|
|
2122
|
+
if (!canBeOmmitted(ty2))
|
|
2123
|
+
return false;
|
|
2124
|
+
}
|
|
2125
|
+
else {
|
|
2126
|
+
if (!subtype_(relations, ty1, ty2))
|
|
2127
|
+
return false;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return true;
|
|
2131
|
+
}
|
|
2132
|
+
if (t1 instanceof FuncClass && t2 instanceof FuncClass) {
|
|
2133
|
+
if (!eqFunctionAnnotations(t1, t2))
|
|
2134
|
+
return false;
|
|
2135
|
+
for (let i = 0; i < t1.argTypes.length; i++) {
|
|
2136
|
+
const argTy1 = t1.argTypes[i];
|
|
2137
|
+
if (i < t2.argTypes.length) {
|
|
2138
|
+
if (!subtype_(relations, t2.argTypes[i], argTy1))
|
|
2139
|
+
return false;
|
|
2140
|
+
}
|
|
2141
|
+
else {
|
|
2142
|
+
if (!canBeOmmitted(argTy1))
|
|
2143
|
+
return false;
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
for (let i = 0; i < t2.retTypes.length; i++) {
|
|
2147
|
+
const retTy2 = t2.retTypes[i];
|
|
2148
|
+
if (i < t1.retTypes.length) {
|
|
2149
|
+
if (!subtype_(relations, t1.retTypes[i], retTy2))
|
|
2150
|
+
return false;
|
|
2151
|
+
}
|
|
2152
|
+
else {
|
|
2153
|
+
if (!canBeOmmitted(retTy2))
|
|
2154
|
+
return false;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
return true;
|
|
2158
|
+
}
|
|
2159
|
+
if (t1 instanceof VariantClass && t2 instanceof VariantClass) {
|
|
2160
|
+
const t2Object = t2.alternativesAsObject;
|
|
2161
|
+
for (const [label, ty1] of t1._fields) {
|
|
2162
|
+
const ty2 = t2Object[idlLabelToId(label)];
|
|
2163
|
+
if (!ty2)
|
|
2164
|
+
return false;
|
|
2165
|
+
if (!subtype_(relations, ty1, ty2))
|
|
2166
|
+
return false;
|
|
2167
|
+
}
|
|
2168
|
+
return true;
|
|
2169
|
+
}
|
|
2170
|
+
if (t1 instanceof ServiceClass && t2 instanceof ServiceClass) {
|
|
2171
|
+
const t1Object = t1.fieldsAsObject();
|
|
2172
|
+
for (const [name, ty2] of t2._fields) {
|
|
2173
|
+
const ty1 = t1Object[name];
|
|
2174
|
+
if (!ty1)
|
|
2175
|
+
return false;
|
|
2176
|
+
if (!subtype_(relations, ty1, ty2))
|
|
2177
|
+
return false;
|
|
2178
|
+
}
|
|
2179
|
+
return true;
|
|
2180
|
+
}
|
|
2181
|
+
if (t1 instanceof RecClass) {
|
|
2182
|
+
return subtype_(relations, t1.getType(), t2);
|
|
2183
|
+
}
|
|
2184
|
+
if (t2 instanceof RecClass) {
|
|
2185
|
+
return subtype_(relations, t1, t2.getType());
|
|
2186
|
+
}
|
|
2187
|
+
return false;
|
|
2188
|
+
}
|
|
2189
|
+
//# sourceMappingURL=idl.js.map
|