@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,762 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LookupLabelStatus = exports.LookupSubtreeStatus = exports.LookupPathStatus = exports.Certificate = exports.NodeType = void 0;
|
|
37
|
+
exports.hashTreeToString = hashTreeToString;
|
|
38
|
+
exports.lookupResultToBuffer = lookupResultToBuffer;
|
|
39
|
+
exports.reconstruct = reconstruct;
|
|
40
|
+
exports.domain_sep = domain_sep;
|
|
41
|
+
exports.lookup_path = lookup_path;
|
|
42
|
+
exports.lookup_subtree = lookup_subtree;
|
|
43
|
+
exports.flatten_forks = flatten_forks;
|
|
44
|
+
exports.find_label = find_label;
|
|
45
|
+
exports.check_canister_ranges = check_canister_ranges;
|
|
46
|
+
exports.lookupCanisterRanges = lookupCanisterRanges;
|
|
47
|
+
exports.lookupCanisterRangesFallback = lookupCanisterRangesFallback;
|
|
48
|
+
exports.decodeCanisterRanges = decodeCanisterRanges;
|
|
49
|
+
exports.getSubnetIdFromCertificate = getSubnetIdFromCertificate;
|
|
50
|
+
const cbor = __importStar(require("./cbor.js"));
|
|
51
|
+
const errors_ts_1 = require("./errors.js");
|
|
52
|
+
const _principal_1 = require("../principal/index.js");
|
|
53
|
+
const _candid_1 = require("../candid/index.js");
|
|
54
|
+
const bls = __importStar(require("./utils/bls.js"));
|
|
55
|
+
const leb_ts_1 = require("./utils/leb.js");
|
|
56
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
57
|
+
const buffer_ts_1 = require("./utils/buffer.js");
|
|
58
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
59
|
+
const constants_ts_1 = require("./constants.js");
|
|
60
|
+
const MINUTES_TO_MSEC = 60 * 1000;
|
|
61
|
+
const HOURS_TO_MINUTES = 60;
|
|
62
|
+
const DAYS_TO_HOURS = 24;
|
|
63
|
+
const DAYS_TO_MINUTES = DAYS_TO_HOURS * HOURS_TO_MINUTES;
|
|
64
|
+
const DEFAULT_CERTIFICATE_MAX_AGE_IN_MINUTES = 5;
|
|
65
|
+
const DEFAULT_CERTIFICATE_MAX_MINUTES_IN_FUTURE = 5;
|
|
66
|
+
// For now, we don't want to set a strict timeout on the certificate delegation freshness,
|
|
67
|
+
// so we set the max age really far in the past.
|
|
68
|
+
const DEFAULT_CERTIFICATE_DELEGATION_MAX_AGE_IN_MINUTES = 30 * DAYS_TO_MINUTES;
|
|
69
|
+
var NodeType;
|
|
70
|
+
(function (NodeType) {
|
|
71
|
+
NodeType[NodeType["Empty"] = 0] = "Empty";
|
|
72
|
+
NodeType[NodeType["Fork"] = 1] = "Fork";
|
|
73
|
+
NodeType[NodeType["Labeled"] = 2] = "Labeled";
|
|
74
|
+
NodeType[NodeType["Leaf"] = 3] = "Leaf";
|
|
75
|
+
NodeType[NodeType["Pruned"] = 4] = "Pruned";
|
|
76
|
+
})(NodeType || (exports.NodeType = NodeType = {}));
|
|
77
|
+
/**
|
|
78
|
+
* Make a human readable string out of a hash tree.
|
|
79
|
+
* @param tree The hash tree to convert to a string
|
|
80
|
+
*/
|
|
81
|
+
function hashTreeToString(tree) {
|
|
82
|
+
const indent = (s) => s
|
|
83
|
+
.split('\n')
|
|
84
|
+
.map(x => ' ' + x)
|
|
85
|
+
.join('\n');
|
|
86
|
+
function labelToString(label) {
|
|
87
|
+
const decoder = new TextDecoder(undefined, { fatal: true });
|
|
88
|
+
try {
|
|
89
|
+
return JSON.stringify(decoder.decode(label));
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return `data(...${label.byteLength} bytes)`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
switch (tree[0]) {
|
|
97
|
+
case NodeType.Empty:
|
|
98
|
+
return '()';
|
|
99
|
+
case NodeType.Fork: {
|
|
100
|
+
if (tree[1] instanceof Array && tree[2] instanceof Uint8Array) {
|
|
101
|
+
const left = hashTreeToString(tree[1]);
|
|
102
|
+
const right = hashTreeToString(tree[2]);
|
|
103
|
+
return `sub(\n left:\n${indent(left)}\n---\n right:\n${indent(right)}\n)`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.HashTreeDecodeErrorCode('Invalid tree structure for fork'));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
case NodeType.Labeled: {
|
|
110
|
+
if (tree[1] instanceof Uint8Array && tree[2] instanceof Uint8Array) {
|
|
111
|
+
const label = labelToString(tree[1]);
|
|
112
|
+
const sub = hashTreeToString(tree[2]);
|
|
113
|
+
return `label(\n label:\n${indent(label)}\n sub:\n${indent(sub)}\n)`;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.HashTreeDecodeErrorCode('Invalid tree structure for labeled'));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
case NodeType.Leaf: {
|
|
120
|
+
if (!tree[1]) {
|
|
121
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.HashTreeDecodeErrorCode('Invalid tree structure for leaf'));
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(tree[1])) {
|
|
124
|
+
return JSON.stringify(tree[1]);
|
|
125
|
+
}
|
|
126
|
+
return `leaf(...${tree[1].byteLength} bytes)`;
|
|
127
|
+
}
|
|
128
|
+
case NodeType.Pruned: {
|
|
129
|
+
if (!tree[1]) {
|
|
130
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.HashTreeDecodeErrorCode('Invalid tree structure for pruned'));
|
|
131
|
+
}
|
|
132
|
+
else if (Array.isArray(tree[1])) {
|
|
133
|
+
return JSON.stringify(tree[1]);
|
|
134
|
+
}
|
|
135
|
+
return `pruned(${(0, utils_1.bytesToHex)(new Uint8Array(tree[1]))}`;
|
|
136
|
+
}
|
|
137
|
+
default: {
|
|
138
|
+
return `unknown(${JSON.stringify(tree[0])})`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function isBufferGreaterThan(a, b) {
|
|
143
|
+
for (let i = 0; i < a.length; i++) {
|
|
144
|
+
if (a[i] > b[i]) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
class Certificate {
|
|
151
|
+
#disableTimeVerification = false;
|
|
152
|
+
#agent = undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Create a new instance of a certificate, automatically verifying it.
|
|
155
|
+
* @param {CreateCertificateOptions} options {@link CreateCertificateOptions}
|
|
156
|
+
* @throws if the verification of the certificate fails
|
|
157
|
+
*/
|
|
158
|
+
static async create(options) {
|
|
159
|
+
const cert = Certificate.createUnverified(options);
|
|
160
|
+
await cert.verify();
|
|
161
|
+
return cert;
|
|
162
|
+
}
|
|
163
|
+
static createUnverified(options) {
|
|
164
|
+
return new Certificate(options.certificate, options.rootKey, options.principal, options.blsVerify ?? bls.blsVerify, options.maxAgeInMinutes, options.disableTimeVerification, options.agent);
|
|
165
|
+
}
|
|
166
|
+
constructor(certificate, _rootKey, _principal, _blsVerify, _maxAgeInMinutes = DEFAULT_CERTIFICATE_MAX_AGE_IN_MINUTES, disableTimeVerification = false, agent) {
|
|
167
|
+
this._rootKey = _rootKey;
|
|
168
|
+
this._principal = _principal;
|
|
169
|
+
this._blsVerify = _blsVerify;
|
|
170
|
+
this._maxAgeInMinutes = _maxAgeInMinutes;
|
|
171
|
+
this.#disableTimeVerification = disableTimeVerification;
|
|
172
|
+
this.cert = cbor.decode(certificate);
|
|
173
|
+
if (agent &&
|
|
174
|
+
'getTimeDiffMsecs' in agent &&
|
|
175
|
+
'hasSyncedTime' in agent &&
|
|
176
|
+
'syncTime' in agent &&
|
|
177
|
+
'syncTimeWithSubnet' in agent) {
|
|
178
|
+
this.#agent = agent;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Lookup a path in the certificate tree, using {@link lookup_path}.
|
|
183
|
+
* @param path The path to lookup.
|
|
184
|
+
* @returns The result of the lookup.
|
|
185
|
+
*/
|
|
186
|
+
lookup_path(path) {
|
|
187
|
+
return lookup_path(path, this.cert.tree);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Lookup a subtree in the certificate tree, using {@link lookup_subtree}.
|
|
191
|
+
* @param path The path to lookup.
|
|
192
|
+
* @returns The result of the lookup.
|
|
193
|
+
*/
|
|
194
|
+
lookup_subtree(path) {
|
|
195
|
+
return lookup_subtree(path, this.cert.tree);
|
|
196
|
+
}
|
|
197
|
+
async verify() {
|
|
198
|
+
const rootHash = await reconstruct(this.cert.tree);
|
|
199
|
+
const derKey = await this._checkDelegationAndGetKey(this.cert.delegation);
|
|
200
|
+
const sig = this.cert.signature;
|
|
201
|
+
const key = extractDER(derKey);
|
|
202
|
+
const msg = (0, utils_1.concatBytes)(constants_ts_1.IC_STATE_ROOT_DOMAIN_SEPARATOR, rootHash);
|
|
203
|
+
const lookupTime = lookupResultToBuffer(this.lookup_path(['time']));
|
|
204
|
+
if (!lookupTime) {
|
|
205
|
+
// Should never happen - time is always present in IC certificates
|
|
206
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.CertificateVerificationErrorCode('Certificate does not contain a time'));
|
|
207
|
+
}
|
|
208
|
+
// Certificate time verification checks
|
|
209
|
+
if (!this.#disableTimeVerification) {
|
|
210
|
+
const timeDiffMsecs = this.#agent?.getTimeDiffMsecs() ?? 0;
|
|
211
|
+
const maxAgeInMsec = this._maxAgeInMinutes * MINUTES_TO_MSEC;
|
|
212
|
+
const now = new Date();
|
|
213
|
+
const adjustedNow = now.getTime() + timeDiffMsecs;
|
|
214
|
+
const earliestCertificateTime = adjustedNow - maxAgeInMsec;
|
|
215
|
+
const latestCertificateTime = adjustedNow + DEFAULT_CERTIFICATE_MAX_MINUTES_IN_FUTURE * MINUTES_TO_MSEC;
|
|
216
|
+
const certTime = (0, leb_ts_1.decodeTime)(lookupTime);
|
|
217
|
+
const isCertificateTimePast = certTime.getTime() < earliestCertificateTime;
|
|
218
|
+
const isCertificateTimeFuture = certTime.getTime() > latestCertificateTime;
|
|
219
|
+
if ((isCertificateTimePast || isCertificateTimeFuture) &&
|
|
220
|
+
this.#agent &&
|
|
221
|
+
!this.#agent.hasSyncedTime()) {
|
|
222
|
+
await this._syncTime();
|
|
223
|
+
return await this.verify();
|
|
224
|
+
}
|
|
225
|
+
if (isCertificateTimePast) {
|
|
226
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateTimeErrorCode(this._maxAgeInMinutes, certTime, now, timeDiffMsecs, 'past'));
|
|
227
|
+
}
|
|
228
|
+
else if (isCertificateTimeFuture) {
|
|
229
|
+
if (this.#agent?.hasSyncedTime()) {
|
|
230
|
+
// This case should never happen, and it signals a bug in either the replica or the local system.
|
|
231
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.UnexpectedErrorCode('System time has been synced with the IC network, but certificate is still too far in the future.'));
|
|
232
|
+
}
|
|
233
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateTimeErrorCode(5, certTime, now, timeDiffMsecs, 'future'));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const sigVer = await this._blsVerify(key, sig, msg);
|
|
238
|
+
if (!sigVer) {
|
|
239
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateVerificationErrorCode('Invalid signature'));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateVerificationErrorCode('Signature verification failed', err));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async _checkDelegationAndGetKey(d) {
|
|
247
|
+
if (!d) {
|
|
248
|
+
return this._rootKey;
|
|
249
|
+
}
|
|
250
|
+
const cert = Certificate.createUnverified({
|
|
251
|
+
certificate: d.certificate,
|
|
252
|
+
rootKey: this._rootKey,
|
|
253
|
+
principal: this._principal,
|
|
254
|
+
blsVerify: this._blsVerify,
|
|
255
|
+
disableTimeVerification: this.#disableTimeVerification,
|
|
256
|
+
maxAgeInMinutes: DEFAULT_CERTIFICATE_DELEGATION_MAX_AGE_IN_MINUTES,
|
|
257
|
+
agent: this.#agent,
|
|
258
|
+
});
|
|
259
|
+
if (cert.cert.delegation) {
|
|
260
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.CertificateHasTooManyDelegationsErrorCode());
|
|
261
|
+
}
|
|
262
|
+
await cert.verify();
|
|
263
|
+
let subnetId;
|
|
264
|
+
if (isCanisterPrincipal(this._principal)) {
|
|
265
|
+
const canisterId = this._principal.canisterId;
|
|
266
|
+
subnetId = _principal_1.Principal.fromUint8Array(d.subnet_id);
|
|
267
|
+
const canisterInRange = check_canister_ranges({
|
|
268
|
+
canisterId,
|
|
269
|
+
subnetId,
|
|
270
|
+
tree: cert.cert.tree,
|
|
271
|
+
});
|
|
272
|
+
if (!canisterInRange) {
|
|
273
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateNotAuthorizedErrorCode(canisterId, subnetId));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else if (isSubnetPrincipal(this._principal)) {
|
|
277
|
+
subnetId = this._principal.subnetId;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
281
|
+
}
|
|
282
|
+
const publicKeyLookup = lookupResultToBuffer(cert.lookup_path(['subnet', subnetId.toUint8Array(), 'public_key']));
|
|
283
|
+
if (!publicKeyLookup) {
|
|
284
|
+
if (isSubnetPrincipal(this._principal)) {
|
|
285
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateNotAuthorizedForSubnetErrorCode(subnetId));
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.MissingLookupValueErrorCode(`Could not find subnet key for subnet ID ${subnetId.toText()}`));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return publicKeyLookup;
|
|
292
|
+
}
|
|
293
|
+
async _syncTime() {
|
|
294
|
+
if (!this.#agent) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (isCanisterPrincipal(this._principal)) {
|
|
298
|
+
await this.#agent.syncTime(this._principal.canisterId);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
await this.#agent.syncTimeWithSubnet(this._principal.subnetId);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.Certificate = Certificate;
|
|
306
|
+
function isSubnetPrincipal(principal) {
|
|
307
|
+
return 'subnetId' in principal;
|
|
308
|
+
}
|
|
309
|
+
function isCanisterPrincipal(principal) {
|
|
310
|
+
return 'canisterId' in principal;
|
|
311
|
+
}
|
|
312
|
+
const DER_PREFIX = (0, utils_1.hexToBytes)('308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100');
|
|
313
|
+
const KEY_LENGTH = 96;
|
|
314
|
+
function extractDER(buf) {
|
|
315
|
+
const expectedLength = DER_PREFIX.byteLength + KEY_LENGTH;
|
|
316
|
+
if (buf.byteLength !== expectedLength) {
|
|
317
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.DerKeyLengthMismatchErrorCode(expectedLength, buf.byteLength));
|
|
318
|
+
}
|
|
319
|
+
const prefix = buf.slice(0, DER_PREFIX.byteLength);
|
|
320
|
+
if (!(0, buffer_ts_1.uint8Equals)(prefix, DER_PREFIX)) {
|
|
321
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.DerPrefixMismatchErrorCode(DER_PREFIX, prefix));
|
|
322
|
+
}
|
|
323
|
+
return buf.slice(DER_PREFIX.byteLength);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Utility function to constrain the type of a lookup result
|
|
327
|
+
* @param result the result of a lookup
|
|
328
|
+
* @returns {Uint8Array | undefined} the value if the lookup was found, `undefined` otherwise
|
|
329
|
+
*/
|
|
330
|
+
function lookupResultToBuffer(result) {
|
|
331
|
+
if (result.status !== LookupPathStatus.Found) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (result.value instanceof Uint8Array) {
|
|
335
|
+
return result.value;
|
|
336
|
+
}
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @param t The hash tree to reconstruct
|
|
341
|
+
*/
|
|
342
|
+
async function reconstruct(t) {
|
|
343
|
+
switch (t[0]) {
|
|
344
|
+
case NodeType.Empty:
|
|
345
|
+
return (0, sha2_1.sha256)(domain_sep('ic-hashtree-empty'));
|
|
346
|
+
case NodeType.Pruned:
|
|
347
|
+
return t[1];
|
|
348
|
+
case NodeType.Leaf:
|
|
349
|
+
return (0, sha2_1.sha256)((0, utils_1.concatBytes)(domain_sep('ic-hashtree-leaf'), t[1]));
|
|
350
|
+
case NodeType.Labeled:
|
|
351
|
+
return (0, sha2_1.sha256)((0, utils_1.concatBytes)(domain_sep('ic-hashtree-labeled'), t[1], await reconstruct(t[2])));
|
|
352
|
+
case NodeType.Fork:
|
|
353
|
+
return (0, sha2_1.sha256)((0, utils_1.concatBytes)(domain_sep('ic-hashtree-fork'), await reconstruct(t[1]), await reconstruct(t[2])));
|
|
354
|
+
default:
|
|
355
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Creates a domain separator for hashing by encoding the input string
|
|
360
|
+
* with its length as a prefix.
|
|
361
|
+
* @param s - The input string to encode.
|
|
362
|
+
* @returns A Uint8Array containing the encoded domain separator.
|
|
363
|
+
*/
|
|
364
|
+
function domain_sep(s) {
|
|
365
|
+
const len = new Uint8Array([s.length]);
|
|
366
|
+
const str = new TextEncoder().encode(s);
|
|
367
|
+
return (0, utils_1.concatBytes)(len, str);
|
|
368
|
+
}
|
|
369
|
+
function pathToLabel(path) {
|
|
370
|
+
return (typeof path[0] === 'string' ? (0, utils_1.utf8ToBytes)(path[0]) : path[0]);
|
|
371
|
+
}
|
|
372
|
+
var LookupPathStatus;
|
|
373
|
+
(function (LookupPathStatus) {
|
|
374
|
+
LookupPathStatus["Unknown"] = "Unknown";
|
|
375
|
+
LookupPathStatus["Absent"] = "Absent";
|
|
376
|
+
LookupPathStatus["Found"] = "Found";
|
|
377
|
+
LookupPathStatus["Error"] = "Error";
|
|
378
|
+
})(LookupPathStatus || (exports.LookupPathStatus = LookupPathStatus = {}));
|
|
379
|
+
var LookupSubtreeStatus;
|
|
380
|
+
(function (LookupSubtreeStatus) {
|
|
381
|
+
LookupSubtreeStatus["Absent"] = "Absent";
|
|
382
|
+
LookupSubtreeStatus["Unknown"] = "Unknown";
|
|
383
|
+
LookupSubtreeStatus["Found"] = "Found";
|
|
384
|
+
})(LookupSubtreeStatus || (exports.LookupSubtreeStatus = LookupSubtreeStatus = {}));
|
|
385
|
+
var LookupLabelStatus;
|
|
386
|
+
(function (LookupLabelStatus) {
|
|
387
|
+
LookupLabelStatus["Absent"] = "Absent";
|
|
388
|
+
LookupLabelStatus["Unknown"] = "Unknown";
|
|
389
|
+
LookupLabelStatus["Found"] = "Found";
|
|
390
|
+
LookupLabelStatus["Less"] = "Less";
|
|
391
|
+
LookupLabelStatus["Greater"] = "Greater";
|
|
392
|
+
})(LookupLabelStatus || (exports.LookupLabelStatus = LookupLabelStatus = {}));
|
|
393
|
+
/**
|
|
394
|
+
* Lookup a path in a tree. If the path is a subtree, use {@link lookup_subtree} instead.
|
|
395
|
+
* @param path the path to look up
|
|
396
|
+
* @param tree the tree to search
|
|
397
|
+
* @returns {LookupResult} the result of the lookup
|
|
398
|
+
*/
|
|
399
|
+
function lookup_path(path, tree) {
|
|
400
|
+
if (path.length === 0) {
|
|
401
|
+
switch (tree[0]) {
|
|
402
|
+
case NodeType.Empty: {
|
|
403
|
+
return {
|
|
404
|
+
status: LookupPathStatus.Absent,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
case NodeType.Leaf: {
|
|
408
|
+
if (!tree[1]) {
|
|
409
|
+
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.HashTreeDecodeErrorCode('Invalid tree structure for leaf'));
|
|
410
|
+
}
|
|
411
|
+
if (tree[1] instanceof Uint8Array) {
|
|
412
|
+
return {
|
|
413
|
+
status: LookupPathStatus.Found,
|
|
414
|
+
value: tree[1].slice(tree[1].byteOffset, tree[1].byteLength + tree[1].byteOffset),
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
418
|
+
}
|
|
419
|
+
case NodeType.Pruned: {
|
|
420
|
+
return {
|
|
421
|
+
status: LookupPathStatus.Unknown,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
case NodeType.Labeled:
|
|
425
|
+
case NodeType.Fork: {
|
|
426
|
+
return {
|
|
427
|
+
status: LookupPathStatus.Error,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
default: {
|
|
431
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const label = pathToLabel(path);
|
|
436
|
+
const lookupResult = find_label(label, tree);
|
|
437
|
+
switch (lookupResult.status) {
|
|
438
|
+
case LookupLabelStatus.Found: {
|
|
439
|
+
return lookup_path(path.slice(1), lookupResult.value);
|
|
440
|
+
}
|
|
441
|
+
case LookupLabelStatus.Absent:
|
|
442
|
+
case LookupLabelStatus.Greater:
|
|
443
|
+
case LookupLabelStatus.Less: {
|
|
444
|
+
return {
|
|
445
|
+
status: LookupPathStatus.Absent,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
case LookupLabelStatus.Unknown: {
|
|
449
|
+
return {
|
|
450
|
+
status: LookupPathStatus.Unknown,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
default: {
|
|
454
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Lookup a subtree in a tree.
|
|
460
|
+
* @param path the path to look up
|
|
461
|
+
* @param tree the tree to search
|
|
462
|
+
* @returns {SubtreeLookupResult} the result of the lookup
|
|
463
|
+
*/
|
|
464
|
+
function lookup_subtree(path, tree) {
|
|
465
|
+
if (path.length === 0) {
|
|
466
|
+
return {
|
|
467
|
+
status: LookupSubtreeStatus.Found,
|
|
468
|
+
value: tree,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
const label = pathToLabel(path);
|
|
472
|
+
const lookupResult = find_label(label, tree);
|
|
473
|
+
switch (lookupResult.status) {
|
|
474
|
+
case LookupLabelStatus.Found: {
|
|
475
|
+
return lookup_subtree(path.slice(1), lookupResult.value);
|
|
476
|
+
}
|
|
477
|
+
case LookupLabelStatus.Unknown: {
|
|
478
|
+
return {
|
|
479
|
+
status: LookupSubtreeStatus.Unknown,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
case LookupLabelStatus.Absent:
|
|
483
|
+
case LookupLabelStatus.Greater:
|
|
484
|
+
case LookupLabelStatus.Less: {
|
|
485
|
+
return {
|
|
486
|
+
status: LookupSubtreeStatus.Absent,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
default: {
|
|
490
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* If the tree is a fork, flatten it into an array of trees
|
|
496
|
+
* @param {HashTree} t the tree to flatten
|
|
497
|
+
* @returns {HashTree[]} the flattened tree
|
|
498
|
+
*/
|
|
499
|
+
function flatten_forks(t) {
|
|
500
|
+
switch (t[0]) {
|
|
501
|
+
case NodeType.Empty:
|
|
502
|
+
return [];
|
|
503
|
+
case NodeType.Fork:
|
|
504
|
+
return flatten_forks(t[1]).concat(flatten_forks(t[2]));
|
|
505
|
+
default:
|
|
506
|
+
return [t];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Find a label in a tree
|
|
511
|
+
* @param label the label to find
|
|
512
|
+
* @param tree the tree to search
|
|
513
|
+
* @returns {LabelLookupResult} the result of the label lookup
|
|
514
|
+
*/
|
|
515
|
+
function find_label(label, tree) {
|
|
516
|
+
switch (tree[0]) {
|
|
517
|
+
// if we have a labelled node, compare the node's label to the one we are
|
|
518
|
+
// looking for
|
|
519
|
+
case NodeType.Labeled:
|
|
520
|
+
// if the label we're searching for is greater than this node's label,
|
|
521
|
+
// we need to keep searching
|
|
522
|
+
if (isBufferGreaterThan(label, tree[1])) {
|
|
523
|
+
return {
|
|
524
|
+
status: LookupLabelStatus.Greater,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
// if the label we're searching for is equal this node's label, we can
|
|
528
|
+
// stop searching and return the found node
|
|
529
|
+
if ((0, buffer_ts_1.uint8Equals)(label, tree[1])) {
|
|
530
|
+
return {
|
|
531
|
+
status: LookupLabelStatus.Found,
|
|
532
|
+
value: tree[2],
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
// if the label we're searching for is not greater than or equal to this
|
|
536
|
+
// node's label, then it's less than this node's label, and we can stop
|
|
537
|
+
// searching because we've looked too far
|
|
538
|
+
return {
|
|
539
|
+
status: LookupLabelStatus.Less,
|
|
540
|
+
};
|
|
541
|
+
// if we have a fork node, we need to search both sides, starting with the left
|
|
542
|
+
case NodeType.Fork: {
|
|
543
|
+
// search in the left node
|
|
544
|
+
const leftLookupResult = find_label(label, tree[1]);
|
|
545
|
+
switch (leftLookupResult.status) {
|
|
546
|
+
// if the label we're searching for is greater than the left node lookup,
|
|
547
|
+
// we need to search the right node
|
|
548
|
+
case LookupLabelStatus.Greater: {
|
|
549
|
+
const rightLookupResult = find_label(label, tree[2]);
|
|
550
|
+
// if the label we're searching for is less than the right node lookup,
|
|
551
|
+
// then we can stop searching and say that the label is provably Absent
|
|
552
|
+
if (rightLookupResult.status === LookupLabelStatus.Less) {
|
|
553
|
+
return {
|
|
554
|
+
status: LookupLabelStatus.Absent,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
// if the label we're searching for is less than or equal to the right
|
|
558
|
+
// node lookup, then we let the caller handle it
|
|
559
|
+
return rightLookupResult;
|
|
560
|
+
}
|
|
561
|
+
// if the left node returns an uncertain result, we need to search the
|
|
562
|
+
// right node
|
|
563
|
+
case LookupLabelStatus.Unknown: {
|
|
564
|
+
const rightLookupResult = find_label(label, tree[2]);
|
|
565
|
+
// if the label we're searching for is less than the right node lookup,
|
|
566
|
+
// then we also need to return an uncertain result
|
|
567
|
+
if (rightLookupResult.status === LookupLabelStatus.Less) {
|
|
568
|
+
return {
|
|
569
|
+
status: LookupLabelStatus.Unknown,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
// if the label we're searching for is less than or equal to the right
|
|
573
|
+
// node lookup, then we let the caller handle it
|
|
574
|
+
return rightLookupResult;
|
|
575
|
+
}
|
|
576
|
+
// if the label we're searching for is not greater than the left node
|
|
577
|
+
// lookup, or the result is not uncertain, we stop searching and return
|
|
578
|
+
// whatever the result of the left node lookup was, which can be either
|
|
579
|
+
// Found or Absent
|
|
580
|
+
default: {
|
|
581
|
+
return leftLookupResult;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// if we encounter a Pruned node, we can't know for certain if the label
|
|
586
|
+
// we're searching for is present or not
|
|
587
|
+
case NodeType.Pruned:
|
|
588
|
+
return {
|
|
589
|
+
status: LookupLabelStatus.Unknown,
|
|
590
|
+
};
|
|
591
|
+
// if the current node is Empty, or a Leaf, we can stop searching because
|
|
592
|
+
// we know for sure that the label we're searching for is not present
|
|
593
|
+
default:
|
|
594
|
+
return {
|
|
595
|
+
status: LookupLabelStatus.Absent,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Ported from https://github.com/dfinity/response-verification/blob/a4b8b46bcf93f44ac30b5698e60bfd245e33ad4e/packages/ic-certification/src/hash_tree/mod.rs#L527-L541.
|
|
601
|
+
* @param path the path to prepend to the paths of the tree
|
|
602
|
+
* @param tree the tree to list the paths of
|
|
603
|
+
* @returns the paths of the tree
|
|
604
|
+
*/
|
|
605
|
+
function list_paths(path, tree) {
|
|
606
|
+
switch (tree[0]) {
|
|
607
|
+
case NodeType.Empty | NodeType.Pruned: {
|
|
608
|
+
return [];
|
|
609
|
+
}
|
|
610
|
+
case NodeType.Leaf: {
|
|
611
|
+
return [path];
|
|
612
|
+
}
|
|
613
|
+
case NodeType.Fork: {
|
|
614
|
+
return list_paths(path, tree[1]).concat(list_paths(path, tree[2]));
|
|
615
|
+
}
|
|
616
|
+
case NodeType.Labeled: {
|
|
617
|
+
const label = tree[1];
|
|
618
|
+
const subtree = tree[2];
|
|
619
|
+
const pathWithLabel = [...path, label];
|
|
620
|
+
return list_paths(pathWithLabel, subtree);
|
|
621
|
+
}
|
|
622
|
+
default: {
|
|
623
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Check if a canister ID falls within the canister ranges of a given subnet
|
|
629
|
+
* @param params the parameters with which to check the canister ranges
|
|
630
|
+
* @param params.canisterId the canister ID to check
|
|
631
|
+
* @param params.subnetId the subnet ID from which to check the canister ranges
|
|
632
|
+
* @param params.tree the hash tree in which to lookup the subnet's canister ranges
|
|
633
|
+
* @returns {boolean} `true` if the canister is in the range, `false` otherwise
|
|
634
|
+
*/
|
|
635
|
+
function check_canister_ranges(params) {
|
|
636
|
+
const rangesLookupValue = lookupCanisterRanges(params);
|
|
637
|
+
const ranges = decodeCanisterRanges(rangesLookupValue);
|
|
638
|
+
const { canisterId } = params;
|
|
639
|
+
const canisterInRange = ranges.some(r => r[0].ltEq(canisterId) && r[1].gtEq(canisterId));
|
|
640
|
+
return canisterInRange;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Lookup the canister ranges using the `/canister_ranges/<subnet_id>/<ranges>` path.
|
|
644
|
+
* Certificates returned by `/api/v4/canister/<effective_canister_id>/call`
|
|
645
|
+
* and `/api/v3/canister/<effective_canister_id>/read_state` use this path.
|
|
646
|
+
*
|
|
647
|
+
* If the new lookup is not found, it tries the fallback lookup with {@link lookupCanisterRangesFallback}.
|
|
648
|
+
* @param params the parameters with which to lookup the canister ranges
|
|
649
|
+
* @param params.subnetId the subnet ID to lookup the canister ranges for
|
|
650
|
+
* @param params.tree the tree to search
|
|
651
|
+
* @param params.canisterId the canister ID to check
|
|
652
|
+
* @returns the encoded canister ranges. Use {@link decodeCanisterRanges} to decode them.
|
|
653
|
+
* @see https://internetcomputer.org/docs/references/ic-interface-spec#http-read-state
|
|
654
|
+
* @see https://internetcomputer.org/docs/references/ic-interface-spec#state-tree-canister-ranges
|
|
655
|
+
*/
|
|
656
|
+
function lookupCanisterRanges(params) {
|
|
657
|
+
const { subnetId, tree, canisterId } = params;
|
|
658
|
+
const canisterRangeShardsLookup = lookup_subtree(['canister_ranges', subnetId.toUint8Array()], tree);
|
|
659
|
+
if (canisterRangeShardsLookup.status !== LookupSubtreeStatus.Found) {
|
|
660
|
+
return lookupCanisterRangesFallback(subnetId, tree);
|
|
661
|
+
}
|
|
662
|
+
const canisterRangeShards = canisterRangeShardsLookup.value;
|
|
663
|
+
const shardPaths = getCanisterRangeShardPaths(canisterRangeShards);
|
|
664
|
+
if (shardPaths.length === 0) {
|
|
665
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.CertificateNotAuthorizedErrorCode(canisterId, subnetId));
|
|
666
|
+
}
|
|
667
|
+
shardPaths.sort(_candid_1.compare);
|
|
668
|
+
const shardDivision = getCanisterRangeShardPartitionPoint(shardPaths, canisterId);
|
|
669
|
+
const maxPotentialShard = shardPaths[shardDivision];
|
|
670
|
+
const canisterRange = getCanisterRangeFromShards(maxPotentialShard, canisterRangeShards);
|
|
671
|
+
return canisterRange;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Lookup the canister ranges using the `/subnet/<subnet_id>/canister_ranges` path.
|
|
675
|
+
* Certificates returned by `/api/v3/canister/<effective_canister_id>/call`
|
|
676
|
+
* and `/api/v2/canister/<effective_canister_id>/read_state` use this path.
|
|
677
|
+
* @param subnetId the subnet ID to lookup the canister ranges for
|
|
678
|
+
* @param tree the tree to search
|
|
679
|
+
* @returns the encoded canister ranges. Use {@link decodeCanisterRanges} to decode them.
|
|
680
|
+
* @see https://internetcomputer.org/docs/references/ic-interface-spec#http-read-state
|
|
681
|
+
*/
|
|
682
|
+
function lookupCanisterRangesFallback(subnetId, tree) {
|
|
683
|
+
const lookupResult = lookup_path(['subnet', subnetId.toUint8Array(), 'canister_ranges'], tree);
|
|
684
|
+
if (lookupResult.status !== LookupPathStatus.Found) {
|
|
685
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.LookupErrorCode(`Could not find canister ranges for subnet ${subnetId.toText()}`, lookupResult.status));
|
|
686
|
+
}
|
|
687
|
+
return lookupResult.value;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Decode canister ranges from CBOR-encoded buffer
|
|
691
|
+
* @param lookupValue the CBOR-encoded value read from the certificate
|
|
692
|
+
* @returns an array of canister range tuples [start, end]
|
|
693
|
+
*/
|
|
694
|
+
function decodeCanisterRanges(lookupValue) {
|
|
695
|
+
const ranges_arr = cbor.decode(lookupValue);
|
|
696
|
+
const ranges = ranges_arr.map(v => [
|
|
697
|
+
_principal_1.Principal.fromUint8Array(v[0]),
|
|
698
|
+
_principal_1.Principal.fromUint8Array(v[1]),
|
|
699
|
+
]);
|
|
700
|
+
return ranges;
|
|
701
|
+
}
|
|
702
|
+
function getCanisterRangeShardPaths(canisterRangeShards) {
|
|
703
|
+
const shardPaths = [];
|
|
704
|
+
for (const path of list_paths([], canisterRangeShards)) {
|
|
705
|
+
const firstLabel = path[0];
|
|
706
|
+
if (!firstLabel) {
|
|
707
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.CertificateVerificationErrorCode('Path is invalid'));
|
|
708
|
+
}
|
|
709
|
+
shardPaths.push(firstLabel);
|
|
710
|
+
}
|
|
711
|
+
return shardPaths;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Finds the partition point that divides shard paths into two groups based on canister ID comparison.
|
|
715
|
+
* Uses binary search to partition the array where:
|
|
716
|
+
* - Elements at indices [0, partitionPoint) have values >= canisterId
|
|
717
|
+
* - Elements at indices [partitionPoint, length) have values < canisterId
|
|
718
|
+
* @param shardPaths Sorted array of shard paths to search through
|
|
719
|
+
* @param canisterId The canister ID to compare against
|
|
720
|
+
* @returns The index of the first shard that is less than the canister ID, or shardPaths.length if all shards are >= canisterId
|
|
721
|
+
*/
|
|
722
|
+
function getCanisterRangeShardPartitionPoint(shardPaths, canisterId) {
|
|
723
|
+
const canisterIdBytes = canisterId.toUint8Array();
|
|
724
|
+
let left = 0;
|
|
725
|
+
let right = shardPaths.length;
|
|
726
|
+
// Binary search for the first element where shard < canisterId
|
|
727
|
+
while (left < right) {
|
|
728
|
+
const mid = Math.floor((left + right) / 2);
|
|
729
|
+
if ((0, _candid_1.compare)(shardPaths[mid], canisterIdBytes) <= 0) {
|
|
730
|
+
// Found an element <= canisterId, search left half for earlier occurrence
|
|
731
|
+
right = mid;
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
// Element is > canisterId, search right half
|
|
735
|
+
left = mid + 1;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return left;
|
|
739
|
+
}
|
|
740
|
+
function getCanisterRangeFromShards(maxShardPath, canisterRangeShards) {
|
|
741
|
+
const canisterRange = lookup_path([maxShardPath], canisterRangeShards);
|
|
742
|
+
if (canisterRange.status !== LookupPathStatus.Found) {
|
|
743
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.LookupErrorCode(`Could not find canister range for shard ${maxShardPath.toString()}`, canisterRange.status));
|
|
744
|
+
}
|
|
745
|
+
return canisterRange.value;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Get the subnet ID from a certificate
|
|
749
|
+
* If the certificate has a delegation, it returns the subnet ID from the delegation.
|
|
750
|
+
* If the certificate has no delegation, it returns the root subnet ID.
|
|
751
|
+
* @param certificate the certificate to get the subnet ID from
|
|
752
|
+
* @param rootKey the root key to use to get the subnet ID
|
|
753
|
+
* @returns the subnet ID
|
|
754
|
+
*/
|
|
755
|
+
function getSubnetIdFromCertificate(certificate, rootKey) {
|
|
756
|
+
if (certificate.delegation) {
|
|
757
|
+
return _principal_1.Principal.fromUint8Array(certificate.delegation.subnet_id);
|
|
758
|
+
}
|
|
759
|
+
// If certificate has no delegation, it comes from the root subnet
|
|
760
|
+
return _principal_1.Principal.selfAuthenticating(rootKey);
|
|
761
|
+
}
|
|
762
|
+
//# sourceMappingURL=certificate.js.map
|