@icp-sdk/core 4.2.3 → 5.0.0-beta.0
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 +7 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +19 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +171 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/index.js +1079 -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 +93 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.js +301 -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 +228 -0
- package/lib/cjs/agent/certificate.d.ts.map +1 -0
- package/lib/cjs/agent/certificate.js +591 -0
- package/lib/cjs/agent/certificate.js.map +1 -0
- package/lib/cjs/agent/constants.d.ts +14 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -0
- package/lib/cjs/agent/constants.js +18 -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 +380 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -0
- package/lib/cjs/agent/errors.js +733 -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 +31 -1
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +59 -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/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/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 +11 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +33 -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 +15 -1
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +24 -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 +4 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +4 -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 +3 -1
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +7 -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 +7 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +16 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +171 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/index.js +1037 -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 +110 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +110 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +93 -0
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/canisterStatus/index.js +261 -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 +228 -0
- package/lib/esm/agent/certificate.d.ts.map +1 -0
- package/lib/esm/agent/certificate.js +545 -0
- package/lib/esm/agent/certificate.js.map +1 -0
- package/lib/esm/agent/constants.d.ts +14 -0
- package/lib/esm/agent/constants.d.ts.map +1 -0
- package/lib/esm/agent/constants.js +15 -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 +380 -0
- package/lib/esm/agent/errors.d.ts.map +1 -0
- package/lib/esm/agent/errors.js +678 -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 +31 -1
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +31 -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/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/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 +11 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +10 -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 +15 -1
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +17 -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 +4 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +4 -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 +3 -1
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +3 -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 +1405 -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 +191 -1
- package/src/agent/canisterStatus/index.ts +412 -0
- package/src/agent/cbor.ts +63 -0
- package/src/agent/certificate.ts +841 -0
- package/src/agent/constants.ts +19 -0
- package/src/agent/der.ts +170 -0
- package/src/agent/errors.ts +868 -0
- package/src/agent/fetch_candid.ts +37 -0
- package/src/agent/index.ts +37 -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/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/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 +16 -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 +19 -1
- package/src/identity/secp256k1/der.ts +156 -0
- package/src/identity/secp256k1/index.ts +5 -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 +3 -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,276 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import * as IDL from './idl.ts';
|
|
5
|
+
|
|
6
|
+
export interface ParseConfig {
|
|
7
|
+
random?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface UIConfig {
|
|
11
|
+
input?: HTMLElement;
|
|
12
|
+
form?: InputForm;
|
|
13
|
+
parse(t: IDL.Type, config: ParseConfig, v: string): any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FormConfig {
|
|
17
|
+
open?: HTMLElement;
|
|
18
|
+
event?: string;
|
|
19
|
+
labelMap?: Record<string, string>;
|
|
20
|
+
container?: HTMLElement;
|
|
21
|
+
render(t: IDL.Type): InputBox;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class InputBox {
|
|
25
|
+
public status: HTMLElement;
|
|
26
|
+
public label: string | null = null;
|
|
27
|
+
public value: any = undefined;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
public idl: IDL.Type,
|
|
31
|
+
public ui: UIConfig,
|
|
32
|
+
) {
|
|
33
|
+
const status = document.createElement('span');
|
|
34
|
+
status.className = 'status';
|
|
35
|
+
this.status = status;
|
|
36
|
+
|
|
37
|
+
if (ui.input) {
|
|
38
|
+
ui.input.addEventListener('blur', () => {
|
|
39
|
+
if ((ui.input as HTMLInputElement).value === '') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.parse();
|
|
43
|
+
});
|
|
44
|
+
ui.input.addEventListener('input', () => {
|
|
45
|
+
status.style.display = 'none';
|
|
46
|
+
ui.input!.classList.remove('reject');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
public isRejected(): boolean {
|
|
51
|
+
return this.value === undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public parse(config: ParseConfig = {}): any {
|
|
55
|
+
if (this.ui.form) {
|
|
56
|
+
const value = this.ui.form.parse(config);
|
|
57
|
+
this.value = value;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (this.ui.input) {
|
|
62
|
+
const input = this.ui.input as HTMLInputElement;
|
|
63
|
+
try {
|
|
64
|
+
const value = this.ui.parse(this.idl, config, input.value);
|
|
65
|
+
if (!this.idl.covariant(value)) {
|
|
66
|
+
throw new Error(`${input.value} is not of type ${this.idl.display()}`);
|
|
67
|
+
}
|
|
68
|
+
this.status.style.display = 'none';
|
|
69
|
+
this.value = value;
|
|
70
|
+
return value;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
input.classList.add('reject');
|
|
73
|
+
this.status.style.display = 'block';
|
|
74
|
+
this.status.innerHTML = 'InputError: ' + (err as Error).message;
|
|
75
|
+
this.value = undefined;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
public render(dom: HTMLElement): void {
|
|
82
|
+
const container = document.createElement('span');
|
|
83
|
+
if (this.label) {
|
|
84
|
+
const label = document.createElement('label');
|
|
85
|
+
label.innerText = this.label;
|
|
86
|
+
container.appendChild(label);
|
|
87
|
+
}
|
|
88
|
+
if (this.ui.input) {
|
|
89
|
+
container.appendChild(this.ui.input);
|
|
90
|
+
container.appendChild(this.status);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (this.ui.form) {
|
|
94
|
+
this.ui.form.render(container);
|
|
95
|
+
}
|
|
96
|
+
dom.appendChild(container);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export abstract class InputForm {
|
|
101
|
+
public form: InputBox[] = [];
|
|
102
|
+
constructor(public ui: FormConfig) {}
|
|
103
|
+
|
|
104
|
+
public abstract parse(config: ParseConfig): any;
|
|
105
|
+
public abstract generateForm(): any;
|
|
106
|
+
public renderForm(dom: HTMLElement): void {
|
|
107
|
+
if (this.ui.container) {
|
|
108
|
+
this.form.forEach(e => e.render(this.ui.container!));
|
|
109
|
+
dom.appendChild(this.ui.container);
|
|
110
|
+
} else {
|
|
111
|
+
this.form.forEach(e => e.render(dom));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
public render(dom: HTMLElement): void {
|
|
115
|
+
if (this.ui.open && this.ui.event) {
|
|
116
|
+
dom.appendChild(this.ui.open);
|
|
117
|
+
const form = this;
|
|
118
|
+
|
|
119
|
+
form.ui.open!.addEventListener(form.ui.event!, () => {
|
|
120
|
+
// Remove old form
|
|
121
|
+
if (form.ui.container) {
|
|
122
|
+
form.ui.container.innerHTML = '';
|
|
123
|
+
} else {
|
|
124
|
+
const oldContainer = form.ui.open!.nextElementSibling;
|
|
125
|
+
if (oldContainer) {
|
|
126
|
+
oldContainer.parentNode!.removeChild(oldContainer);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Render form
|
|
130
|
+
form.generateForm();
|
|
131
|
+
form.renderForm(dom);
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
this.generateForm();
|
|
135
|
+
this.renderForm(dom);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class RecordForm extends InputForm {
|
|
141
|
+
constructor(
|
|
142
|
+
public fields: Array<[string, IDL.Type]>,
|
|
143
|
+
public ui: FormConfig,
|
|
144
|
+
) {
|
|
145
|
+
super(ui);
|
|
146
|
+
}
|
|
147
|
+
public generateForm(): void {
|
|
148
|
+
this.form = this.fields.map(([key, type]) => {
|
|
149
|
+
const input = this.ui.render(type);
|
|
150
|
+
// eslint-disable-next-line
|
|
151
|
+
if (this.ui.labelMap && this.ui.labelMap.hasOwnProperty(key)) {
|
|
152
|
+
input.label = this.ui.labelMap[key] + ' ';
|
|
153
|
+
} else {
|
|
154
|
+
input.label = key + ' ';
|
|
155
|
+
}
|
|
156
|
+
return input;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
public parse(config: ParseConfig): Record<string, any> | undefined {
|
|
160
|
+
const v: Record<string, any> = {};
|
|
161
|
+
this.fields.forEach(([key, _], i) => {
|
|
162
|
+
const value = this.form[i].parse(config);
|
|
163
|
+
v[key] = value;
|
|
164
|
+
});
|
|
165
|
+
if (this.form.some(input => input.isRejected())) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return v;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export class TupleForm extends InputForm {
|
|
173
|
+
constructor(
|
|
174
|
+
public components: IDL.Type[],
|
|
175
|
+
public ui: FormConfig,
|
|
176
|
+
) {
|
|
177
|
+
super(ui);
|
|
178
|
+
}
|
|
179
|
+
public generateForm(): void {
|
|
180
|
+
this.form = this.components.map(type => {
|
|
181
|
+
const input = this.ui.render(type);
|
|
182
|
+
return input;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
public parse(config: ParseConfig): any[] | undefined {
|
|
186
|
+
const v: any[] = [];
|
|
187
|
+
this.components.forEach((_, i) => {
|
|
188
|
+
const value = this.form[i].parse(config);
|
|
189
|
+
v.push(value);
|
|
190
|
+
});
|
|
191
|
+
if (this.form.some(input => input.isRejected())) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
return v;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class VariantForm extends InputForm {
|
|
199
|
+
constructor(
|
|
200
|
+
public fields: Array<[string, IDL.Type]>,
|
|
201
|
+
public ui: FormConfig,
|
|
202
|
+
) {
|
|
203
|
+
super(ui);
|
|
204
|
+
}
|
|
205
|
+
public generateForm(): void {
|
|
206
|
+
const index = (this.ui.open as HTMLSelectElement).selectedIndex;
|
|
207
|
+
const [_, type] = this.fields[index];
|
|
208
|
+
const variant = this.ui.render(type);
|
|
209
|
+
this.form = [variant];
|
|
210
|
+
}
|
|
211
|
+
public parse(config: ParseConfig): Record<string, any> | undefined {
|
|
212
|
+
const select = this.ui.open as HTMLSelectElement;
|
|
213
|
+
const selected = select.options[select.selectedIndex].value;
|
|
214
|
+
const value = this.form[0].parse(config);
|
|
215
|
+
if (value === undefined) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
const v: Record<string, any> = {};
|
|
219
|
+
v[selected] = value;
|
|
220
|
+
return v;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class OptionForm extends InputForm {
|
|
225
|
+
constructor(
|
|
226
|
+
public ty: IDL.Type,
|
|
227
|
+
public ui: FormConfig,
|
|
228
|
+
) {
|
|
229
|
+
super(ui);
|
|
230
|
+
}
|
|
231
|
+
public generateForm(): void {
|
|
232
|
+
if ((this.ui.open as HTMLInputElement).checked) {
|
|
233
|
+
const opt = this.ui.render(this.ty);
|
|
234
|
+
this.form = [opt];
|
|
235
|
+
} else {
|
|
236
|
+
this.form = [];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
public parse<T>(config: ParseConfig): [T] | [] | undefined {
|
|
240
|
+
if (this.form.length === 0) {
|
|
241
|
+
return [];
|
|
242
|
+
} else {
|
|
243
|
+
const value = this.form[0].parse(config);
|
|
244
|
+
if (value === undefined) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
return [value];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class VecForm extends InputForm {
|
|
253
|
+
constructor(
|
|
254
|
+
public ty: IDL.Type,
|
|
255
|
+
public ui: FormConfig,
|
|
256
|
+
) {
|
|
257
|
+
super(ui);
|
|
258
|
+
}
|
|
259
|
+
public generateForm(): void {
|
|
260
|
+
const len = +(this.ui.open as HTMLInputElement).value;
|
|
261
|
+
this.form = [];
|
|
262
|
+
for (let i = 0; i < len; i++) {
|
|
263
|
+
const t = this.ui.render(this.ty);
|
|
264
|
+
this.form.push(t);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
public parse<T>(config: ParseConfig): T[] | undefined {
|
|
268
|
+
const value = this.form.map(input => {
|
|
269
|
+
return input.parse(config);
|
|
270
|
+
});
|
|
271
|
+
if (this.form.some(input => input.isRejected())) {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
import * as IDL from './idl.ts';
|
|
4
|
+
import { Principal } from '#principal';
|
|
5
|
+
import * as UI from './candid-core.ts';
|
|
6
|
+
|
|
7
|
+
type InputBox = UI.InputBox;
|
|
8
|
+
|
|
9
|
+
const InputConfig: UI.UIConfig = { parse: parsePrimitive };
|
|
10
|
+
const FormConfig: UI.FormConfig = { render: renderInput };
|
|
11
|
+
|
|
12
|
+
export const inputBox = (t: IDL.Type, config: Partial<UI.UIConfig>) => {
|
|
13
|
+
return new UI.InputBox(t, { ...InputConfig, ...config });
|
|
14
|
+
};
|
|
15
|
+
export const recordForm = (fields: Array<[string, IDL.Type]>, config: Partial<UI.FormConfig>) => {
|
|
16
|
+
return new UI.RecordForm(fields, { ...FormConfig, ...config });
|
|
17
|
+
};
|
|
18
|
+
export const tupleForm = (components: IDL.Type[], config: Partial<UI.FormConfig>) => {
|
|
19
|
+
return new UI.TupleForm(components, { ...FormConfig, ...config });
|
|
20
|
+
};
|
|
21
|
+
export const variantForm = (fields: Array<[string, IDL.Type]>, config: Partial<UI.FormConfig>) => {
|
|
22
|
+
return new UI.VariantForm(fields, { ...FormConfig, ...config });
|
|
23
|
+
};
|
|
24
|
+
export const optForm = (ty: IDL.Type, config: Partial<UI.FormConfig>) => {
|
|
25
|
+
return new UI.OptionForm(ty, { ...FormConfig, ...config });
|
|
26
|
+
};
|
|
27
|
+
export const vecForm = (ty: IDL.Type, config: Partial<UI.FormConfig>) => {
|
|
28
|
+
return new UI.VecForm(ty, { ...FormConfig, ...config });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class Render extends IDL.Visitor<null, InputBox> {
|
|
32
|
+
public visitType<T>(t: IDL.Type<T>, _d: null): InputBox {
|
|
33
|
+
const input = document.createElement('input');
|
|
34
|
+
input.classList.add('argument');
|
|
35
|
+
input.placeholder = t.display();
|
|
36
|
+
return inputBox(t, { input });
|
|
37
|
+
}
|
|
38
|
+
public visitNull(t: IDL.NullClass, _d: null): InputBox {
|
|
39
|
+
return inputBox(t, {});
|
|
40
|
+
}
|
|
41
|
+
public visitRecord(t: IDL.RecordClass, fields: Array<[string, IDL.Type]>, _d: null): InputBox {
|
|
42
|
+
let config = {};
|
|
43
|
+
if (fields.length > 1) {
|
|
44
|
+
const container = document.createElement('div');
|
|
45
|
+
container.classList.add('popup-form');
|
|
46
|
+
config = { container };
|
|
47
|
+
}
|
|
48
|
+
const form = recordForm(fields, config);
|
|
49
|
+
return inputBox(t as IDL.Type<any>, { form });
|
|
50
|
+
}
|
|
51
|
+
public visitTuple<T extends any[]>(
|
|
52
|
+
t: IDL.TupleClass<T>,
|
|
53
|
+
components: IDL.Type[],
|
|
54
|
+
_d: null,
|
|
55
|
+
): InputBox {
|
|
56
|
+
let config = {};
|
|
57
|
+
if (components.length > 1) {
|
|
58
|
+
const container = document.createElement('div');
|
|
59
|
+
container.classList.add('popup-form');
|
|
60
|
+
config = { container };
|
|
61
|
+
}
|
|
62
|
+
const form = tupleForm(components, config);
|
|
63
|
+
return inputBox(t as IDL.Type<any>, { form });
|
|
64
|
+
}
|
|
65
|
+
public visitVariant(t: IDL.VariantClass, fields: Array<[string, IDL.Type]>, _d: null): InputBox {
|
|
66
|
+
const select = document.createElement('select');
|
|
67
|
+
for (const [key, _type] of fields) {
|
|
68
|
+
const option = new Option(key);
|
|
69
|
+
select.add(option);
|
|
70
|
+
}
|
|
71
|
+
select.selectedIndex = -1;
|
|
72
|
+
select.classList.add('open');
|
|
73
|
+
const config: Partial<UI.FormConfig> = { open: select, event: 'change' };
|
|
74
|
+
const form = variantForm(fields, config);
|
|
75
|
+
return inputBox(t as IDL.Type<any>, { form });
|
|
76
|
+
}
|
|
77
|
+
public visitOpt<T>(t: IDL.OptClass<T>, ty: IDL.Type<T>, _d: null): InputBox {
|
|
78
|
+
const checkbox = document.createElement('input');
|
|
79
|
+
checkbox.type = 'checkbox';
|
|
80
|
+
checkbox.classList.add('open');
|
|
81
|
+
const form = optForm(ty, { open: checkbox, event: 'change' });
|
|
82
|
+
return inputBox(t as IDL.Type<any>, { form });
|
|
83
|
+
}
|
|
84
|
+
public visitVec<T>(t: IDL.VecClass<T>, ty: IDL.Type<T>, _d: null): InputBox {
|
|
85
|
+
const len = document.createElement('input');
|
|
86
|
+
len.type = 'number';
|
|
87
|
+
len.min = '0';
|
|
88
|
+
len.max = '100';
|
|
89
|
+
len.style.width = '8rem';
|
|
90
|
+
len.placeholder = 'len';
|
|
91
|
+
len.classList.add('open');
|
|
92
|
+
const container = document.createElement('div');
|
|
93
|
+
container.classList.add('popup-form');
|
|
94
|
+
const form = vecForm(ty, { open: len, event: 'change', container });
|
|
95
|
+
return inputBox(t, { form });
|
|
96
|
+
}
|
|
97
|
+
public visitRec<T>(_t: IDL.RecClass<T>, ty: IDL.ConstructType<T>, _d: null): InputBox {
|
|
98
|
+
return renderInput(ty);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
class Parse extends IDL.Visitor<string, any> {
|
|
103
|
+
public visitNull(_t: IDL.NullClass, _v: string): null {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
public visitBool(_t: IDL.BoolClass, v: string): boolean {
|
|
107
|
+
if (v === 'true') {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (v === 'false') {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
throw new Error(`Cannot parse ${v} as boolean`);
|
|
114
|
+
}
|
|
115
|
+
public visitText(_t: IDL.TextClass, v: string): string {
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
public visitFloat(_t: IDL.FloatClass, v: string): number {
|
|
119
|
+
return parseFloat(v);
|
|
120
|
+
}
|
|
121
|
+
public visitFixedInt(t: IDL.FixedIntClass, v: string): number | bigint {
|
|
122
|
+
if (t._bits <= 32) {
|
|
123
|
+
return parseInt(v, 10);
|
|
124
|
+
} else {
|
|
125
|
+
return BigInt(v);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
public visitFixedNat(t: IDL.FixedNatClass, v: string): number | bigint {
|
|
129
|
+
if (t._bits <= 32) {
|
|
130
|
+
return parseInt(v, 10);
|
|
131
|
+
} else {
|
|
132
|
+
return BigInt(v);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
public visitNumber(_t: IDL.PrimitiveType, v: string): bigint {
|
|
136
|
+
return BigInt(v);
|
|
137
|
+
}
|
|
138
|
+
public visitPrincipal(_t: IDL.PrincipalClass, v: string): Principal {
|
|
139
|
+
return Principal.fromText(v);
|
|
140
|
+
}
|
|
141
|
+
public visitService(_t: IDL.ServiceClass, v: string): Principal {
|
|
142
|
+
return Principal.fromText(v);
|
|
143
|
+
}
|
|
144
|
+
public visitFunc(_t: IDL.FuncClass, v: string): [Principal, string] {
|
|
145
|
+
const x = v.split('.', 2);
|
|
146
|
+
return [Principal.fromText(x[0]), x[1]];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
class Random extends IDL.Visitor<string, any> {
|
|
151
|
+
public visitNull(_t: IDL.NullClass, _v: string): null {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
public visitBool(_t: IDL.BoolClass, _v: string): boolean {
|
|
155
|
+
return Math.random() < 0.5;
|
|
156
|
+
}
|
|
157
|
+
public visitText(_t: IDL.TextClass, _v: string): string {
|
|
158
|
+
return Math.random().toString(36).substring(6);
|
|
159
|
+
}
|
|
160
|
+
public visitFloat(_t: IDL.FloatClass, _v: string): number {
|
|
161
|
+
return Math.random();
|
|
162
|
+
}
|
|
163
|
+
public visitInt(_t: IDL.IntClass, _v: string): bigint {
|
|
164
|
+
return BigInt(this.generateNumber(true));
|
|
165
|
+
}
|
|
166
|
+
public visitNat(_t: IDL.NatClass, _v: string): bigint {
|
|
167
|
+
return BigInt(this.generateNumber(false));
|
|
168
|
+
}
|
|
169
|
+
public visitFixedInt(t: IDL.FixedIntClass, v: string): number | bigint {
|
|
170
|
+
const x = this.generateNumber(true);
|
|
171
|
+
if (t._bits <= 32) {
|
|
172
|
+
return x;
|
|
173
|
+
} else {
|
|
174
|
+
return BigInt(v);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
public visitFixedNat(t: IDL.FixedNatClass, v: string): number | bigint {
|
|
178
|
+
const x = this.generateNumber(false);
|
|
179
|
+
if (t._bits <= 32) {
|
|
180
|
+
return x;
|
|
181
|
+
} else {
|
|
182
|
+
return BigInt(v);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
private generateNumber(signed: boolean): number {
|
|
186
|
+
const num = Math.floor(Math.random() * 100);
|
|
187
|
+
if (signed && Math.random() < 0.5) {
|
|
188
|
+
return -num;
|
|
189
|
+
} else {
|
|
190
|
+
return num;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function parsePrimitive(t: IDL.Type, config: UI.ParseConfig, d: string) {
|
|
196
|
+
if (config.random && d === '') {
|
|
197
|
+
return t.accept(new Random(), d);
|
|
198
|
+
} else {
|
|
199
|
+
return t.accept(new Parse(), d);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param t an IDL type
|
|
206
|
+
* @returns an input for that type
|
|
207
|
+
*/
|
|
208
|
+
export function renderInput(t: IDL.Type): InputBox {
|
|
209
|
+
return t.accept(new Render(), null);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
interface ValueConfig {
|
|
213
|
+
input: InputBox;
|
|
214
|
+
value: any;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
*
|
|
219
|
+
* @param t an IDL Type
|
|
220
|
+
* @param input an InputBox
|
|
221
|
+
* @param value any
|
|
222
|
+
* @returns rendering that value to the provided input
|
|
223
|
+
*/
|
|
224
|
+
export function renderValue(t: IDL.Type, input: InputBox, value: any) {
|
|
225
|
+
return t.accept(new RenderValue(), { input, value });
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
class RenderValue extends IDL.Visitor<ValueConfig, void> {
|
|
229
|
+
public visitType<T>(t: IDL.Type<T>, d: ValueConfig) {
|
|
230
|
+
(d.input.ui.input as HTMLInputElement).value = t.valueToString(d.value);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public visitNull(_t: IDL.NullClass, _d: ValueConfig) {}
|
|
234
|
+
public visitText(_t: IDL.TextClass, d: ValueConfig) {
|
|
235
|
+
(d.input.ui.input as HTMLInputElement).value = d.value;
|
|
236
|
+
}
|
|
237
|
+
public visitRec<T>(_t: IDL.RecClass<T>, ty: IDL.ConstructType<T>, d: ValueConfig): void {
|
|
238
|
+
renderValue(ty, d.input, d.value);
|
|
239
|
+
}
|
|
240
|
+
public visitOpt<T>(_t: IDL.OptClass<T>, ty: IDL.Type<T>, d: ValueConfig): void {
|
|
241
|
+
if (d.value.length === 0) {
|
|
242
|
+
return;
|
|
243
|
+
} else {
|
|
244
|
+
const form = d.input.ui.form!;
|
|
245
|
+
const open = form.ui.open as HTMLInputElement;
|
|
246
|
+
open.checked = true;
|
|
247
|
+
open.dispatchEvent(new Event(form.ui.event!));
|
|
248
|
+
renderValue(ty, form.form[0], d.value[0]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
public visitRecord(_t: IDL.RecordClass, fields: Array<[string, IDL.Type]>, d: ValueConfig) {
|
|
252
|
+
const form = d.input.ui.form!;
|
|
253
|
+
fields.forEach(([key, type], i) => {
|
|
254
|
+
renderValue(type, form.form[i], d.value[key]);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
public visitTuple<T extends any[]>(
|
|
258
|
+
_t: IDL.TupleClass<T>,
|
|
259
|
+
components: IDL.Type[],
|
|
260
|
+
d: ValueConfig,
|
|
261
|
+
) {
|
|
262
|
+
const form = d.input.ui.form!;
|
|
263
|
+
components.forEach((type, i) => {
|
|
264
|
+
renderValue(type, form.form[i], d.value[i]);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
public visitVariant(_t: IDL.VariantClass, fields: Array<[string, IDL.Type]>, d: ValueConfig) {
|
|
268
|
+
const form = d.input.ui.form!;
|
|
269
|
+
const selected = Object.entries(d.value)[0];
|
|
270
|
+
fields.forEach(([key, type], i) => {
|
|
271
|
+
if (key === selected[0]) {
|
|
272
|
+
const open = form.ui.open as HTMLSelectElement;
|
|
273
|
+
open.selectedIndex = i;
|
|
274
|
+
open.dispatchEvent(new Event(form.ui.event!));
|
|
275
|
+
renderValue(type, form.form[0], selected[1]);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
public visitVec<T>(_t: IDL.VecClass<T>, ty: IDL.Type<T>, d: ValueConfig) {
|
|
280
|
+
const form = d.input.ui.form!;
|
|
281
|
+
const len = d.value.length;
|
|
282
|
+
const open = form.ui.open as HTMLInputElement;
|
|
283
|
+
open.value = len;
|
|
284
|
+
open.dispatchEvent(new Event(form.ui.event!));
|
|
285
|
+
d.value.forEach((v: T, i: number) => {
|
|
286
|
+
renderValue(ty, form.form[i], v);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|