@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,163 @@
|
|
|
1
|
+
export type ExpirableMapOptions<K, V> = {
|
|
2
|
+
source?: Iterable<[K, V]>;
|
|
3
|
+
expirationTime?: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A map that expires entries after a given time.
|
|
8
|
+
* Defaults to 10 minutes.
|
|
9
|
+
*/
|
|
10
|
+
export class ExpirableMap<K, V> implements Map<K, V> {
|
|
11
|
+
// Internals
|
|
12
|
+
#inner: Map<K, { value: V; timestamp: number }>;
|
|
13
|
+
#expirationTime: number;
|
|
14
|
+
|
|
15
|
+
[Symbol.iterator]: () => MapIterator<[K, V]> = this.entries.bind(this);
|
|
16
|
+
[Symbol.toStringTag] = 'ExpirableMap';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new ExpirableMap.
|
|
20
|
+
* @param {ExpirableMapOptions<any, any>} options - options for the map.
|
|
21
|
+
* @param {Iterable<[any, any]>} options.source - an optional source of entries to initialize the map with.
|
|
22
|
+
* @param {number} options.expirationTime - the time in milliseconds after which entries will expire.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options: ExpirableMapOptions<K, V> = {}) {
|
|
25
|
+
const { source = [], expirationTime = 10 * 60 * 1000 } = options;
|
|
26
|
+
const currentTime = Date.now();
|
|
27
|
+
this.#inner = new Map(
|
|
28
|
+
[...source].map(([key, value]) => [key, { value, timestamp: currentTime }]),
|
|
29
|
+
);
|
|
30
|
+
this.#expirationTime = expirationTime;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Prune removes all expired entries.
|
|
35
|
+
*/
|
|
36
|
+
prune() {
|
|
37
|
+
const currentTime = Date.now();
|
|
38
|
+
for (const [key, entry] of this.#inner.entries()) {
|
|
39
|
+
if (currentTime - entry.timestamp > this.#expirationTime) {
|
|
40
|
+
this.#inner.delete(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Implementing the Map interface
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set the value for the given key. Prunes expired entries.
|
|
50
|
+
* @param key for the entry
|
|
51
|
+
* @param value of the entry
|
|
52
|
+
* @returns this
|
|
53
|
+
*/
|
|
54
|
+
set(key: K, value: V) {
|
|
55
|
+
this.prune();
|
|
56
|
+
const entry = {
|
|
57
|
+
value,
|
|
58
|
+
timestamp: Date.now(),
|
|
59
|
+
};
|
|
60
|
+
this.#inner.set(key, entry);
|
|
61
|
+
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get the value associated with the key, if it exists and has not expired.
|
|
67
|
+
* @param key K
|
|
68
|
+
* @returns the value associated with the key, or undefined if the key is not present or has expired.
|
|
69
|
+
*/
|
|
70
|
+
get(key: K) {
|
|
71
|
+
const entry = this.#inner.get(key);
|
|
72
|
+
if (entry === undefined) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
if (Date.now() - entry.timestamp > this.#expirationTime) {
|
|
76
|
+
this.#inner.delete(key);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return entry.value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Clear all entries.
|
|
84
|
+
*/
|
|
85
|
+
clear() {
|
|
86
|
+
this.#inner.clear();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Entries returns the entries of the map, without the expiration time.
|
|
91
|
+
* @returns an iterator over the entries of the map.
|
|
92
|
+
*/
|
|
93
|
+
entries(): MapIterator<[K, V]> {
|
|
94
|
+
const iterator = this.#inner.entries();
|
|
95
|
+
const generator = function* () {
|
|
96
|
+
for (const [key, value] of iterator) {
|
|
97
|
+
yield [key, value.value] as [K, V];
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
};
|
|
101
|
+
return generator();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Values returns the values of the map, without the expiration time.
|
|
106
|
+
* @returns an iterator over the values of the map.
|
|
107
|
+
*/
|
|
108
|
+
values(): MapIterator<V> {
|
|
109
|
+
const iterator = this.#inner.values();
|
|
110
|
+
const generator = function* () {
|
|
111
|
+
for (const value of iterator) {
|
|
112
|
+
yield value.value;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
};
|
|
116
|
+
return generator();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Keys returns the keys of the map
|
|
121
|
+
* @returns an iterator over the keys of the map.
|
|
122
|
+
*/
|
|
123
|
+
keys(): MapIterator<K> {
|
|
124
|
+
return this.#inner.keys();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* forEach calls the callbackfn on each entry of the map.
|
|
129
|
+
* @param callbackfn to call on each entry
|
|
130
|
+
* @param thisArg to use as this when calling the callbackfn
|
|
131
|
+
*/
|
|
132
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: ExpirableMap<K, V>) {
|
|
133
|
+
for (const [key, value] of this.#inner.entries()) {
|
|
134
|
+
callbackfn.call(thisArg, value.value, key, this);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* has returns true if the key exists and has not expired.
|
|
140
|
+
* @param key K
|
|
141
|
+
* @returns true if the key exists and has not expired.
|
|
142
|
+
*/
|
|
143
|
+
has(key: K): boolean {
|
|
144
|
+
return this.#inner.has(key);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* delete the entry for the given key.
|
|
149
|
+
* @param key K
|
|
150
|
+
* @returns true if the key existed and has been deleted.
|
|
151
|
+
*/
|
|
152
|
+
delete(key: K) {
|
|
153
|
+
return this.#inner.delete(key);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* get size of the map.
|
|
158
|
+
* @returns the size of the map.
|
|
159
|
+
*/
|
|
160
|
+
get size() {
|
|
161
|
+
return this.#inner.size;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PipeArrayBuffer, lebDecode } from '#candid';
|
|
2
|
+
|
|
3
|
+
const MILLISECOND_TO_NANOSECONDS = BigInt(1_000_000);
|
|
4
|
+
|
|
5
|
+
export const decodeLeb128 = (buf: Uint8Array): bigint => {
|
|
6
|
+
return lebDecode(new PipeArrayBuffer(buf));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// time is a LEB128-encoded Nat
|
|
10
|
+
export const decodeTime = (buf: Uint8Array): Date => {
|
|
11
|
+
const timestampNs = decodeLeb128(buf);
|
|
12
|
+
const timestampMs = timestampNs / MILLISECOND_TO_NANOSECONDS;
|
|
13
|
+
return new Date(Number(timestampMs));
|
|
14
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random unsigned 32-bit integer between 0 and 0xffffffff
|
|
3
|
+
* @returns {number} a random number
|
|
4
|
+
*/
|
|
5
|
+
export const randomNumber = (): number => {
|
|
6
|
+
// determine whether browser crypto is available
|
|
7
|
+
if (typeof window !== 'undefined' && !!window.crypto && !!window.crypto.getRandomValues) {
|
|
8
|
+
const array = new Uint32Array(1);
|
|
9
|
+
window.crypto.getRandomValues(array);
|
|
10
|
+
return array[0];
|
|
11
|
+
}
|
|
12
|
+
// A second check for webcrypto, in case it is loaded under global instead of window
|
|
13
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
14
|
+
const array = new Uint32Array(1);
|
|
15
|
+
crypto.getRandomValues(array);
|
|
16
|
+
return array[0];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type nodeCrypto = {
|
|
20
|
+
randomInt: (min: number, max: number) => number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// determine whether node crypto is available
|
|
24
|
+
if (typeof crypto !== 'undefined' && (crypto as unknown as nodeCrypto).randomInt) {
|
|
25
|
+
return (crypto as unknown as nodeCrypto).randomInt(0, 0xffffffff);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// fall back to Math.random
|
|
29
|
+
return Math.floor(Math.random() * 0xffffffff);
|
|
30
|
+
};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Principal } from '#principal';
|
|
2
|
+
import * as cbor from '../cbor.ts';
|
|
3
|
+
import { decodeLeb128 } from '../utils/leb.ts';
|
|
4
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
|
|
5
|
+
import { type DerEncodedPublicKey } from '../auth.ts';
|
|
6
|
+
import {
|
|
7
|
+
type Cert,
|
|
8
|
+
flatten_forks,
|
|
9
|
+
LookupPathStatus,
|
|
10
|
+
lookup_path,
|
|
11
|
+
lookup_subtree,
|
|
12
|
+
type LabeledHashTree,
|
|
13
|
+
LookupSubtreeStatus,
|
|
14
|
+
} from '../certificate.ts';
|
|
15
|
+
import {
|
|
16
|
+
LookupErrorCode,
|
|
17
|
+
DerKeyLengthMismatchErrorCode,
|
|
18
|
+
ProtocolError,
|
|
19
|
+
UnknownError,
|
|
20
|
+
HashTreeDecodeErrorCode,
|
|
21
|
+
} from '../errors.ts';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The root subnet ID for IC mainnet
|
|
25
|
+
*/
|
|
26
|
+
export const IC_ROOT_SUBNET_ID = Principal.fromText(
|
|
27
|
+
'tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe',
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export type SubnetNodeKeys = Map<string, DerEncodedPublicKey>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents the useful information about a subnet
|
|
34
|
+
*/
|
|
35
|
+
export type BaseSubnetStatus = {
|
|
36
|
+
/**
|
|
37
|
+
* The subnet ID
|
|
38
|
+
*/
|
|
39
|
+
subnetId: string;
|
|
40
|
+
/**
|
|
41
|
+
* The node keys of the subnet
|
|
42
|
+
*/
|
|
43
|
+
nodeKeys: SubnetNodeKeys;
|
|
44
|
+
/**
|
|
45
|
+
* Not supported
|
|
46
|
+
*/
|
|
47
|
+
metrics?: never;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Base types of an entry on the status map.
|
|
52
|
+
* An entry of null indicates that the request failed, due to lack of permissions or the result being missing.
|
|
53
|
+
*/
|
|
54
|
+
export type BaseStatus = string | Uint8Array | Date | Uint8Array[] | Principal[] | bigint | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Decode strategy for custom paths
|
|
58
|
+
*/
|
|
59
|
+
export type DecodeStrategy = 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using TextEncoder.
|
|
63
|
+
* @param {string} key the key to use to access the returned value in the status map
|
|
64
|
+
* @param {Uint8Array[]} path the path to the desired value, represented as an array of buffers
|
|
65
|
+
* @param {string} decodeStrategy the strategy to use to decode the returned value
|
|
66
|
+
*/
|
|
67
|
+
export class CustomPath implements CustomPath {
|
|
68
|
+
public key: string;
|
|
69
|
+
public path: Uint8Array[] | string;
|
|
70
|
+
public decodeStrategy: DecodeStrategy;
|
|
71
|
+
constructor(key: string, path: Uint8Array[] | string, decodeStrategy: DecodeStrategy) {
|
|
72
|
+
this.key = key;
|
|
73
|
+
this.path = path;
|
|
74
|
+
this.decodeStrategy = decodeStrategy;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Decode a value based on the specified strategy
|
|
80
|
+
* @param data the raw data to decode
|
|
81
|
+
* @param strategy the decode strategy to use
|
|
82
|
+
* @returns the decoded value
|
|
83
|
+
*/
|
|
84
|
+
export function decodeValue(data: Uint8Array, strategy: DecodeStrategy): BaseStatus {
|
|
85
|
+
switch (strategy) {
|
|
86
|
+
case 'raw':
|
|
87
|
+
return data;
|
|
88
|
+
case 'leb128':
|
|
89
|
+
return decodeLeb128(data);
|
|
90
|
+
case 'cbor':
|
|
91
|
+
return cbor.decode(data);
|
|
92
|
+
case 'hex':
|
|
93
|
+
return bytesToHex(data);
|
|
94
|
+
case 'utf-8':
|
|
95
|
+
return new TextDecoder().decode(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Decode controllers from CBOR-encoded buffer
|
|
101
|
+
* @param buf the CBOR-encoded buffer to decode
|
|
102
|
+
* @returns an array of principal IDs
|
|
103
|
+
*/
|
|
104
|
+
export function decodeControllers(buf: Uint8Array): Principal[] {
|
|
105
|
+
const controllersRaw = cbor.decode<Uint8Array[]>(buf);
|
|
106
|
+
return controllersRaw.map(buf => {
|
|
107
|
+
return Principal.fromUint8Array(buf);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Encode a metadata path for canister metadata queries
|
|
113
|
+
* @param metaPath the metadata path (string or Uint8Array)
|
|
114
|
+
* @param canisterUint8Array the canister ID as Uint8Array
|
|
115
|
+
* @returns the encoded path
|
|
116
|
+
*/
|
|
117
|
+
export function encodeMetadataPath(
|
|
118
|
+
metaPath: string | Uint8Array,
|
|
119
|
+
canisterUint8Array: Uint8Array,
|
|
120
|
+
): Uint8Array[] {
|
|
121
|
+
const encoded = typeof metaPath === 'string' ? utf8ToBytes(metaPath) : metaPath;
|
|
122
|
+
return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('metadata'), encoded];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check if a path object has custom path signature (has 'key' and 'path' properties)
|
|
127
|
+
* @param path the path to check
|
|
128
|
+
* @returns true if the path has custom path signature, false otherwise
|
|
129
|
+
*/
|
|
130
|
+
export function isCustomPath<T>(path: T): path is T & { key: string; path: unknown } {
|
|
131
|
+
return typeof path === 'object' && path !== null && 'key' in path && 'path' in path;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Lookup node keys from a certificate for a given subnet
|
|
136
|
+
* This can be used for both canister and subnet status queries
|
|
137
|
+
* @param certificate the certificate to fetch node keys from
|
|
138
|
+
* @param subnetId the subnet ID to fetch node keys for
|
|
139
|
+
* @returns a map of node IDs to public keys
|
|
140
|
+
*/
|
|
141
|
+
export function lookupNodeKeysFromCertificate(
|
|
142
|
+
certificate: Cert,
|
|
143
|
+
subnetId: Principal,
|
|
144
|
+
): SubnetNodeKeys {
|
|
145
|
+
const subnetLookupResult = lookup_subtree(
|
|
146
|
+
['subnet', subnetId.toUint8Array(), 'node'],
|
|
147
|
+
certificate.tree,
|
|
148
|
+
);
|
|
149
|
+
if (subnetLookupResult.status !== LookupSubtreeStatus.Found) {
|
|
150
|
+
throw ProtocolError.fromCode(new LookupErrorCode('Node not found', subnetLookupResult.status));
|
|
151
|
+
}
|
|
152
|
+
if (subnetLookupResult.value instanceof Uint8Array) {
|
|
153
|
+
throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid node tree'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// The forks are all labeled trees with the <node_id> label
|
|
157
|
+
const nodeForks = flatten_forks(subnetLookupResult.value) as Array<LabeledHashTree>;
|
|
158
|
+
const nodeKeys = new Map<string, DerEncodedPublicKey>();
|
|
159
|
+
|
|
160
|
+
nodeForks.forEach(fork => {
|
|
161
|
+
const node_id = Principal.from(fork[1]).toText();
|
|
162
|
+
const publicKeyLookupResult = lookup_path(['public_key'], fork[2]);
|
|
163
|
+
if (publicKeyLookupResult.status !== LookupPathStatus.Found) {
|
|
164
|
+
throw ProtocolError.fromCode(
|
|
165
|
+
new LookupErrorCode('Public key not found', publicKeyLookupResult.status),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const derEncodedPublicKey = publicKeyLookupResult.value;
|
|
170
|
+
if (derEncodedPublicKey.byteLength !== 44) {
|
|
171
|
+
throw ProtocolError.fromCode(
|
|
172
|
+
new DerKeyLengthMismatchErrorCode(44, derEncodedPublicKey.byteLength),
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
nodeKeys.set(node_id, derEncodedPublicKey as DerEncodedPublicKey);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return nodeKeys;
|
|
180
|
+
}
|
|
@@ -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
|
+
}
|