@icp-sdk/core 4.2.3 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent/actor.d.ts +203 -0
- package/lib/cjs/agent/actor.d.ts.map +1 -0
- package/lib/cjs/agent/actor.js +341 -0
- package/lib/cjs/agent/actor.js.map +1 -0
- package/lib/cjs/agent/agent/api.d.ts +216 -0
- package/lib/cjs/agent/agent/api.d.ts.map +1 -0
- package/lib/cjs/agent/agent/api.js +39 -0
- package/lib/cjs/agent/agent/api.js.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +19 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +171 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/index.js +1079 -0
- package/lib/cjs/agent/agent/http/index.js.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.js +135 -0
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
- package/lib/cjs/agent/agent/http/types.d.ts +81 -0
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/types.js +43 -0
- package/lib/cjs/agent/agent/http/types.js.map +1 -0
- package/lib/cjs/agent/agent/index.d.ts +3 -0
- package/lib/cjs/agent/agent/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/index.js +19 -0
- package/lib/cjs/agent/agent/index.js.map +1 -0
- package/lib/cjs/agent/auth.d.ts +91 -0
- package/lib/cjs/agent/auth.d.ts.map +1 -0
- package/lib/cjs/agent/auth.js +65 -0
- package/lib/cjs/agent/auth.js.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts +93 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.js +301 -0
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
- package/lib/cjs/agent/cbor.d.ts +26 -0
- package/lib/cjs/agent/cbor.d.ts.map +1 -0
- package/lib/cjs/agent/cbor.js +93 -0
- package/lib/cjs/agent/cbor.js.map +1 -0
- package/lib/cjs/agent/certificate.d.ts +228 -0
- package/lib/cjs/agent/certificate.d.ts.map +1 -0
- package/lib/cjs/agent/certificate.js +591 -0
- package/lib/cjs/agent/certificate.js.map +1 -0
- package/lib/cjs/agent/constants.d.ts +14 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -0
- package/lib/cjs/agent/constants.js +18 -0
- package/lib/cjs/agent/constants.js.map +1 -0
- package/lib/cjs/agent/der.d.ts +34 -0
- package/lib/cjs/agent/der.d.ts.map +1 -0
- package/lib/cjs/agent/der.js +175 -0
- package/lib/cjs/agent/der.js.map +1 -0
- package/lib/cjs/agent/errors.d.ts +380 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -0
- package/lib/cjs/agent/errors.js +733 -0
- package/lib/cjs/agent/errors.js.map +1 -0
- package/lib/cjs/agent/fetch_candid.d.ts +9 -0
- package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
- package/lib/cjs/agent/fetch_candid.js +69 -0
- package/lib/cjs/agent/fetch_candid.js.map +1 -0
- package/lib/cjs/agent/index.d.ts +31 -1
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +59 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +24 -0
- package/lib/cjs/agent/observable.d.ts.map +1 -0
- package/lib/cjs/agent/observable.js +34 -0
- package/lib/cjs/agent/observable.js.map +1 -0
- package/lib/cjs/agent/polling/backoff.d.ts +50 -0
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
- package/lib/cjs/agent/polling/backoff.js +90 -0
- package/lib/cjs/agent/polling/backoff.js.map +1 -0
- package/lib/cjs/agent/polling/index.d.ts +63 -0
- package/lib/cjs/agent/polling/index.d.ts.map +1 -0
- package/lib/cjs/agent/polling/index.js +183 -0
- package/lib/cjs/agent/polling/index.js.map +1 -0
- package/lib/cjs/agent/polling/strategy.d.ts +52 -0
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
- package/lib/cjs/agent/polling/strategy.js +104 -0
- package/lib/cjs/agent/polling/strategy.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +16 -0
- package/lib/cjs/agent/public_key.d.ts.map +1 -0
- package/lib/cjs/agent/public_key.js +52 -0
- package/lib/cjs/agent/public_key.js.map +1 -0
- package/lib/cjs/agent/request_id.d.ts +24 -0
- package/lib/cjs/agent/request_id.d.ts.map +1 -0
- package/lib/cjs/agent/request_id.js +88 -0
- package/lib/cjs/agent/request_id.js.map +1 -0
- package/lib/cjs/agent/utils/bls.d.ts +10 -0
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
- package/lib/cjs/agent/utils/bls.js +20 -0
- package/lib/cjs/agent/utils/bls.js.map +1 -0
- package/lib/cjs/agent/utils/buffer.d.ts +22 -0
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/agent/utils/buffer.js +55 -0
- package/lib/cjs/agent/utils/buffer.js.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.js +148 -0
- package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
- package/lib/cjs/agent/utils/leb.d.ts +3 -0
- package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
- package/lib/cjs/agent/utils/leb.js +17 -0
- package/lib/cjs/agent/utils/leb.js.map +1 -0
- package/lib/cjs/agent/utils/random.d.ts +6 -0
- package/lib/cjs/agent/utils/random.d.ts.map +1 -0
- package/lib/cjs/agent/utils/random.js +29 -0
- package/lib/cjs/agent/utils/random.js.map +1 -0
- package/lib/cjs/candid/candid-core.d.ts +72 -0
- package/lib/cjs/candid/candid-core.d.ts.map +1 -0
- package/lib/cjs/candid/candid-core.js +251 -0
- package/lib/cjs/candid/candid-core.js.map +1 -0
- package/lib/cjs/candid/candid-ui.d.ts +35 -0
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
- package/lib/cjs/candid/candid-ui.js +317 -0
- package/lib/cjs/candid/candid-ui.js.map +1 -0
- package/lib/cjs/candid/idl.d.ts +579 -0
- package/lib/cjs/candid/idl.d.ts.map +1 -0
- package/lib/cjs/candid/idl.js +2228 -0
- package/lib/cjs/candid/idl.js.map +1 -0
- package/lib/cjs/candid/index.d.ts +11 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +33 -1
- package/lib/cjs/candid/index.js.map +1 -1
- package/lib/cjs/candid/types.d.ts +6 -0
- package/lib/cjs/candid/types.d.ts.map +1 -0
- package/lib/cjs/candid/types.js +4 -0
- package/lib/cjs/candid/types.js.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.js +30 -0
- package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +86 -0
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/candid/utils/buffer.js +191 -0
- package/lib/cjs/candid/utils/buffer.js.map +1 -0
- package/lib/cjs/candid/utils/hash.d.ts +7 -0
- package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
- package/lib/cjs/candid/utils/hash.js +33 -0
- package/lib/cjs/candid/utils/hash.js.map +1 -0
- package/lib/cjs/candid/utils/leb128.d.ts +65 -0
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
- package/lib/cjs/candid/utils/leb128.js +228 -0
- package/lib/cjs/candid/utils/leb128.js.map +1 -0
- package/lib/cjs/identity/identity/delegation.d.ts +164 -0
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
- package/lib/cjs/identity/identity/delegation.js +302 -0
- package/lib/cjs/identity/identity/delegation.js.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.js +117 -0
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
- package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ed25519.js +200 -0
- package/lib/cjs/identity/identity/ed25519.js.map +1 -0
- package/lib/cjs/identity/identity/partial.d.ts +34 -0
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
- package/lib/cjs/identity/identity/partial.js +54 -0
- package/lib/cjs/identity/identity/partial.js.map +1 -0
- package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/cjs/identity/identity/webauthn.js +197 -0
- package/lib/cjs/identity/identity/webauthn.js.map +1 -0
- package/lib/cjs/identity/index.d.ts +15 -1
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +24 -1
- package/lib/cjs/identity/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/der.js +165 -0
- package/lib/cjs/identity/secp256k1/der.js.map +1 -0
- package/lib/cjs/identity/secp256k1/index.d.ts +4 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +4 -1
- package/lib/cjs/identity/secp256k1/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/pem.js +75 -0
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/cjs/principal/index.d.ts +3 -1
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +7 -1
- package/lib/cjs/principal/index.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +50 -0
- package/lib/cjs/principal/principal.d.ts.map +1 -0
- package/lib/cjs/principal/principal.js +148 -0
- package/lib/cjs/principal/principal.js.map +1 -0
- package/lib/cjs/principal/utils/base32.d.ts +10 -0
- package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
- package/lib/cjs/principal/utils/base32.js +90 -0
- package/lib/cjs/principal/utils/base32.js.map +1 -0
- package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
- package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/cjs/principal/utils/getCrc.js +53 -0
- package/lib/cjs/principal/utils/getCrc.js.map +1 -0
- package/lib/esm/agent/actor.d.ts +203 -0
- package/lib/esm/agent/actor.d.ts.map +1 -0
- package/lib/esm/agent/actor.js +337 -0
- package/lib/esm/agent/actor.js.map +1 -0
- package/lib/esm/agent/agent/api.d.ts +216 -0
- package/lib/esm/agent/agent/api.d.ts.map +1 -0
- package/lib/esm/agent/agent/api.js +34 -0
- package/lib/esm/agent/agent/api.js.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +16 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +171 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/index.js +1037 -0
- package/lib/esm/agent/agent/http/index.js.map +1 -0
- package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/transforms.js +128 -0
- package/lib/esm/agent/agent/http/transforms.js.map +1 -0
- package/lib/esm/agent/agent/http/types.d.ts +81 -0
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/types.js +39 -0
- package/lib/esm/agent/agent/http/types.js.map +1 -0
- package/lib/esm/agent/agent/index.d.ts +3 -0
- package/lib/esm/agent/agent/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/index.js +3 -0
- package/lib/esm/agent/agent/index.js.map +1 -0
- package/lib/esm/agent/auth.d.ts +91 -0
- package/lib/esm/agent/auth.d.ts.map +1 -0
- package/lib/esm/agent/auth.js +59 -0
- package/lib/esm/agent/auth.js.map +1 -0
- package/lib/esm/agent/canister-env/index.d.ts +110 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +110 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +93 -0
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/canisterStatus/index.js +261 -0
- package/lib/esm/agent/canisterStatus/index.js.map +1 -0
- package/lib/esm/agent/cbor.d.ts +26 -0
- package/lib/esm/agent/cbor.d.ts.map +1 -0
- package/lib/esm/agent/cbor.js +54 -0
- package/lib/esm/agent/cbor.js.map +1 -0
- package/lib/esm/agent/certificate.d.ts +228 -0
- package/lib/esm/agent/certificate.d.ts.map +1 -0
- package/lib/esm/agent/certificate.js +545 -0
- package/lib/esm/agent/certificate.js.map +1 -0
- package/lib/esm/agent/constants.d.ts +14 -0
- package/lib/esm/agent/constants.d.ts.map +1 -0
- package/lib/esm/agent/constants.js +15 -0
- package/lib/esm/agent/constants.js.map +1 -0
- package/lib/esm/agent/der.d.ts +34 -0
- package/lib/esm/agent/der.d.ts.map +1 -0
- package/lib/esm/agent/der.js +166 -0
- package/lib/esm/agent/der.js.map +1 -0
- package/lib/esm/agent/errors.d.ts +380 -0
- package/lib/esm/agent/errors.d.ts.map +1 -0
- package/lib/esm/agent/errors.js +678 -0
- package/lib/esm/agent/errors.js.map +1 -0
- package/lib/esm/agent/fetch_candid.d.ts +9 -0
- package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
- package/lib/esm/agent/fetch_candid.js +33 -0
- package/lib/esm/agent/fetch_candid.js.map +1 -0
- package/lib/esm/agent/index.d.ts +31 -1
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +31 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +24 -0
- package/lib/esm/agent/observable.d.ts.map +1 -0
- package/lib/esm/agent/observable.js +29 -0
- package/lib/esm/agent/observable.js.map +1 -0
- package/lib/esm/agent/polling/backoff.d.ts +50 -0
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
- package/lib/esm/agent/polling/backoff.js +85 -0
- package/lib/esm/agent/polling/backoff.js.map +1 -0
- package/lib/esm/agent/polling/index.d.ts +63 -0
- package/lib/esm/agent/polling/index.d.ts.map +1 -0
- package/lib/esm/agent/polling/index.js +144 -0
- package/lib/esm/agent/polling/index.js.map +1 -0
- package/lib/esm/agent/polling/strategy.d.ts +52 -0
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
- package/lib/esm/agent/polling/strategy.js +94 -0
- package/lib/esm/agent/polling/strategy.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +16 -0
- package/lib/esm/agent/public_key.d.ts.map +1 -0
- package/lib/esm/agent/public_key.js +48 -0
- package/lib/esm/agent/public_key.js.map +1 -0
- package/lib/esm/agent/request_id.d.ts +24 -0
- package/lib/esm/agent/request_id.d.ts.map +1 -0
- package/lib/esm/agent/request_id.js +83 -0
- package/lib/esm/agent/request_id.js.map +1 -0
- package/lib/esm/agent/utils/bls.d.ts +10 -0
- package/lib/esm/agent/utils/bls.d.ts.map +1 -0
- package/lib/esm/agent/utils/bls.js +17 -0
- package/lib/esm/agent/utils/bls.js.map +1 -0
- package/lib/esm/agent/utils/buffer.d.ts +22 -0
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
- package/lib/esm/agent/utils/buffer.js +50 -0
- package/lib/esm/agent/utils/buffer.js.map +1 -0
- package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableMap.js +144 -0
- package/lib/esm/agent/utils/expirableMap.js.map +1 -0
- package/lib/esm/agent/utils/leb.d.ts +3 -0
- package/lib/esm/agent/utils/leb.d.ts.map +1 -0
- package/lib/esm/agent/utils/leb.js +12 -0
- package/lib/esm/agent/utils/leb.js.map +1 -0
- package/lib/esm/agent/utils/random.d.ts +6 -0
- package/lib/esm/agent/utils/random.d.ts.map +1 -0
- package/lib/esm/agent/utils/random.js +25 -0
- package/lib/esm/agent/utils/random.js.map +1 -0
- package/lib/esm/candid/candid-core.d.ts +72 -0
- package/lib/esm/candid/candid-core.d.ts.map +1 -0
- package/lib/esm/candid/candid-core.js +241 -0
- package/lib/esm/candid/candid-core.js.map +1 -0
- package/lib/esm/candid/candid-ui.d.ts +35 -0
- package/lib/esm/candid/candid-ui.d.ts.map +1 -0
- package/lib/esm/candid/candid-ui.js +272 -0
- package/lib/esm/candid/candid-ui.js.map +1 -0
- package/lib/esm/candid/idl.d.ts +579 -0
- package/lib/esm/candid/idl.d.ts.map +1 -0
- package/lib/esm/candid/idl.js +2189 -0
- package/lib/esm/candid/idl.js.map +1 -0
- package/lib/esm/candid/index.d.ts +11 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +10 -1
- package/lib/esm/candid/index.js.map +1 -1
- package/lib/esm/candid/types.d.ts +6 -0
- package/lib/esm/candid/types.d.ts.map +1 -0
- package/lib/esm/candid/types.js +3 -0
- package/lib/esm/candid/types.js.map +1 -0
- package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
- package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/esm/candid/utils/bigint-math.js +26 -0
- package/lib/esm/candid/utils/bigint-math.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +86 -0
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
- package/lib/esm/candid/utils/buffer.js +182 -0
- package/lib/esm/candid/utils/buffer.js.map +1 -0
- package/lib/esm/candid/utils/hash.d.ts +7 -0
- package/lib/esm/candid/utils/hash.d.ts.map +1 -0
- package/lib/esm/candid/utils/hash.js +30 -0
- package/lib/esm/candid/utils/hash.js.map +1 -0
- package/lib/esm/candid/utils/leb128.d.ts +65 -0
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
- package/lib/esm/candid/utils/leb128.js +216 -0
- package/lib/esm/candid/utils/leb128.js.map +1 -0
- package/lib/esm/identity/identity/delegation.d.ts +164 -0
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
- package/lib/esm/identity/identity/delegation.js +294 -0
- package/lib/esm/identity/identity/delegation.js.map +1 -0
- package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/esm/identity/identity/ecdsa.js +112 -0
- package/lib/esm/identity/identity/ecdsa.js.map +1 -0
- package/lib/esm/identity/identity/ed25519.d.ts +67 -0
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/esm/identity/identity/ed25519.js +195 -0
- package/lib/esm/identity/identity/ed25519.js.map +1 -0
- package/lib/esm/identity/identity/partial.d.ts +34 -0
- package/lib/esm/identity/identity/partial.d.ts.map +1 -0
- package/lib/esm/identity/identity/partial.js +50 -0
- package/lib/esm/identity/identity/partial.js.map +1 -0
- package/lib/esm/identity/identity/webauthn.d.ts +51 -0
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/esm/identity/identity/webauthn.js +192 -0
- package/lib/esm/identity/identity/webauthn.js.map +1 -0
- package/lib/esm/identity/index.d.ts +15 -1
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +17 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +33 -0
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/der.js +156 -0
- package/lib/esm/identity/secp256k1/der.js.map +1 -0
- package/lib/esm/identity/secp256k1/index.d.ts +4 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +4 -1
- package/lib/esm/identity/secp256k1/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/pem.js +39 -0
- package/lib/esm/identity/secp256k1/pem.js.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/esm/principal/index.d.ts +3 -1
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +3 -1
- package/lib/esm/principal/index.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +50 -0
- package/lib/esm/principal/principal.d.ts.map +1 -0
- package/lib/esm/principal/principal.js +144 -0
- package/lib/esm/principal/principal.js.map +1 -0
- package/lib/esm/principal/utils/base32.d.ts +10 -0
- package/lib/esm/principal/utils/base32.d.ts.map +1 -0
- package/lib/esm/principal/utils/base32.js +86 -0
- package/lib/esm/principal/utils/base32.js.map +1 -0
- package/lib/esm/principal/utils/getCrc.d.ts +6 -0
- package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/esm/principal/utils/getCrc.js +50 -0
- package/lib/esm/principal/utils/getCrc.js.map +1 -0
- package/package.json +17 -11
- package/src/agent/actor.ts +576 -0
- package/src/agent/agent/api.ts +262 -0
- package/src/agent/agent/http/index.ts +1405 -0
- package/src/agent/agent/http/transforms.ts +158 -0
- package/src/agent/agent/http/types.ts +126 -0
- package/src/agent/agent/index.ts +2 -0
- package/src/agent/auth.ts +147 -0
- package/src/agent/canister-env/index.ts +191 -1
- package/src/agent/canisterStatus/index.ts +412 -0
- package/src/agent/cbor.ts +63 -0
- package/src/agent/certificate.ts +841 -0
- package/src/agent/constants.ts +19 -0
- package/src/agent/der.ts +170 -0
- package/src/agent/errors.ts +868 -0
- package/src/agent/fetch_candid.ts +37 -0
- package/src/agent/index.ts +37 -1
- package/src/agent/observable.ts +49 -0
- package/src/agent/polling/backoff.ts +130 -0
- package/src/agent/polling/index.ts +250 -0
- package/src/agent/polling/strategy.ts +144 -0
- package/src/agent/public_key.ts +65 -0
- package/src/agent/request_id.ts +92 -0
- package/src/agent/utils/bls.ts +18 -0
- package/src/agent/utils/buffer.ts +60 -0
- package/src/agent/utils/expirableMap.ts +163 -0
- package/src/agent/utils/leb.ts +14 -0
- package/src/agent/utils/random.ts +30 -0
- package/src/candid/candid-core.ts +276 -0
- package/src/candid/candid-ui.ts +289 -0
- package/src/candid/idl.ts +2556 -0
- package/src/candid/index.ts +16 -1
- package/src/candid/types.ts +7 -0
- package/src/candid/utils/bigint-math.ts +26 -0
- package/src/candid/utils/buffer.ts +221 -0
- package/src/candid/utils/hash.ts +31 -0
- package/src/candid/utils/leb128.ts +234 -0
- package/src/identity/identity/delegation.ts +411 -0
- package/src/identity/identity/ecdsa.ts +158 -0
- package/src/identity/identity/ed25519.ts +239 -0
- package/src/identity/identity/partial.ts +60 -0
- package/src/identity/identity/webauthn.ts +265 -0
- package/src/identity/index.ts +19 -1
- package/src/identity/secp256k1/der.ts +156 -0
- package/src/identity/secp256k1/index.ts +5 -1
- package/src/identity/secp256k1/pem.ts +40 -0
- package/src/identity/secp256k1/secp256k1.ts +270 -0
- package/src/package.json +4 -0
- package/src/principal/index.ts +3 -1
- package/src/principal/principal.ts +171 -0
- package/src/principal/utils/base32.ts +101 -0
- package/src/principal/utils/getCrc.ts +52 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { lebEncode } from '#candid';
|
|
2
|
+
import {
|
|
3
|
+
Endpoint,
|
|
4
|
+
type HttpAgentRequest,
|
|
5
|
+
type HttpAgentRequestTransformFn,
|
|
6
|
+
type HttpHeaderField,
|
|
7
|
+
makeNonce,
|
|
8
|
+
type Nonce,
|
|
9
|
+
} from './types.ts';
|
|
10
|
+
import { ExpiryJsonDeserializeErrorCode, InputError } from '../../errors.ts';
|
|
11
|
+
|
|
12
|
+
export const JSON_KEY_EXPIRY = '__expiry__';
|
|
13
|
+
const SECONDS_TO_MILLISECONDS = BigInt(1_000);
|
|
14
|
+
const MILLISECONDS_TO_NANOSECONDS = BigInt(1_000_000);
|
|
15
|
+
const MINUTES_TO_SECONDS = BigInt(60);
|
|
16
|
+
const MINUTES_TO_MILLISECONDS = MINUTES_TO_SECONDS * SECONDS_TO_MILLISECONDS;
|
|
17
|
+
|
|
18
|
+
const EXPIRY_DELTA_THRESHOLD_MILLISECONDS = BigInt(1) * MINUTES_TO_MILLISECONDS;
|
|
19
|
+
|
|
20
|
+
function roundToSecond(millis: bigint): bigint {
|
|
21
|
+
return (millis / SECONDS_TO_MILLISECONDS) * SECONDS_TO_MILLISECONDS;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function roundToMinute(millis: bigint): bigint {
|
|
25
|
+
return (millis / MINUTES_TO_MILLISECONDS) * MINUTES_TO_MILLISECONDS;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type JsonnableExpiry = {
|
|
29
|
+
[JSON_KEY_EXPIRY]: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export class Expiry {
|
|
33
|
+
public readonly _isExpiry = true;
|
|
34
|
+
|
|
35
|
+
private constructor(private readonly __expiry__: bigint) {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an Expiry object from a delta in milliseconds.
|
|
39
|
+
* The expiry is calculated as: current_time + delta + clock_drift
|
|
40
|
+
* The resulting expiry is then rounded:
|
|
41
|
+
* - If rounding down to the nearest minute still provides at least 60 seconds in the future, use minute precision
|
|
42
|
+
* - Otherwise, use second precision
|
|
43
|
+
* @param deltaInMs The milliseconds to add to the current time.
|
|
44
|
+
* @param clockDriftInMs The milliseconds to add to the current time, typically the clock drift between IC network clock and the client's clock. Defaults to `0` if not provided.
|
|
45
|
+
* @returns {Expiry} The constructed Expiry object.
|
|
46
|
+
*/
|
|
47
|
+
public static fromDeltaInMilliseconds(deltaInMs: number, clockDriftInMs: number = 0): Expiry {
|
|
48
|
+
const correctedNowMs = BigInt(Date.now()) + BigInt(clockDriftInMs);
|
|
49
|
+
const expiryMs = correctedNowMs + BigInt(deltaInMs);
|
|
50
|
+
|
|
51
|
+
const roundedToMinute = roundToMinute(expiryMs);
|
|
52
|
+
|
|
53
|
+
let roundedExpiryMs: bigint;
|
|
54
|
+
if (roundedToMinute >= correctedNowMs + EXPIRY_DELTA_THRESHOLD_MILLISECONDS) {
|
|
55
|
+
roundedExpiryMs = roundedToMinute;
|
|
56
|
+
} else {
|
|
57
|
+
const roundedToSecond = roundToSecond(expiryMs);
|
|
58
|
+
roundedExpiryMs = roundedToSecond;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return new Expiry(roundedExpiryMs * MILLISECONDS_TO_NANOSECONDS);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public toBigInt(): bigint {
|
|
65
|
+
return this.__expiry__;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public toHash(): Uint8Array {
|
|
69
|
+
return lebEncode(this.__expiry__);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public toString(): string {
|
|
73
|
+
return this.__expiry__.toString();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Serializes to JSON
|
|
78
|
+
* @returns {JsonnableExpiry} a JSON object with a single key, {@link JSON_KEY_EXPIRY}, whose value is the expiry as a string
|
|
79
|
+
*/
|
|
80
|
+
public toJSON(): JsonnableExpiry {
|
|
81
|
+
return { [JSON_KEY_EXPIRY]: this.toString() };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Deserializes a {@link JsonnableExpiry} object from a JSON string.
|
|
86
|
+
* @param input The JSON string to deserialize.
|
|
87
|
+
* @returns {Expiry} The deserialized Expiry object.
|
|
88
|
+
*/
|
|
89
|
+
public static fromJSON(input: string): Expiry {
|
|
90
|
+
const obj = JSON.parse(input);
|
|
91
|
+
if (obj[JSON_KEY_EXPIRY]) {
|
|
92
|
+
try {
|
|
93
|
+
const expiry = BigInt(obj[JSON_KEY_EXPIRY]);
|
|
94
|
+
return new Expiry(expiry);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw new InputError(new ExpiryJsonDeserializeErrorCode(`Not a valid BigInt: ${error}`));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
throw new InputError(
|
|
100
|
+
new ExpiryJsonDeserializeErrorCode(`The input does not contain the key ${JSON_KEY_EXPIRY}`),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public static isExpiry(other: unknown): other is Expiry {
|
|
105
|
+
return (
|
|
106
|
+
other instanceof Expiry ||
|
|
107
|
+
(typeof other === 'object' &&
|
|
108
|
+
other !== null &&
|
|
109
|
+
'_isExpiry' in other &&
|
|
110
|
+
(other as { _isExpiry: boolean })['_isExpiry'] === true &&
|
|
111
|
+
'__expiry__' in other &&
|
|
112
|
+
typeof (other as { __expiry__: bigint })['__expiry__'] === 'bigint')
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create a Nonce transform, which takes a function that returns a Buffer, and adds it
|
|
119
|
+
* as the nonce to every call requests.
|
|
120
|
+
* @param nonceFn A function that returns a buffer. By default uses a semi-random method.
|
|
121
|
+
*/
|
|
122
|
+
export function makeNonceTransform(nonceFn: () => Nonce = makeNonce): HttpAgentRequestTransformFn {
|
|
123
|
+
return async (request: HttpAgentRequest) => {
|
|
124
|
+
// Nonce needs to be inserted into the header for all requests, to enable logs to be correlated with requests.
|
|
125
|
+
const headers = request.request.headers;
|
|
126
|
+
// TODO: uncomment this when the http proxy supports it.
|
|
127
|
+
// headers.set('X-IC-Request-ID', toHex(new Uint8Array(nonce)));
|
|
128
|
+
request.request.headers = headers;
|
|
129
|
+
|
|
130
|
+
// Nonce only needs to be inserted into the body for async calls, to prevent replay attacks.
|
|
131
|
+
if (request.endpoint === Endpoint.Call) {
|
|
132
|
+
request.body.nonce = nonceFn();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create a transform that adds a delay (by default 5 minutes) to the expiry.
|
|
139
|
+
* @param delayInMilliseconds The delay to add to the call time, in milliseconds.
|
|
140
|
+
*/
|
|
141
|
+
export function makeExpiryTransform(delayInMilliseconds: number): HttpAgentRequestTransformFn {
|
|
142
|
+
return async (request: HttpAgentRequest) => {
|
|
143
|
+
request.body.ingress_expiry = Expiry.fromDeltaInMilliseconds(delayInMilliseconds);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Maps the default fetch headers field to the serializable HttpHeaderField.
|
|
149
|
+
* @param headers Fetch definition of the headers type
|
|
150
|
+
* @returns array of header fields
|
|
151
|
+
*/
|
|
152
|
+
export function httpHeadersTransform(headers: Headers): HttpHeaderField[] {
|
|
153
|
+
const headerFields: HttpHeaderField[] = [];
|
|
154
|
+
headers.forEach((value, key) => {
|
|
155
|
+
headerFields.push([key, value]);
|
|
156
|
+
});
|
|
157
|
+
return headerFields;
|
|
158
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Principal } from '#principal';
|
|
2
|
+
import { Expiry } from './transforms.ts';
|
|
3
|
+
import { randomNumber } from '../../utils/random.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export enum Endpoint {
|
|
9
|
+
Query = 'read',
|
|
10
|
+
ReadState = 'read_state',
|
|
11
|
+
Call = 'call',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// An HttpAgent request, before it gets encoded and sent to the server.
|
|
15
|
+
// We create an empty request that we will fill later.
|
|
16
|
+
export type HttpAgentRequest =
|
|
17
|
+
| HttpAgentQueryRequest
|
|
18
|
+
| HttpAgentSubmitRequest
|
|
19
|
+
| HttpAgentReadStateRequest;
|
|
20
|
+
|
|
21
|
+
export interface HttpAgentBaseRequest {
|
|
22
|
+
readonly endpoint: Endpoint;
|
|
23
|
+
request: RequestInit;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type HttpHeaderField = [string, string];
|
|
27
|
+
|
|
28
|
+
export interface HttpAgentSubmitRequest extends HttpAgentBaseRequest {
|
|
29
|
+
readonly endpoint: Endpoint.Call;
|
|
30
|
+
body: CallRequest;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface HttpAgentQueryRequest extends HttpAgentBaseRequest {
|
|
34
|
+
readonly endpoint: Endpoint.Query;
|
|
35
|
+
body: ReadRequest;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface HttpAgentReadStateRequest extends HttpAgentBaseRequest {
|
|
39
|
+
readonly endpoint: Endpoint.ReadState;
|
|
40
|
+
body: ReadRequest;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Signed<T> {
|
|
44
|
+
content: T;
|
|
45
|
+
sender_pubkey: ArrayBuffer;
|
|
46
|
+
sender_sig: ArrayBuffer;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UnSigned<T> {
|
|
50
|
+
content: T;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Envelope<T> = Signed<T> | UnSigned<T>;
|
|
54
|
+
|
|
55
|
+
export interface HttpAgentRequestTransformFn {
|
|
56
|
+
(args: HttpAgentRequest): Promise<HttpAgentRequest | undefined | void>;
|
|
57
|
+
priority?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The fields in a "call" submit request.
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
export interface CallRequest extends Record<string, any> {
|
|
63
|
+
request_type: SubmitRequestType.Call;
|
|
64
|
+
canister_id: Principal;
|
|
65
|
+
method_name: string;
|
|
66
|
+
arg: Uint8Array;
|
|
67
|
+
sender: Uint8Array | Principal;
|
|
68
|
+
ingress_expiry: Expiry;
|
|
69
|
+
nonce?: Nonce;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The types of values allowed in the `request_type` field for submit requests.
|
|
73
|
+
export enum SubmitRequestType {
|
|
74
|
+
Call = 'call',
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The types of values allowed in the `request_type` field for read requests.
|
|
78
|
+
export enum ReadRequestType {
|
|
79
|
+
Query = 'query',
|
|
80
|
+
ReadState = 'read_state',
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The fields in a "query" read request.
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
export interface QueryRequest extends Record<string, any> {
|
|
86
|
+
request_type: ReadRequestType.Query;
|
|
87
|
+
canister_id: Principal;
|
|
88
|
+
method_name: string;
|
|
89
|
+
arg: Uint8Array;
|
|
90
|
+
sender: Uint8Array | Principal;
|
|
91
|
+
ingress_expiry: Expiry;
|
|
92
|
+
nonce?: Nonce;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
export interface ReadStateRequest extends Record<string, any> {
|
|
97
|
+
request_type: ReadRequestType.ReadState;
|
|
98
|
+
paths: Uint8Array[][];
|
|
99
|
+
ingress_expiry: Expiry;
|
|
100
|
+
sender: Uint8Array | Principal;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type ReadRequest = QueryRequest | ReadStateRequest;
|
|
104
|
+
|
|
105
|
+
// A Nonce that can be used for calls.
|
|
106
|
+
export type Nonce = Uint8Array & { __nonce__: void };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Create a random Nonce, based on random values
|
|
110
|
+
*/
|
|
111
|
+
export function makeNonce(): Nonce {
|
|
112
|
+
// Encode 128 bits.
|
|
113
|
+
const buffer = new ArrayBuffer(16);
|
|
114
|
+
const view = new DataView(buffer);
|
|
115
|
+
const rand1 = randomNumber();
|
|
116
|
+
const rand2 = randomNumber();
|
|
117
|
+
const rand3 = randomNumber();
|
|
118
|
+
const rand4 = randomNumber();
|
|
119
|
+
|
|
120
|
+
view.setUint32(0, rand1);
|
|
121
|
+
view.setUint32(4, rand2);
|
|
122
|
+
view.setUint32(8, rand3);
|
|
123
|
+
view.setUint32(12, rand4);
|
|
124
|
+
|
|
125
|
+
return Object.assign(new Uint8Array(buffer), { __nonce__: undefined });
|
|
126
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Principal } from '#principal';
|
|
2
|
+
import { type HttpAgentRequest } from './agent/http/types.ts';
|
|
3
|
+
import { requestIdOf } from './request_id.ts';
|
|
4
|
+
import { bytesToHex, concatBytes } from '@noble/hashes/utils';
|
|
5
|
+
import { IC_REQUEST_DOMAIN_SEPARATOR } from './constants.ts';
|
|
6
|
+
/**
|
|
7
|
+
* A Key Pair, containing a secret and public key.
|
|
8
|
+
*/
|
|
9
|
+
export interface KeyPair {
|
|
10
|
+
secretKey: Uint8Array;
|
|
11
|
+
publicKey: PublicKey;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A public key that is DER encoded. This is a branded Uint8Array.
|
|
16
|
+
*/
|
|
17
|
+
export type DerEncodedPublicKey = Uint8Array & { __derEncodedPublicKey__?: void };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A signature array buffer.
|
|
21
|
+
*/
|
|
22
|
+
export type Signature = Uint8Array & { __signature__: void };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A Public Key implementation.
|
|
26
|
+
*/
|
|
27
|
+
export interface PublicKey {
|
|
28
|
+
toDer(): DerEncodedPublicKey;
|
|
29
|
+
// rawKey, toRaw, and derKey are optional for backwards compatibility.
|
|
30
|
+
toRaw?(): Uint8Array;
|
|
31
|
+
rawKey?: Uint8Array;
|
|
32
|
+
derKey?: DerEncodedPublicKey;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A General Identity object. This does not have to be a private key (for example,
|
|
37
|
+
* the Anonymous identity), but it must be able to transform request.
|
|
38
|
+
*/
|
|
39
|
+
export interface Identity {
|
|
40
|
+
/**
|
|
41
|
+
* Get the principal represented by this identity. Normally should be a
|
|
42
|
+
* `Principal.selfAuthenticating()`.
|
|
43
|
+
*/
|
|
44
|
+
getPrincipal(): Principal;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Transform a request into a signed version of the request. This is done last
|
|
48
|
+
* after the transforms on the body of a request. The returned object can be
|
|
49
|
+
* anything, but must be serializable to CBOR.
|
|
50
|
+
*/
|
|
51
|
+
transformRequest(request: HttpAgentRequest): Promise<unknown>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* An Identity that can sign blobs.
|
|
56
|
+
*/
|
|
57
|
+
export abstract class SignIdentity implements Identity {
|
|
58
|
+
protected _principal: Principal | undefined;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the public key that would match this identity's signature.
|
|
62
|
+
*/
|
|
63
|
+
public abstract getPublicKey(): PublicKey;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Signs a blob of data, with this identity's private key.
|
|
67
|
+
*/
|
|
68
|
+
public abstract sign(blob: Uint8Array): Promise<Signature>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the principal represented by this identity. Normally should be a
|
|
72
|
+
* `Principal.selfAuthenticating()`.
|
|
73
|
+
*/
|
|
74
|
+
public getPrincipal(): Principal {
|
|
75
|
+
if (!this._principal) {
|
|
76
|
+
this._principal = Principal.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()));
|
|
77
|
+
}
|
|
78
|
+
return this._principal;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Transform a request into a signed version of the request. This is done last
|
|
83
|
+
* after the transforms on the body of a request. The returned object can be
|
|
84
|
+
* anything, but must be serializable to CBOR.
|
|
85
|
+
* @param request - internet computer request to transform
|
|
86
|
+
*/
|
|
87
|
+
public async transformRequest(request: HttpAgentRequest): Promise<unknown> {
|
|
88
|
+
const { body, ...fields } = request;
|
|
89
|
+
const requestId = requestIdOf(body);
|
|
90
|
+
return {
|
|
91
|
+
...fields,
|
|
92
|
+
body: {
|
|
93
|
+
content: body,
|
|
94
|
+
sender_pubkey: this.getPublicKey().toDer(),
|
|
95
|
+
sender_sig: await this.sign(concatBytes(IC_REQUEST_DOMAIN_SEPARATOR, requestId)),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class AnonymousIdentity implements Identity {
|
|
102
|
+
public getPrincipal(): Principal {
|
|
103
|
+
return Principal.anonymous();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public async transformRequest(request: HttpAgentRequest): Promise<unknown> {
|
|
107
|
+
return {
|
|
108
|
+
...request,
|
|
109
|
+
body: { content: request.body },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* We need to communicate with other agents on the page about identities,
|
|
116
|
+
* but those messages may need to go across boundaries where it's not possible to
|
|
117
|
+
* serialize/deserialize object prototypes easily.
|
|
118
|
+
* So these are lightweight, serializable objects that contain enough information to recreate
|
|
119
|
+
* SignIdentities, but don't commit to having all methods of SignIdentity.
|
|
120
|
+
*
|
|
121
|
+
* Use Case:
|
|
122
|
+
* * DOM Events that let differently-versioned components communicate to one another about
|
|
123
|
+
* Identities, even if they're using slightly different versions of agent packages to
|
|
124
|
+
* create/interpret them.
|
|
125
|
+
*/
|
|
126
|
+
export interface AnonymousIdentityDescriptor {
|
|
127
|
+
type: 'AnonymousIdentity';
|
|
128
|
+
}
|
|
129
|
+
export interface PublicKeyIdentityDescriptor {
|
|
130
|
+
type: 'PublicKeyIdentity';
|
|
131
|
+
publicKey: string;
|
|
132
|
+
}
|
|
133
|
+
export type IdentityDescriptor = AnonymousIdentityDescriptor | PublicKeyIdentityDescriptor;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create an IdentityDescriptor from an Identity
|
|
137
|
+
* @param identity - identity describe in returned descriptor
|
|
138
|
+
*/
|
|
139
|
+
export function createIdentityDescriptor(
|
|
140
|
+
identity: SignIdentity | AnonymousIdentity,
|
|
141
|
+
): IdentityDescriptor {
|
|
142
|
+
const identityIndicator: IdentityDescriptor =
|
|
143
|
+
'getPublicKey' in identity
|
|
144
|
+
? { type: 'PublicKeyIdentity', publicKey: bytesToHex(identity.getPublicKey().toDer()) }
|
|
145
|
+
: { type: 'AnonymousIdentity' };
|
|
146
|
+
return identityIndicator;
|
|
147
|
+
}
|
|
@@ -1 +1,191 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @experimental
|
|
3
|
+
* @module canister-env/api
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { hexToBytes } from '@noble/hashes/utils';
|
|
7
|
+
import {
|
|
8
|
+
InputError,
|
|
9
|
+
InvalidRootKeyErrorCode,
|
|
10
|
+
EmptyCookieErrorCode,
|
|
11
|
+
MissingRootKeyErrorCode,
|
|
12
|
+
MissingCookieErrorCode,
|
|
13
|
+
} from '../errors.ts';
|
|
14
|
+
|
|
15
|
+
const IC_ENV_COOKIE_NAME = 'ic_env';
|
|
16
|
+
|
|
17
|
+
const ENV_VAR_SEPARATOR = '&';
|
|
18
|
+
const ENV_VAR_ASSIGNMENT_SYMBOL = '=';
|
|
19
|
+
|
|
20
|
+
const IC_ROOT_KEY_VALUE_NAME = 'ic_root_key';
|
|
21
|
+
const IC_ROOT_KEY_ENV_NAME = 'IC_ROOT_KEY'; // the value must be the same as the `CanisterEnv.IC_ROOT_KEY` property name
|
|
22
|
+
|
|
23
|
+
const IC_ROOT_KEY_BYTES_LENGTH = 133;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The environment variables served by the asset canister that hosts the frontend.
|
|
27
|
+
* You can extend the `CanisterEnv` interface to add your own environment variables
|
|
28
|
+
* and have strong typing for them.
|
|
29
|
+
* @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
|
|
30
|
+
* @experimental
|
|
31
|
+
* @example
|
|
32
|
+
* Extend the global `CanisterEnv` interface to add your own environment variables:
|
|
33
|
+
* ```ts title="index.ts"
|
|
34
|
+
* // You can declare the interface to have strong typing
|
|
35
|
+
* // for your own environment variables across your codebase
|
|
36
|
+
* declare module '@icp-sdk/core/agent/canister-env' {
|
|
37
|
+
* interface CanisterEnv {
|
|
38
|
+
* readonly ['PUBLIC_CANISTER_ID:backend']: string;
|
|
39
|
+
* readonly PUBLIC_API_URL: string;
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* const env = getCanisterEnv();
|
|
44
|
+
*
|
|
45
|
+
* console.log(env.IC_ROOT_KEY); // by default served by the asset canister
|
|
46
|
+
* console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ TS passes
|
|
47
|
+
* console.log(env.PUBLIC_API_URL); // ✅ TS passes
|
|
48
|
+
* console.log(env['PUBLIC_CANISTER_ID:another']); // ❌ TS will show an error
|
|
49
|
+
* ```
|
|
50
|
+
* @example
|
|
51
|
+
* Alternatively, use the generic parameter to specify additional properties:
|
|
52
|
+
* ```ts title="index.ts"
|
|
53
|
+
* const env = getCanisterEnv<{ readonly ['PUBLIC_CANISTER_ID:backend']: string }>();
|
|
54
|
+
*
|
|
55
|
+
* console.log(env.IC_ROOT_KEY); // by default served by the asset canister
|
|
56
|
+
* console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ from generic parameter, TS passes
|
|
57
|
+
* console.log(env['PUBLIC_CANISTER_ID:frontend']); // ❌ TS will show an error
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export interface CanisterEnv {
|
|
61
|
+
/**
|
|
62
|
+
* The root key of the IC network where the asset canister is deployed.
|
|
63
|
+
* Served by default by the asset canister that hosts the frontend.
|
|
64
|
+
*/
|
|
65
|
+
readonly IC_ROOT_KEY: Uint8Array; // the key must be the same as the `IC_ROOT_KEY_ENV_NAME` constant
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Options for the {@link getCanisterEnv} function
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
72
|
+
export type GetCanisterEnvOptions = {
|
|
73
|
+
/**
|
|
74
|
+
* The name of the cookie to get the environment variables from.
|
|
75
|
+
* @default 'ic_env'
|
|
76
|
+
*/
|
|
77
|
+
cookieName?: string;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the environment variables served by the asset canister via the cookie.
|
|
82
|
+
*
|
|
83
|
+
* The returned object always includes `IC_ROOT_KEY` property.
|
|
84
|
+
* You can extend the global `CanisterEnv` interface to add your own environment variables
|
|
85
|
+
* and have strong typing for them.
|
|
86
|
+
*
|
|
87
|
+
* In Node.js environment (or any other environment where `globalThis.document` is not available), this function will throw an error.
|
|
88
|
+
* Use {@link safeGetCanisterEnv} if you need a function that returns `undefined` instead of throwing errors.
|
|
89
|
+
* @param options The options for loading the canister environment variables
|
|
90
|
+
* @returns The environment variables for the asset canister, always including `IC_ROOT_KEY`
|
|
91
|
+
* @throws {TypeError} When `globalThis.document` is not available
|
|
92
|
+
* @throws {InputError} When the cookie is not found
|
|
93
|
+
* @throws {InputError} When the `IC_ROOT_KEY` is missing or has an invalid length
|
|
94
|
+
* @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
|
|
95
|
+
* @experimental
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* type MyCanisterEnv = {
|
|
99
|
+
* readonly ['PUBLIC_CANISTER_ID:backend']: string;
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* const env = getCanisterEnv<MyCanisterEnv>();
|
|
103
|
+
*
|
|
104
|
+
* console.log(env.IC_ROOT_KEY); // always available (Uint8Array)
|
|
105
|
+
* console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ from generic parameter, TS passes
|
|
106
|
+
* console.log(env['PUBLIC_CANISTER_ID:frontend']); // ❌ TS will show an error
|
|
107
|
+
* ```
|
|
108
|
+
* Have a look at {@link CanisterEnv} for more details on how to extend the interface
|
|
109
|
+
*/
|
|
110
|
+
export function getCanisterEnv<T = Record<string, never>>(
|
|
111
|
+
options: GetCanisterEnvOptions = {},
|
|
112
|
+
): CanisterEnv & T {
|
|
113
|
+
const { cookieName = IC_ENV_COOKIE_NAME } = options;
|
|
114
|
+
|
|
115
|
+
const cookie = getCookie(cookieName);
|
|
116
|
+
if (!cookie) {
|
|
117
|
+
throw InputError.fromCode(new MissingCookieErrorCode(cookieName));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const cookieValue = cookie.split('=')[1].trim();
|
|
121
|
+
if (!cookieValue) {
|
|
122
|
+
throw InputError.fromCode(new EmptyCookieErrorCode(cookieName));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const decodedCookieValue = decodeURIComponent(cookieValue);
|
|
126
|
+
const envVars = parseEnvVars<T>(decodedCookieValue);
|
|
127
|
+
if (!envVars.IC_ROOT_KEY) {
|
|
128
|
+
throw InputError.fromCode(new MissingRootKeyErrorCode());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return envVars;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Safe version of {@link getCanisterEnv} that returns `undefined` instead of throwing errors.
|
|
136
|
+
* @param options The options for loading the asset canister environment variables
|
|
137
|
+
* @returns The environment variables for the asset canister, or `undefined` if any error occurs
|
|
138
|
+
* @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
|
|
139
|
+
* @experimental
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* // in a browser environment with valid cookie
|
|
143
|
+
* const env = safeGetCanisterEnv();
|
|
144
|
+
* console.log(env); // { IC_ROOT_KEY: Uint8Array, ... }
|
|
145
|
+
*
|
|
146
|
+
* // in a Node.js environment
|
|
147
|
+
* const env = safeGetCanisterEnv();
|
|
148
|
+
* console.log(env); // undefined
|
|
149
|
+
*
|
|
150
|
+
* // in a browser without the environment cookie
|
|
151
|
+
* const env = safeGetCanisterEnv();
|
|
152
|
+
* console.log(env); // undefined
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function safeGetCanisterEnv<T = Record<string, never>>(
|
|
156
|
+
options: GetCanisterEnvOptions = {},
|
|
157
|
+
): (CanisterEnv & T) | undefined {
|
|
158
|
+
try {
|
|
159
|
+
return getCanisterEnv<T>(options);
|
|
160
|
+
} catch {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function getCookie(cookieName: string): string | undefined {
|
|
166
|
+
return globalThis.document.cookie
|
|
167
|
+
.split(';')
|
|
168
|
+
.find(cookie => cookie.trim().startsWith(`${cookieName}=`));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parseEnvVars<T = Record<string, never>>(decoded: string): CanisterEnv & T {
|
|
172
|
+
const entries = decoded.split(ENV_VAR_SEPARATOR).map(v => {
|
|
173
|
+
// we only want to split at the first occurrence of the assignment symbol
|
|
174
|
+
const symbolIndex = v.indexOf(ENV_VAR_ASSIGNMENT_SYMBOL);
|
|
175
|
+
|
|
176
|
+
const key = v.slice(0, symbolIndex);
|
|
177
|
+
const value = v.substring(symbolIndex + 1);
|
|
178
|
+
|
|
179
|
+
if (key === IC_ROOT_KEY_VALUE_NAME) {
|
|
180
|
+
const rootKey = hexToBytes(value);
|
|
181
|
+
if (rootKey.length !== IC_ROOT_KEY_BYTES_LENGTH) {
|
|
182
|
+
throw InputError.fromCode(new InvalidRootKeyErrorCode(rootKey, IC_ROOT_KEY_BYTES_LENGTH));
|
|
183
|
+
}
|
|
184
|
+
return [IC_ROOT_KEY_ENV_NAME, rootKey];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return [key, value];
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return Object.fromEntries(entries);
|
|
191
|
+
}
|