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