@icp-sdk/core 4.2.2 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent/actor.d.ts +203 -0
- package/lib/cjs/agent/actor.d.ts.map +1 -0
- package/lib/cjs/agent/actor.js +341 -0
- package/lib/cjs/agent/actor.js.map +1 -0
- package/lib/cjs/agent/agent/api.d.ts +216 -0
- package/lib/cjs/agent/agent/api.d.ts.map +1 -0
- package/lib/cjs/agent/agent/api.js +39 -0
- package/lib/cjs/agent/agent/api.js.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +19 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +171 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/index.js +1079 -0
- package/lib/cjs/agent/agent/http/index.js.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.js +135 -0
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
- package/lib/cjs/agent/agent/http/types.d.ts +81 -0
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/types.js +43 -0
- package/lib/cjs/agent/agent/http/types.js.map +1 -0
- package/lib/cjs/agent/agent/index.d.ts +3 -0
- package/lib/cjs/agent/agent/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/index.js +19 -0
- package/lib/cjs/agent/agent/index.js.map +1 -0
- package/lib/cjs/agent/auth.d.ts +91 -0
- package/lib/cjs/agent/auth.d.ts.map +1 -0
- package/lib/cjs/agent/auth.js +65 -0
- package/lib/cjs/agent/auth.js.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts +93 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.js +301 -0
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
- package/lib/cjs/agent/cbor.d.ts +26 -0
- package/lib/cjs/agent/cbor.d.ts.map +1 -0
- package/lib/cjs/agent/cbor.js +93 -0
- package/lib/cjs/agent/cbor.js.map +1 -0
- package/lib/cjs/agent/certificate.d.ts +228 -0
- package/lib/cjs/agent/certificate.d.ts.map +1 -0
- package/lib/cjs/agent/certificate.js +591 -0
- package/lib/cjs/agent/certificate.js.map +1 -0
- package/lib/cjs/agent/constants.d.ts +14 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -0
- package/lib/cjs/agent/constants.js +18 -0
- package/lib/cjs/agent/constants.js.map +1 -0
- package/lib/cjs/agent/der.d.ts +34 -0
- package/lib/cjs/agent/der.d.ts.map +1 -0
- package/lib/cjs/agent/der.js +175 -0
- package/lib/cjs/agent/der.js.map +1 -0
- package/lib/cjs/agent/errors.d.ts +380 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -0
- package/lib/cjs/agent/errors.js +733 -0
- package/lib/cjs/agent/errors.js.map +1 -0
- package/lib/cjs/agent/fetch_candid.d.ts +9 -0
- package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
- package/lib/cjs/agent/fetch_candid.js +69 -0
- package/lib/cjs/agent/fetch_candid.js.map +1 -0
- package/lib/cjs/agent/index.d.ts +31 -1
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +59 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +24 -0
- package/lib/cjs/agent/observable.d.ts.map +1 -0
- package/lib/cjs/agent/observable.js +34 -0
- package/lib/cjs/agent/observable.js.map +1 -0
- package/lib/cjs/agent/polling/backoff.d.ts +50 -0
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
- package/lib/cjs/agent/polling/backoff.js +90 -0
- package/lib/cjs/agent/polling/backoff.js.map +1 -0
- package/lib/cjs/agent/polling/index.d.ts +63 -0
- package/lib/cjs/agent/polling/index.d.ts.map +1 -0
- package/lib/cjs/agent/polling/index.js +183 -0
- package/lib/cjs/agent/polling/index.js.map +1 -0
- package/lib/cjs/agent/polling/strategy.d.ts +52 -0
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
- package/lib/cjs/agent/polling/strategy.js +104 -0
- package/lib/cjs/agent/polling/strategy.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +16 -0
- package/lib/cjs/agent/public_key.d.ts.map +1 -0
- package/lib/cjs/agent/public_key.js +52 -0
- package/lib/cjs/agent/public_key.js.map +1 -0
- package/lib/cjs/agent/request_id.d.ts +24 -0
- package/lib/cjs/agent/request_id.d.ts.map +1 -0
- package/lib/cjs/agent/request_id.js +88 -0
- package/lib/cjs/agent/request_id.js.map +1 -0
- package/lib/cjs/agent/utils/bls.d.ts +10 -0
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
- package/lib/cjs/agent/utils/bls.js +20 -0
- package/lib/cjs/agent/utils/bls.js.map +1 -0
- package/lib/cjs/agent/utils/buffer.d.ts +22 -0
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/agent/utils/buffer.js +55 -0
- package/lib/cjs/agent/utils/buffer.js.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.js +148 -0
- package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
- package/lib/cjs/agent/utils/leb.d.ts +3 -0
- package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
- package/lib/cjs/agent/utils/leb.js +17 -0
- package/lib/cjs/agent/utils/leb.js.map +1 -0
- package/lib/cjs/agent/utils/random.d.ts +6 -0
- package/lib/cjs/agent/utils/random.d.ts.map +1 -0
- package/lib/cjs/agent/utils/random.js +29 -0
- package/lib/cjs/agent/utils/random.js.map +1 -0
- package/lib/cjs/candid/candid-core.d.ts +72 -0
- package/lib/cjs/candid/candid-core.d.ts.map +1 -0
- package/lib/cjs/candid/candid-core.js +251 -0
- package/lib/cjs/candid/candid-core.js.map +1 -0
- package/lib/cjs/candid/candid-ui.d.ts +35 -0
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
- package/lib/cjs/candid/candid-ui.js +317 -0
- package/lib/cjs/candid/candid-ui.js.map +1 -0
- package/lib/cjs/candid/idl.d.ts +579 -0
- package/lib/cjs/candid/idl.d.ts.map +1 -0
- package/lib/cjs/candid/idl.js +2228 -0
- package/lib/cjs/candid/idl.js.map +1 -0
- package/lib/cjs/candid/index.d.ts +11 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +33 -1
- package/lib/cjs/candid/index.js.map +1 -1
- package/lib/cjs/candid/types.d.ts +6 -0
- package/lib/cjs/candid/types.d.ts.map +1 -0
- package/lib/cjs/candid/types.js +4 -0
- package/lib/cjs/candid/types.js.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.js +30 -0
- package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +86 -0
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/candid/utils/buffer.js +191 -0
- package/lib/cjs/candid/utils/buffer.js.map +1 -0
- package/lib/cjs/candid/utils/hash.d.ts +7 -0
- package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
- package/lib/cjs/candid/utils/hash.js +33 -0
- package/lib/cjs/candid/utils/hash.js.map +1 -0
- package/lib/cjs/candid/utils/leb128.d.ts +65 -0
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
- package/lib/cjs/candid/utils/leb128.js +228 -0
- package/lib/cjs/candid/utils/leb128.js.map +1 -0
- package/lib/cjs/identity/identity/delegation.d.ts +164 -0
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
- package/lib/cjs/identity/identity/delegation.js +302 -0
- package/lib/cjs/identity/identity/delegation.js.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.js +117 -0
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
- package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ed25519.js +200 -0
- package/lib/cjs/identity/identity/ed25519.js.map +1 -0
- package/lib/cjs/identity/identity/partial.d.ts +34 -0
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
- package/lib/cjs/identity/identity/partial.js +54 -0
- package/lib/cjs/identity/identity/partial.js.map +1 -0
- package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/cjs/identity/identity/webauthn.js +197 -0
- package/lib/cjs/identity/identity/webauthn.js.map +1 -0
- package/lib/cjs/identity/index.d.ts +15 -1
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +24 -1
- package/lib/cjs/identity/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/der.js +165 -0
- package/lib/cjs/identity/secp256k1/der.js.map +1 -0
- package/lib/cjs/identity/secp256k1/index.d.ts +4 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +4 -1
- package/lib/cjs/identity/secp256k1/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/pem.js +75 -0
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/cjs/principal/index.d.ts +3 -1
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +7 -1
- package/lib/cjs/principal/index.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +50 -0
- package/lib/cjs/principal/principal.d.ts.map +1 -0
- package/lib/cjs/principal/principal.js +148 -0
- package/lib/cjs/principal/principal.js.map +1 -0
- package/lib/cjs/principal/utils/base32.d.ts +10 -0
- package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
- package/lib/cjs/principal/utils/base32.js +90 -0
- package/lib/cjs/principal/utils/base32.js.map +1 -0
- package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
- package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/cjs/principal/utils/getCrc.js +53 -0
- package/lib/cjs/principal/utils/getCrc.js.map +1 -0
- package/lib/esm/agent/actor.d.ts +203 -0
- package/lib/esm/agent/actor.d.ts.map +1 -0
- package/lib/esm/agent/actor.js +337 -0
- package/lib/esm/agent/actor.js.map +1 -0
- package/lib/esm/agent/agent/api.d.ts +216 -0
- package/lib/esm/agent/agent/api.d.ts.map +1 -0
- package/lib/esm/agent/agent/api.js +34 -0
- package/lib/esm/agent/agent/api.js.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +16 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +171 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/index.js +1037 -0
- package/lib/esm/agent/agent/http/index.js.map +1 -0
- package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/transforms.js +128 -0
- package/lib/esm/agent/agent/http/transforms.js.map +1 -0
- package/lib/esm/agent/agent/http/types.d.ts +81 -0
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/types.js +39 -0
- package/lib/esm/agent/agent/http/types.js.map +1 -0
- package/lib/esm/agent/agent/index.d.ts +3 -0
- package/lib/esm/agent/agent/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/index.js +3 -0
- package/lib/esm/agent/agent/index.js.map +1 -0
- package/lib/esm/agent/auth.d.ts +91 -0
- package/lib/esm/agent/auth.d.ts.map +1 -0
- package/lib/esm/agent/auth.js +59 -0
- package/lib/esm/agent/auth.js.map +1 -0
- package/lib/esm/agent/canister-env/index.d.ts +110 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +110 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +93 -0
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/canisterStatus/index.js +261 -0
- package/lib/esm/agent/canisterStatus/index.js.map +1 -0
- package/lib/esm/agent/cbor.d.ts +26 -0
- package/lib/esm/agent/cbor.d.ts.map +1 -0
- package/lib/esm/agent/cbor.js +54 -0
- package/lib/esm/agent/cbor.js.map +1 -0
- package/lib/esm/agent/certificate.d.ts +228 -0
- package/lib/esm/agent/certificate.d.ts.map +1 -0
- package/lib/esm/agent/certificate.js +545 -0
- package/lib/esm/agent/certificate.js.map +1 -0
- package/lib/esm/agent/constants.d.ts +14 -0
- package/lib/esm/agent/constants.d.ts.map +1 -0
- package/lib/esm/agent/constants.js +15 -0
- package/lib/esm/agent/constants.js.map +1 -0
- package/lib/esm/agent/der.d.ts +34 -0
- package/lib/esm/agent/der.d.ts.map +1 -0
- package/lib/esm/agent/der.js +166 -0
- package/lib/esm/agent/der.js.map +1 -0
- package/lib/esm/agent/errors.d.ts +380 -0
- package/lib/esm/agent/errors.d.ts.map +1 -0
- package/lib/esm/agent/errors.js +678 -0
- package/lib/esm/agent/errors.js.map +1 -0
- package/lib/esm/agent/fetch_candid.d.ts +9 -0
- package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
- package/lib/esm/agent/fetch_candid.js +33 -0
- package/lib/esm/agent/fetch_candid.js.map +1 -0
- package/lib/esm/agent/index.d.ts +31 -1
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +31 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +24 -0
- package/lib/esm/agent/observable.d.ts.map +1 -0
- package/lib/esm/agent/observable.js +29 -0
- package/lib/esm/agent/observable.js.map +1 -0
- package/lib/esm/agent/polling/backoff.d.ts +50 -0
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
- package/lib/esm/agent/polling/backoff.js +85 -0
- package/lib/esm/agent/polling/backoff.js.map +1 -0
- package/lib/esm/agent/polling/index.d.ts +63 -0
- package/lib/esm/agent/polling/index.d.ts.map +1 -0
- package/lib/esm/agent/polling/index.js +144 -0
- package/lib/esm/agent/polling/index.js.map +1 -0
- package/lib/esm/agent/polling/strategy.d.ts +52 -0
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
- package/lib/esm/agent/polling/strategy.js +94 -0
- package/lib/esm/agent/polling/strategy.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +16 -0
- package/lib/esm/agent/public_key.d.ts.map +1 -0
- package/lib/esm/agent/public_key.js +48 -0
- package/lib/esm/agent/public_key.js.map +1 -0
- package/lib/esm/agent/request_id.d.ts +24 -0
- package/lib/esm/agent/request_id.d.ts.map +1 -0
- package/lib/esm/agent/request_id.js +83 -0
- package/lib/esm/agent/request_id.js.map +1 -0
- package/lib/esm/agent/utils/bls.d.ts +10 -0
- package/lib/esm/agent/utils/bls.d.ts.map +1 -0
- package/lib/esm/agent/utils/bls.js +17 -0
- package/lib/esm/agent/utils/bls.js.map +1 -0
- package/lib/esm/agent/utils/buffer.d.ts +22 -0
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
- package/lib/esm/agent/utils/buffer.js +50 -0
- package/lib/esm/agent/utils/buffer.js.map +1 -0
- package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableMap.js +144 -0
- package/lib/esm/agent/utils/expirableMap.js.map +1 -0
- package/lib/esm/agent/utils/leb.d.ts +3 -0
- package/lib/esm/agent/utils/leb.d.ts.map +1 -0
- package/lib/esm/agent/utils/leb.js +12 -0
- package/lib/esm/agent/utils/leb.js.map +1 -0
- package/lib/esm/agent/utils/random.d.ts +6 -0
- package/lib/esm/agent/utils/random.d.ts.map +1 -0
- package/lib/esm/agent/utils/random.js +25 -0
- package/lib/esm/agent/utils/random.js.map +1 -0
- package/lib/esm/candid/candid-core.d.ts +72 -0
- package/lib/esm/candid/candid-core.d.ts.map +1 -0
- package/lib/esm/candid/candid-core.js +241 -0
- package/lib/esm/candid/candid-core.js.map +1 -0
- package/lib/esm/candid/candid-ui.d.ts +35 -0
- package/lib/esm/candid/candid-ui.d.ts.map +1 -0
- package/lib/esm/candid/candid-ui.js +272 -0
- package/lib/esm/candid/candid-ui.js.map +1 -0
- package/lib/esm/candid/idl.d.ts +579 -0
- package/lib/esm/candid/idl.d.ts.map +1 -0
- package/lib/esm/candid/idl.js +2189 -0
- package/lib/esm/candid/idl.js.map +1 -0
- package/lib/esm/candid/index.d.ts +11 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +10 -1
- package/lib/esm/candid/index.js.map +1 -1
- package/lib/esm/candid/types.d.ts +6 -0
- package/lib/esm/candid/types.d.ts.map +1 -0
- package/lib/esm/candid/types.js +3 -0
- package/lib/esm/candid/types.js.map +1 -0
- package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
- package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/esm/candid/utils/bigint-math.js +26 -0
- package/lib/esm/candid/utils/bigint-math.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +86 -0
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
- package/lib/esm/candid/utils/buffer.js +182 -0
- package/lib/esm/candid/utils/buffer.js.map +1 -0
- package/lib/esm/candid/utils/hash.d.ts +7 -0
- package/lib/esm/candid/utils/hash.d.ts.map +1 -0
- package/lib/esm/candid/utils/hash.js +30 -0
- package/lib/esm/candid/utils/hash.js.map +1 -0
- package/lib/esm/candid/utils/leb128.d.ts +65 -0
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
- package/lib/esm/candid/utils/leb128.js +216 -0
- package/lib/esm/candid/utils/leb128.js.map +1 -0
- package/lib/esm/identity/identity/delegation.d.ts +164 -0
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
- package/lib/esm/identity/identity/delegation.js +294 -0
- package/lib/esm/identity/identity/delegation.js.map +1 -0
- package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/esm/identity/identity/ecdsa.js +112 -0
- package/lib/esm/identity/identity/ecdsa.js.map +1 -0
- package/lib/esm/identity/identity/ed25519.d.ts +67 -0
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/esm/identity/identity/ed25519.js +195 -0
- package/lib/esm/identity/identity/ed25519.js.map +1 -0
- package/lib/esm/identity/identity/partial.d.ts +34 -0
- package/lib/esm/identity/identity/partial.d.ts.map +1 -0
- package/lib/esm/identity/identity/partial.js +50 -0
- package/lib/esm/identity/identity/partial.js.map +1 -0
- package/lib/esm/identity/identity/webauthn.d.ts +51 -0
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/esm/identity/identity/webauthn.js +192 -0
- package/lib/esm/identity/identity/webauthn.js.map +1 -0
- package/lib/esm/identity/index.d.ts +15 -1
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +17 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +33 -0
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/der.js +156 -0
- package/lib/esm/identity/secp256k1/der.js.map +1 -0
- package/lib/esm/identity/secp256k1/index.d.ts +4 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +4 -1
- package/lib/esm/identity/secp256k1/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/pem.js +39 -0
- package/lib/esm/identity/secp256k1/pem.js.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/esm/principal/index.d.ts +3 -1
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +3 -1
- package/lib/esm/principal/index.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +50 -0
- package/lib/esm/principal/principal.d.ts.map +1 -0
- package/lib/esm/principal/principal.js +144 -0
- package/lib/esm/principal/principal.js.map +1 -0
- package/lib/esm/principal/utils/base32.d.ts +10 -0
- package/lib/esm/principal/utils/base32.d.ts.map +1 -0
- package/lib/esm/principal/utils/base32.js +86 -0
- package/lib/esm/principal/utils/base32.js.map +1 -0
- package/lib/esm/principal/utils/getCrc.d.ts +6 -0
- package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/esm/principal/utils/getCrc.js +50 -0
- package/lib/esm/principal/utils/getCrc.js.map +1 -0
- package/package.json +17 -11
- package/src/agent/actor.ts +576 -0
- package/src/agent/agent/api.ts +262 -0
- package/src/agent/agent/http/index.ts +1405 -0
- package/src/agent/agent/http/transforms.ts +158 -0
- package/src/agent/agent/http/types.ts +126 -0
- package/src/agent/agent/index.ts +2 -0
- package/src/agent/auth.ts +147 -0
- package/src/agent/canister-env/index.ts +191 -1
- package/src/agent/canisterStatus/index.ts +412 -0
- package/src/agent/cbor.ts +63 -0
- package/src/agent/certificate.ts +841 -0
- package/src/agent/constants.ts +19 -0
- package/src/agent/der.ts +170 -0
- package/src/agent/errors.ts +868 -0
- package/src/agent/fetch_candid.ts +37 -0
- package/src/agent/index.ts +37 -1
- package/src/agent/observable.ts +49 -0
- package/src/agent/polling/backoff.ts +130 -0
- package/src/agent/polling/index.ts +250 -0
- package/src/agent/polling/strategy.ts +144 -0
- package/src/agent/public_key.ts +65 -0
- package/src/agent/request_id.ts +92 -0
- package/src/agent/utils/bls.ts +18 -0
- package/src/agent/utils/buffer.ts +60 -0
- package/src/agent/utils/expirableMap.ts +163 -0
- package/src/agent/utils/leb.ts +14 -0
- package/src/agent/utils/random.ts +30 -0
- package/src/candid/candid-core.ts +276 -0
- package/src/candid/candid-ui.ts +289 -0
- package/src/candid/idl.ts +2556 -0
- package/src/candid/index.ts +16 -1
- package/src/candid/types.ts +7 -0
- package/src/candid/utils/bigint-math.ts +26 -0
- package/src/candid/utils/buffer.ts +221 -0
- package/src/candid/utils/hash.ts +31 -0
- package/src/candid/utils/leb128.ts +234 -0
- package/src/identity/identity/delegation.ts +411 -0
- package/src/identity/identity/ecdsa.ts +158 -0
- package/src/identity/identity/ed25519.ts +239 -0
- package/src/identity/identity/partial.ts +60 -0
- package/src/identity/identity/webauthn.ts +265 -0
- package/src/identity/index.ts +19 -1
- package/src/identity/secp256k1/der.ts +156 -0
- package/src/identity/secp256k1/index.ts +5 -1
- package/src/identity/secp256k1/pem.ts +40 -0
- package/src/identity/secp256k1/secp256k1.ts +270 -0
- package/src/package.json +4 -0
- package/src/principal/index.ts +3 -1
- package/src/principal/principal.ts +171 -0
- package/src/principal/utils/base32.ts +101 -0
- package/src/principal/utils/getCrc.ts +52 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Principal } from '#principal';
|
|
2
|
+
import * as CanisterStatus from './canisterStatus/index.ts';
|
|
3
|
+
import { IDL } from '#candid';
|
|
4
|
+
import { HttpAgent } from './agent/http/index.ts';
|
|
5
|
+
import { Actor, type ActorSubclass } from './actor.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the Candid interface for the specified canister.
|
|
9
|
+
* @param canisterId A string corresponding to the canister ID
|
|
10
|
+
* @param agent The agent to use for the request (usually an `HttpAgent`)
|
|
11
|
+
* @returns Candid source code
|
|
12
|
+
*/
|
|
13
|
+
export async function fetchCandid(canisterId: string, agent?: HttpAgent): Promise<string> {
|
|
14
|
+
if (!agent) {
|
|
15
|
+
// Create an anonymous `HttpAgent` (adapted from Candid UI)
|
|
16
|
+
agent = await HttpAgent.create();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Attempt to use canister metadata
|
|
20
|
+
const status = await CanisterStatus.request({
|
|
21
|
+
agent,
|
|
22
|
+
canisterId: Principal.fromText(canisterId),
|
|
23
|
+
paths: ['candid'],
|
|
24
|
+
});
|
|
25
|
+
const candid = status.get('candid') as string | undefined;
|
|
26
|
+
if (candid) {
|
|
27
|
+
return candid;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Use `__get_candid_interface_tmp_hack` for canisters without Candid metadata
|
|
31
|
+
const tmpHackInterface: IDL.InterfaceFactory = ({ IDL }) =>
|
|
32
|
+
IDL.Service({
|
|
33
|
+
__get_candid_interface_tmp_hack: IDL.Func([], [IDL.Text], ['query']),
|
|
34
|
+
});
|
|
35
|
+
const actor: ActorSubclass = Actor.createActor(tmpHackInterface, { agent, canisterId });
|
|
36
|
+
return (await actor.__get_candid_interface_tmp_hack()) as string;
|
|
37
|
+
}
|
package/src/agent/index.ts
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module api
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './actor.ts';
|
|
6
|
+
export * from './agent/index.ts';
|
|
7
|
+
export * from './agent/http/transforms.ts';
|
|
8
|
+
export * from './agent/http/types.ts';
|
|
9
|
+
export * from './auth.ts';
|
|
10
|
+
export * from './certificate.ts';
|
|
11
|
+
export {
|
|
12
|
+
IC_REQUEST_DOMAIN_SEPARATOR,
|
|
13
|
+
IC_RESPONSE_DOMAIN_SEPARATOR,
|
|
14
|
+
IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR,
|
|
15
|
+
} from './constants.ts';
|
|
16
|
+
export * from './der.ts';
|
|
17
|
+
export * from './errors.ts';
|
|
18
|
+
export * from './fetch_candid.ts';
|
|
19
|
+
export * from './observable.ts';
|
|
20
|
+
export * from './public_key.ts';
|
|
21
|
+
export * from './request_id.ts';
|
|
22
|
+
export * from './utils/bls.ts';
|
|
23
|
+
export * from './utils/buffer.ts';
|
|
24
|
+
export * from './utils/random.ts';
|
|
25
|
+
export * as polling from './polling/index.ts';
|
|
26
|
+
import * as CanisterStatus from './canisterStatus/index.ts';
|
|
27
|
+
export { CanisterStatus };
|
|
28
|
+
/**
|
|
29
|
+
* The CanisterStatus utility is used to request structured data directly from the IC public API. This data can be accessed using agent.readState, but CanisterStatus provides a helpful abstraction with some known paths.
|
|
30
|
+
*
|
|
31
|
+
* You can request a canisters Controllers, ModuleHash, Candid interface, Subnet, or Time, or provide a custom path {@link CanisterStatus.CustomPath} and pass arbitrary buffers for valid paths identified in https://internetcomputer.org/docs/current/references/ic-interface-spec.
|
|
32
|
+
*
|
|
33
|
+
* The primary method for this namespace is {@link CanisterStatus.request}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export { Cbor, ToCborValue } from './cbor.ts';
|
|
37
|
+
export * from './polling/index.ts';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AgentError } from './errors.ts';
|
|
2
|
+
|
|
3
|
+
export type ObserveFunction<T> = (data: T, ...rest: unknown[]) => void;
|
|
4
|
+
|
|
5
|
+
export class Observable<T> {
|
|
6
|
+
observers: ObserveFunction<T>[];
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.observers = [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
subscribe(func: ObserveFunction<T>) {
|
|
13
|
+
this.observers.push(func);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
unsubscribe(func: ObserveFunction<T>) {
|
|
17
|
+
this.observers = this.observers.filter(observer => observer !== func);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
notify(data: T, ...rest: unknown[]) {
|
|
21
|
+
this.observers.forEach(observer => observer(data, ...rest));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type AgentLog =
|
|
26
|
+
| {
|
|
27
|
+
message: string;
|
|
28
|
+
level: 'warn' | 'info';
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
message: string;
|
|
32
|
+
level: 'error';
|
|
33
|
+
error: AgentError;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export class ObservableLog extends Observable<AgentLog> {
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
}
|
|
40
|
+
print(message: string, ...rest: unknown[]) {
|
|
41
|
+
this.notify({ message, level: 'info' }, ...rest);
|
|
42
|
+
}
|
|
43
|
+
warn(message: string, ...rest: unknown[]) {
|
|
44
|
+
this.notify({ message, level: 'warn' }, ...rest);
|
|
45
|
+
}
|
|
46
|
+
error(message: string, error: AgentError, ...rest: unknown[]) {
|
|
47
|
+
this.notify({ message, level: 'error', error }, ...rest);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const RANDOMIZATION_FACTOR = 0.5;
|
|
2
|
+
const MULTIPLIER = 1.5;
|
|
3
|
+
const INITIAL_INTERVAL_MSEC = 500;
|
|
4
|
+
const MAX_INTERVAL_MSEC = 60_000;
|
|
5
|
+
const MAX_ELAPSED_TIME_MSEC = 900_000;
|
|
6
|
+
const MAX_ITERATIONS = 10;
|
|
7
|
+
|
|
8
|
+
export type BackoffStrategy = {
|
|
9
|
+
next: () => number | null;
|
|
10
|
+
currentInterval?: number;
|
|
11
|
+
count?: number;
|
|
12
|
+
ellapsedTimeInMsec?: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type BackoffStrategyArgs = {
|
|
16
|
+
maxIterations?: number;
|
|
17
|
+
maxElapsedTime?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type BackoffStrategyFactory = (args?: BackoffStrategyArgs) => BackoffStrategy;
|
|
21
|
+
|
|
22
|
+
// export type BackoffStrategyGenerator = Generator<number, void, unknown>;
|
|
23
|
+
|
|
24
|
+
export type ExponentialBackoffOptions = {
|
|
25
|
+
initialInterval?: number;
|
|
26
|
+
randomizationFactor?: number;
|
|
27
|
+
multiplier?: number;
|
|
28
|
+
maxInterval?: number;
|
|
29
|
+
maxElapsedTime?: number;
|
|
30
|
+
maxIterations?: number;
|
|
31
|
+
date?: DateConstructor;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Exponential backoff strategy.
|
|
36
|
+
*/
|
|
37
|
+
export class ExponentialBackoff {
|
|
38
|
+
#currentInterval: number;
|
|
39
|
+
#randomizationFactor: number;
|
|
40
|
+
#multiplier: number;
|
|
41
|
+
#maxInterval: number;
|
|
42
|
+
#startTime: number;
|
|
43
|
+
#maxElapsedTime: number;
|
|
44
|
+
#maxIterations: number;
|
|
45
|
+
#date: DateConstructor;
|
|
46
|
+
#count = 0;
|
|
47
|
+
|
|
48
|
+
static default = {
|
|
49
|
+
initialInterval: INITIAL_INTERVAL_MSEC,
|
|
50
|
+
randomizationFactor: RANDOMIZATION_FACTOR,
|
|
51
|
+
multiplier: MULTIPLIER,
|
|
52
|
+
maxInterval: MAX_INTERVAL_MSEC,
|
|
53
|
+
// 1 minute
|
|
54
|
+
maxElapsedTime: MAX_ELAPSED_TIME_MSEC,
|
|
55
|
+
maxIterations: MAX_ITERATIONS,
|
|
56
|
+
date: Date,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
constructor(options: ExponentialBackoffOptions = ExponentialBackoff.default) {
|
|
60
|
+
const {
|
|
61
|
+
initialInterval = INITIAL_INTERVAL_MSEC,
|
|
62
|
+
randomizationFactor = RANDOMIZATION_FACTOR,
|
|
63
|
+
multiplier = MULTIPLIER,
|
|
64
|
+
maxInterval = MAX_INTERVAL_MSEC,
|
|
65
|
+
maxElapsedTime = MAX_ELAPSED_TIME_MSEC,
|
|
66
|
+
maxIterations = MAX_ITERATIONS,
|
|
67
|
+
date = Date,
|
|
68
|
+
} = options;
|
|
69
|
+
this.#currentInterval = initialInterval;
|
|
70
|
+
this.#randomizationFactor = randomizationFactor;
|
|
71
|
+
this.#multiplier = multiplier;
|
|
72
|
+
this.#maxInterval = maxInterval;
|
|
73
|
+
this.#date = date;
|
|
74
|
+
this.#startTime = date.now();
|
|
75
|
+
this.#maxElapsedTime = maxElapsedTime;
|
|
76
|
+
this.#maxIterations = maxIterations;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get ellapsedTimeInMsec() {
|
|
80
|
+
return this.#date.now() - this.#startTime;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get currentInterval() {
|
|
84
|
+
return this.#currentInterval;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get count() {
|
|
88
|
+
return this.#count;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get randomValueFromInterval() {
|
|
92
|
+
const delta = this.#randomizationFactor * this.#currentInterval;
|
|
93
|
+
const min = this.#currentInterval - delta;
|
|
94
|
+
const max = this.#currentInterval + delta;
|
|
95
|
+
return Math.random() * (max - min) + min;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public incrementCurrentInterval() {
|
|
99
|
+
this.#currentInterval = Math.min(this.#currentInterval * this.#multiplier, this.#maxInterval);
|
|
100
|
+
this.#count++;
|
|
101
|
+
|
|
102
|
+
return this.#currentInterval;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public next() {
|
|
106
|
+
if (this.ellapsedTimeInMsec >= this.#maxElapsedTime || this.#count >= this.#maxIterations) {
|
|
107
|
+
return null;
|
|
108
|
+
} else {
|
|
109
|
+
this.incrementCurrentInterval();
|
|
110
|
+
return this.randomValueFromInterval;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Utility function to create an exponential backoff iterator.
|
|
116
|
+
* @param options - for the exponential backoff
|
|
117
|
+
* @returns an iterator that yields the next delay in the exponential backoff
|
|
118
|
+
* @yields the next delay in the exponential backoff
|
|
119
|
+
*/
|
|
120
|
+
export function* exponentialBackoff(
|
|
121
|
+
options: ExponentialBackoffOptions = ExponentialBackoff.default,
|
|
122
|
+
) {
|
|
123
|
+
const backoff = new ExponentialBackoff(options);
|
|
124
|
+
|
|
125
|
+
let next = backoff.next();
|
|
126
|
+
while (next) {
|
|
127
|
+
yield next;
|
|
128
|
+
next = backoff.next();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { type RequestId } from '../request_id.ts';
|
|
2
|
+
import {
|
|
3
|
+
type CreateCertificateOptions,
|
|
4
|
+
Certificate,
|
|
5
|
+
lookupResultToBuffer,
|
|
6
|
+
} from '../certificate.ts';
|
|
7
|
+
import { type Agent, type ReadStateResponse } from '../agent/api.ts';
|
|
8
|
+
import { Principal } from '#principal';
|
|
9
|
+
import {
|
|
10
|
+
CertifiedRejectErrorCode,
|
|
11
|
+
ExternalError,
|
|
12
|
+
InputError,
|
|
13
|
+
InvalidReadStateRequestErrorCode,
|
|
14
|
+
MissingRootKeyErrorCode,
|
|
15
|
+
RejectError,
|
|
16
|
+
RequestStatusDoneNoReplyErrorCode,
|
|
17
|
+
UnknownError,
|
|
18
|
+
UNREACHABLE_ERROR,
|
|
19
|
+
} from '../errors.ts';
|
|
20
|
+
|
|
21
|
+
export * as strategy from './strategy.ts';
|
|
22
|
+
import { defaultStrategy } from './strategy.ts';
|
|
23
|
+
import { ReadRequestType, type ReadStateRequest } from '../agent/http/types.ts';
|
|
24
|
+
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
25
|
+
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
26
|
+
export { defaultStrategy } from './strategy.ts';
|
|
27
|
+
|
|
28
|
+
export type PollStrategy = (
|
|
29
|
+
canisterId: Principal,
|
|
30
|
+
requestId: RequestId,
|
|
31
|
+
status: RequestStatusResponseStatus,
|
|
32
|
+
) => Promise<void>;
|
|
33
|
+
|
|
34
|
+
interface SignedReadStateRequestWithExpiry extends ReadStateRequest {
|
|
35
|
+
body: {
|
|
36
|
+
content: Pick<ReadStateRequest, 'request_type' | 'ingress_expiry'>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for controlling polling behavior
|
|
42
|
+
*/
|
|
43
|
+
export interface PollingOptions {
|
|
44
|
+
/**
|
|
45
|
+
* A polling strategy that dictates how much and often we should poll the
|
|
46
|
+
* read_state endpoint to get the result of an update call.
|
|
47
|
+
* @default {@link defaultStrategy}
|
|
48
|
+
*/
|
|
49
|
+
strategy?: PollStrategy;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether to reuse the same signed request for polling or create a new unsigned request each time.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
preSignReadStateRequest?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Optional replacement function that verifies the BLS signature of a certificate.
|
|
59
|
+
*/
|
|
60
|
+
blsVerify?: CreateCertificateOptions['blsVerify'];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The request to use for polling. If not provided, a new request will be created.
|
|
64
|
+
* This is only used if `preSignReadStateRequest` is set to false.
|
|
65
|
+
*/
|
|
66
|
+
request?: ReadStateRequest;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const DEFAULT_POLLING_OPTIONS: PollingOptions = {
|
|
70
|
+
preSignReadStateRequest: false,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check if an object has a property
|
|
75
|
+
* @param value the object that might have the property
|
|
76
|
+
* @param property the key of property we're looking for
|
|
77
|
+
*/
|
|
78
|
+
function hasProperty<O extends object, P extends string>(
|
|
79
|
+
value: O,
|
|
80
|
+
property: P,
|
|
81
|
+
): value is O & Record<P, unknown> {
|
|
82
|
+
return Object.prototype.hasOwnProperty.call(value, property);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isObjectWithProperty<O extends object, P extends string>(
|
|
86
|
+
value: unknown,
|
|
87
|
+
property: P,
|
|
88
|
+
): value is O & Record<P, unknown> {
|
|
89
|
+
return value !== null && typeof value === 'object' && hasProperty(value, property);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function hasFunction<O extends object, P extends string>(
|
|
93
|
+
value: O,
|
|
94
|
+
property: P,
|
|
95
|
+
): value is O & Record<P, (...args: unknown[]) => unknown> {
|
|
96
|
+
return hasProperty(value, property) && typeof value[property] === 'function';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Check if value is a signed read state request with expiry
|
|
101
|
+
* @param value to check
|
|
102
|
+
*/
|
|
103
|
+
function isSignedReadStateRequestWithExpiry(
|
|
104
|
+
value: unknown,
|
|
105
|
+
): value is SignedReadStateRequestWithExpiry {
|
|
106
|
+
return (
|
|
107
|
+
isObjectWithProperty(value, 'body') &&
|
|
108
|
+
isObjectWithProperty(value.body, 'content') &&
|
|
109
|
+
(value.body.content as { request_type: ReadRequestType }).request_type ===
|
|
110
|
+
ReadRequestType.ReadState &&
|
|
111
|
+
isObjectWithProperty(value.body.content, 'ingress_expiry') &&
|
|
112
|
+
typeof value.body.content.ingress_expiry === 'object' &&
|
|
113
|
+
value.body.content.ingress_expiry !== null &&
|
|
114
|
+
hasFunction(value.body.content.ingress_expiry, 'toHash')
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Polls the IC to check the status of the given request then
|
|
120
|
+
* returns the response bytes once the request has been processed.
|
|
121
|
+
* @param agent The agent to use to poll read_state.
|
|
122
|
+
* @param canisterId The effective canister ID.
|
|
123
|
+
* @param requestId The Request ID to poll status for.
|
|
124
|
+
* @param options polling options to control behavior
|
|
125
|
+
*/
|
|
126
|
+
export async function pollForResponse(
|
|
127
|
+
agent: Agent,
|
|
128
|
+
canisterId: Principal,
|
|
129
|
+
requestId: RequestId,
|
|
130
|
+
options: PollingOptions = {},
|
|
131
|
+
): Promise<{
|
|
132
|
+
certificate: Certificate;
|
|
133
|
+
reply: Uint8Array;
|
|
134
|
+
}> {
|
|
135
|
+
const path = [utf8ToBytes('request_status'), requestId];
|
|
136
|
+
|
|
137
|
+
let state: ReadStateResponse;
|
|
138
|
+
let currentRequest: ReadStateRequest | undefined;
|
|
139
|
+
const preSignReadStateRequest = options.preSignReadStateRequest ?? false;
|
|
140
|
+
if (preSignReadStateRequest) {
|
|
141
|
+
// If preSignReadStateRequest is true, we need to create a new request
|
|
142
|
+
currentRequest = await constructRequest({
|
|
143
|
+
paths: [path],
|
|
144
|
+
agent,
|
|
145
|
+
pollingOptions: options,
|
|
146
|
+
});
|
|
147
|
+
state = await agent.readState(canisterId, { paths: [path] }, undefined, currentRequest);
|
|
148
|
+
} else {
|
|
149
|
+
// If preSignReadStateRequest is false, we use the default strategy and sign the request each time
|
|
150
|
+
state = await agent.readState(canisterId, { paths: [path] });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (agent.rootKey == null) {
|
|
154
|
+
throw ExternalError.fromCode(new MissingRootKeyErrorCode());
|
|
155
|
+
}
|
|
156
|
+
const cert = await Certificate.create({
|
|
157
|
+
certificate: state.certificate,
|
|
158
|
+
rootKey: agent.rootKey,
|
|
159
|
+
canisterId: canisterId,
|
|
160
|
+
blsVerify: options.blsVerify,
|
|
161
|
+
agent,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const maybeBuf = lookupResultToBuffer(cert.lookup_path([...path, utf8ToBytes('status')]));
|
|
165
|
+
let status;
|
|
166
|
+
if (typeof maybeBuf === 'undefined') {
|
|
167
|
+
// Missing requestId means we need to wait
|
|
168
|
+
status = RequestStatusResponseStatus.Unknown;
|
|
169
|
+
} else {
|
|
170
|
+
status = new TextDecoder().decode(maybeBuf);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
switch (status) {
|
|
174
|
+
case RequestStatusResponseStatus.Replied: {
|
|
175
|
+
return {
|
|
176
|
+
reply: lookupResultToBuffer(cert.lookup_path([...path, 'reply']))!,
|
|
177
|
+
certificate: cert,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case RequestStatusResponseStatus.Received:
|
|
182
|
+
case RequestStatusResponseStatus.Unknown:
|
|
183
|
+
case RequestStatusResponseStatus.Processing: {
|
|
184
|
+
// Execute the polling strategy, then retry.
|
|
185
|
+
const strategy = options.strategy ?? defaultStrategy();
|
|
186
|
+
await strategy(canisterId, requestId, status);
|
|
187
|
+
|
|
188
|
+
return pollForResponse(agent, canisterId, requestId, {
|
|
189
|
+
...options,
|
|
190
|
+
// Pass over either the strategy already provided or the new one created above
|
|
191
|
+
strategy,
|
|
192
|
+
request: currentRequest,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
case RequestStatusResponseStatus.Rejected: {
|
|
197
|
+
const rejectCode = new Uint8Array(
|
|
198
|
+
lookupResultToBuffer(cert.lookup_path([...path, 'reject_code']))!,
|
|
199
|
+
)[0];
|
|
200
|
+
const rejectMessage = new TextDecoder().decode(
|
|
201
|
+
lookupResultToBuffer(cert.lookup_path([...path, 'reject_message']))!,
|
|
202
|
+
);
|
|
203
|
+
const errorCodeBuf = lookupResultToBuffer(cert.lookup_path([...path, 'error_code']));
|
|
204
|
+
const errorCode = errorCodeBuf ? new TextDecoder().decode(errorCodeBuf) : undefined;
|
|
205
|
+
throw RejectError.fromCode(
|
|
206
|
+
new CertifiedRejectErrorCode(requestId, rejectCode, rejectMessage, errorCode),
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
case RequestStatusResponseStatus.Done:
|
|
211
|
+
// This is _technically_ not an error, but we still didn't see the `Replied` status so
|
|
212
|
+
// we don't know the result and cannot decode it.
|
|
213
|
+
throw UnknownError.fromCode(new RequestStatusDoneNoReplyErrorCode(requestId));
|
|
214
|
+
}
|
|
215
|
+
throw UNREACHABLE_ERROR;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Determine if we should reuse the read state request or create a new one
|
|
219
|
+
// based on the options provided.
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Constructs a read state request for the given paths.
|
|
223
|
+
* If the request is already signed and has an expiry, it will be returned as is.
|
|
224
|
+
* Otherwise, a new request will be created.
|
|
225
|
+
* @param options The options to use for creating the request.
|
|
226
|
+
* @param options.paths The paths to read from.
|
|
227
|
+
* @param options.agent The agent to use to create the request.
|
|
228
|
+
* @param options.pollingOptions The options to use for creating the request.
|
|
229
|
+
* @returns The read state request.
|
|
230
|
+
*/
|
|
231
|
+
export async function constructRequest(options: {
|
|
232
|
+
paths: Uint8Array[][];
|
|
233
|
+
agent: Agent;
|
|
234
|
+
pollingOptions: PollingOptions;
|
|
235
|
+
}): Promise<ReadStateRequest> {
|
|
236
|
+
const { paths, agent, pollingOptions } = options;
|
|
237
|
+
if (pollingOptions.request && isSignedReadStateRequestWithExpiry(pollingOptions.request)) {
|
|
238
|
+
return pollingOptions.request;
|
|
239
|
+
}
|
|
240
|
+
const request = await agent.createReadStateRequest?.(
|
|
241
|
+
{
|
|
242
|
+
paths,
|
|
243
|
+
},
|
|
244
|
+
undefined,
|
|
245
|
+
);
|
|
246
|
+
if (!isSignedReadStateRequestWithExpiry(request)) {
|
|
247
|
+
throw InputError.fromCode(new InvalidReadStateRequestErrorCode(request));
|
|
248
|
+
}
|
|
249
|
+
return request;
|
|
250
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Principal } from '#principal';
|
|
2
|
+
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
3
|
+
import { type PollStrategy } from './index.ts';
|
|
4
|
+
import { type RequestId } from '../request_id.ts';
|
|
5
|
+
import { ProtocolError, TimeoutWaitingForResponseErrorCode } from '../errors.ts';
|
|
6
|
+
|
|
7
|
+
export type Predicate<T> = (
|
|
8
|
+
canisterId: Principal,
|
|
9
|
+
requestId: RequestId,
|
|
10
|
+
status: RequestStatusResponseStatus,
|
|
11
|
+
) => Promise<T>;
|
|
12
|
+
|
|
13
|
+
const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A best practices polling strategy: wait 2 seconds before the first poll, then 1 second
|
|
17
|
+
* with an exponential backoff factor of 1.2. Timeout after 5 minutes.
|
|
18
|
+
*
|
|
19
|
+
* Note that calling this function will create the strategy chain described above and already start the 5 minutes timeout.
|
|
20
|
+
* You should only call this function when you want to start the polling, and not before, to avoid exhausting the 5 minutes timeout in advance.
|
|
21
|
+
*/
|
|
22
|
+
export function defaultStrategy(): PollStrategy {
|
|
23
|
+
return chain(conditionalDelay(once(), 1000), backoff(1000, 1.2), timeout(FIVE_MINUTES_IN_MSEC));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Predicate that returns true once.
|
|
28
|
+
*/
|
|
29
|
+
export function once(): Predicate<boolean> {
|
|
30
|
+
let first = true;
|
|
31
|
+
return async () => {
|
|
32
|
+
if (first) {
|
|
33
|
+
first = false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delay the polling once.
|
|
42
|
+
* @param condition A predicate that indicates when to delay.
|
|
43
|
+
* @param timeInMsec The amount of time to delay.
|
|
44
|
+
*/
|
|
45
|
+
export function conditionalDelay(condition: Predicate<boolean>, timeInMsec: number): PollStrategy {
|
|
46
|
+
return async (
|
|
47
|
+
canisterId: Principal,
|
|
48
|
+
requestId: RequestId,
|
|
49
|
+
status: RequestStatusResponseStatus,
|
|
50
|
+
) => {
|
|
51
|
+
if (await condition(canisterId, requestId, status)) {
|
|
52
|
+
return new Promise(resolve => setTimeout(resolve, timeInMsec));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Error out after a maximum number of polling has been done.
|
|
59
|
+
* @param count The maximum attempts to poll.
|
|
60
|
+
*/
|
|
61
|
+
export function maxAttempts(count: number): PollStrategy {
|
|
62
|
+
let attempts = count;
|
|
63
|
+
return async (
|
|
64
|
+
_canisterId: Principal,
|
|
65
|
+
requestId: RequestId,
|
|
66
|
+
status: RequestStatusResponseStatus,
|
|
67
|
+
) => {
|
|
68
|
+
if (--attempts <= 0) {
|
|
69
|
+
throw ProtocolError.fromCode(
|
|
70
|
+
new TimeoutWaitingForResponseErrorCode(
|
|
71
|
+
`Failed to retrieve a reply for request after ${count} attempts`,
|
|
72
|
+
requestId,
|
|
73
|
+
status,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Throttle polling.
|
|
82
|
+
* @param throttleInMsec Amount in millisecond to wait between each polling.
|
|
83
|
+
*/
|
|
84
|
+
export function throttle(throttleInMsec: number): PollStrategy {
|
|
85
|
+
return () => new Promise(resolve => setTimeout(resolve, throttleInMsec));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Reject a call after a certain amount of time.
|
|
90
|
+
* @param timeInMsec Time in milliseconds before the polling should be rejected.
|
|
91
|
+
*/
|
|
92
|
+
export function timeout(timeInMsec: number): PollStrategy {
|
|
93
|
+
const end = Date.now() + timeInMsec;
|
|
94
|
+
return async (
|
|
95
|
+
_canisterId: Principal,
|
|
96
|
+
requestId: RequestId,
|
|
97
|
+
status: RequestStatusResponseStatus,
|
|
98
|
+
) => {
|
|
99
|
+
if (Date.now() > end) {
|
|
100
|
+
throw ProtocolError.fromCode(
|
|
101
|
+
new TimeoutWaitingForResponseErrorCode(
|
|
102
|
+
`Request timed out after ${timeInMsec} msec`,
|
|
103
|
+
requestId,
|
|
104
|
+
status,
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A strategy that throttle, but using an exponential backoff strategy.
|
|
113
|
+
* @param startingThrottleInMsec The throttle in milliseconds to start with.
|
|
114
|
+
* @param backoffFactor The factor to multiple the throttle time between every poll. For
|
|
115
|
+
* example if using 2, the throttle will double between every run.
|
|
116
|
+
*/
|
|
117
|
+
export function backoff(startingThrottleInMsec: number, backoffFactor: number): PollStrategy {
|
|
118
|
+
let currentThrottling = startingThrottleInMsec;
|
|
119
|
+
|
|
120
|
+
return () =>
|
|
121
|
+
new Promise(resolve =>
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
currentThrottling *= backoffFactor;
|
|
124
|
+
resolve();
|
|
125
|
+
}, currentThrottling),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Chain multiple polling strategy. This _chains_ the strategies, so if you pass in,
|
|
131
|
+
* say, two throttling strategy of 1 second, it will result in a throttle of 2 seconds.
|
|
132
|
+
* @param strategies A strategy list to chain.
|
|
133
|
+
*/
|
|
134
|
+
export function chain(...strategies: PollStrategy[]): PollStrategy {
|
|
135
|
+
return async (
|
|
136
|
+
canisterId: Principal,
|
|
137
|
+
requestId: RequestId,
|
|
138
|
+
status: RequestStatusResponseStatus,
|
|
139
|
+
) => {
|
|
140
|
+
for (const a of strategies) {
|
|
141
|
+
await a(canisterId, requestId, status);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|