@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,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DerEncodedPublicKey,
|
|
3
|
+
type KeyPair,
|
|
4
|
+
type PublicKey,
|
|
5
|
+
type Signature,
|
|
6
|
+
SignIdentity,
|
|
7
|
+
ED25519_OID,
|
|
8
|
+
unwrapDER,
|
|
9
|
+
wrapDER,
|
|
10
|
+
} from '#agent';
|
|
11
|
+
import { uint8Equals, uint8FromBufLike } from '#candid';
|
|
12
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
13
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
14
|
+
|
|
15
|
+
declare type KeyLike = PublicKey | DerEncodedPublicKey | ArrayBuffer | ArrayBufferView;
|
|
16
|
+
|
|
17
|
+
function isObject(value: unknown) {
|
|
18
|
+
return value !== null && typeof value === 'object';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class Ed25519PublicKey implements PublicKey {
|
|
22
|
+
/**
|
|
23
|
+
* Construct Ed25519PublicKey from an existing PublicKey
|
|
24
|
+
* @param {unknown} maybeKey - existing PublicKey, ArrayBuffer, DerEncodedPublicKey, or hex string
|
|
25
|
+
* @returns {Ed25519PublicKey} Instance of Ed25519PublicKey
|
|
26
|
+
*/
|
|
27
|
+
public static from(maybeKey: unknown): Ed25519PublicKey {
|
|
28
|
+
if (typeof maybeKey === 'string') {
|
|
29
|
+
const key = hexToBytes(maybeKey);
|
|
30
|
+
return this.fromRaw(key);
|
|
31
|
+
} else if (isObject(maybeKey)) {
|
|
32
|
+
const key = maybeKey as KeyLike;
|
|
33
|
+
if (isObject(key) && Object.hasOwnProperty.call(key, '__derEncodedPublicKey__')) {
|
|
34
|
+
return this.fromDer(key as DerEncodedPublicKey);
|
|
35
|
+
} else if (ArrayBuffer.isView(key)) {
|
|
36
|
+
const view = key as ArrayBufferView;
|
|
37
|
+
return this.fromRaw(uint8FromBufLike(view.buffer));
|
|
38
|
+
} else if (key instanceof ArrayBuffer) {
|
|
39
|
+
return this.fromRaw(uint8FromBufLike(key));
|
|
40
|
+
} else if ('rawKey' in key && key.rawKey instanceof Uint8Array) {
|
|
41
|
+
return this.fromRaw(key.rawKey);
|
|
42
|
+
} else if ('derKey' in key) {
|
|
43
|
+
return this.fromDer(key.derKey as DerEncodedPublicKey);
|
|
44
|
+
} else if ('toDer' in key) {
|
|
45
|
+
return this.fromDer(key.toDer());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Cannot construct Ed25519PublicKey from the provided key.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public static fromRaw(rawKey: Uint8Array): Ed25519PublicKey {
|
|
52
|
+
return new Ed25519PublicKey(rawKey);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public static fromDer(derKey: DerEncodedPublicKey): Ed25519PublicKey {
|
|
56
|
+
return new Ed25519PublicKey(this.derDecode(derKey));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The length of Ed25519 public keys is always 32 bytes.
|
|
60
|
+
private static RAW_KEY_LENGTH = 32;
|
|
61
|
+
|
|
62
|
+
private static derEncode(publicKey: Uint8Array): DerEncodedPublicKey {
|
|
63
|
+
const key = wrapDER(publicKey, ED25519_OID) as DerEncodedPublicKey;
|
|
64
|
+
key.__derEncodedPublicKey__ = undefined;
|
|
65
|
+
return key;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private static derDecode(key: DerEncodedPublicKey): Uint8Array {
|
|
69
|
+
const unwrapped = unwrapDER(key, ED25519_OID);
|
|
70
|
+
if (unwrapped.length !== this.RAW_KEY_LENGTH) {
|
|
71
|
+
throw new Error('An Ed25519 public key must be exactly 32bytes long');
|
|
72
|
+
}
|
|
73
|
+
return unwrapped;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#rawKey: Uint8Array;
|
|
77
|
+
|
|
78
|
+
public get rawKey(): Uint8Array {
|
|
79
|
+
return this.#rawKey;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#derKey: DerEncodedPublicKey;
|
|
83
|
+
|
|
84
|
+
public get derKey(): DerEncodedPublicKey {
|
|
85
|
+
return this.#derKey;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
|
89
|
+
private constructor(key: Uint8Array) {
|
|
90
|
+
if (key.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
|
|
91
|
+
throw new Error('An Ed25519 public key must be exactly 32bytes long');
|
|
92
|
+
}
|
|
93
|
+
this.#rawKey = key;
|
|
94
|
+
this.#derKey = Ed25519PublicKey.derEncode(key);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public toDer(): DerEncodedPublicKey {
|
|
98
|
+
return this.derKey;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public toRaw(): Uint8Array {
|
|
102
|
+
return this.rawKey;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Ed25519KeyIdentity is an implementation of SignIdentity that uses Ed25519 keys. This class is used to sign and verify messages for an agent.
|
|
108
|
+
*/
|
|
109
|
+
export class Ed25519KeyIdentity extends SignIdentity {
|
|
110
|
+
/**
|
|
111
|
+
* Generate a new Ed25519KeyIdentity.
|
|
112
|
+
* @param seed a 32-byte seed for the private key. If not provided, a random seed will be generated.
|
|
113
|
+
* @returns Ed25519KeyIdentity
|
|
114
|
+
*/
|
|
115
|
+
public static generate(seed?: Uint8Array): Ed25519KeyIdentity {
|
|
116
|
+
if (seed && seed.length !== 32) {
|
|
117
|
+
throw new Error('Ed25519 Seed needs to be 32 bytes long.');
|
|
118
|
+
}
|
|
119
|
+
if (!seed) seed = ed25519.utils.randomPrivateKey();
|
|
120
|
+
// Check if the seed is all zeros
|
|
121
|
+
if (uint8Equals(seed, new Uint8Array(new Array(32).fill(0)))) {
|
|
122
|
+
console.warn(
|
|
123
|
+
'Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const sk = new Uint8Array(32);
|
|
127
|
+
for (let i = 0; i < 32; i++) {
|
|
128
|
+
sk[i] = seed[i];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const pk = ed25519.getPublicKey(sk);
|
|
132
|
+
return Ed25519KeyIdentity.fromKeyPair(pk, sk);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public static fromParsedJson(obj: JsonnableEd25519KeyIdentity): Ed25519KeyIdentity {
|
|
136
|
+
const [publicKeyDer, privateKeyRaw] = obj;
|
|
137
|
+
return new Ed25519KeyIdentity(
|
|
138
|
+
Ed25519PublicKey.fromDer(hexToBytes(publicKeyDer) as DerEncodedPublicKey),
|
|
139
|
+
hexToBytes(privateKeyRaw),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public static fromJSON(json: string): Ed25519KeyIdentity {
|
|
144
|
+
const parsed = JSON.parse(json);
|
|
145
|
+
if (Array.isArray(parsed)) {
|
|
146
|
+
if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
|
|
147
|
+
return this.fromParsedJson([parsed[0], parsed[1]]);
|
|
148
|
+
} else {
|
|
149
|
+
throw new Error('Deserialization error: JSON must have at least 2 items.');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public static fromKeyPair(publicKey: Uint8Array, privateKey: Uint8Array): Ed25519KeyIdentity {
|
|
156
|
+
return new Ed25519KeyIdentity(Ed25519PublicKey.fromRaw(publicKey), privateKey);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public static fromSecretKey(secretKey: Uint8Array): Ed25519KeyIdentity {
|
|
160
|
+
const publicKey = ed25519.getPublicKey(secretKey);
|
|
161
|
+
return Ed25519KeyIdentity.fromKeyPair(publicKey, secretKey);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#publicKey: Ed25519PublicKey;
|
|
165
|
+
#privateKey: Uint8Array;
|
|
166
|
+
|
|
167
|
+
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
|
168
|
+
protected constructor(publicKey: PublicKey, privateKey: Uint8Array) {
|
|
169
|
+
super();
|
|
170
|
+
this.#publicKey = Ed25519PublicKey.from(publicKey);
|
|
171
|
+
this.#privateKey = privateKey;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Serialize this key to JSON.
|
|
176
|
+
*/
|
|
177
|
+
public toJSON(): JsonnableEd25519KeyIdentity {
|
|
178
|
+
return [bytesToHex(this.#publicKey.toDer()), bytesToHex(this.#privateKey)];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Return a copy of the key pair.
|
|
183
|
+
*/
|
|
184
|
+
public getKeyPair(): KeyPair {
|
|
185
|
+
return {
|
|
186
|
+
secretKey: this.#privateKey,
|
|
187
|
+
publicKey: this.#publicKey,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Return the public key.
|
|
193
|
+
*/
|
|
194
|
+
public getPublicKey(): Required<PublicKey> {
|
|
195
|
+
return this.#publicKey;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Signs a blob of data, with this identity's private key.
|
|
200
|
+
* @param challenge - challenge to sign with this identity's secretKey, producing a signature
|
|
201
|
+
*/
|
|
202
|
+
public async sign(challenge: Uint8Array): Promise<Signature> {
|
|
203
|
+
// Some implementations of Ed25519 private keys append a public key to the end of the private key. We only want the private key.
|
|
204
|
+
const signature = ed25519.sign(challenge, this.#privateKey.slice(0, 32));
|
|
205
|
+
// add { __signature__: void; } to the signature to make it compatible with the agent
|
|
206
|
+
|
|
207
|
+
Object.defineProperty(signature, '__signature__', {
|
|
208
|
+
enumerable: false,
|
|
209
|
+
value: undefined,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return signature as Signature;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Verify
|
|
217
|
+
* @param sig - signature to verify
|
|
218
|
+
* @param msg - message to verify
|
|
219
|
+
* @param pk - public key
|
|
220
|
+
* @returns - true if the signature is valid, false otherwise
|
|
221
|
+
*/
|
|
222
|
+
public static verify(
|
|
223
|
+
sig: ArrayBuffer | Uint8Array | string,
|
|
224
|
+
msg: ArrayBuffer | Uint8Array | string,
|
|
225
|
+
pk: ArrayBuffer | Uint8Array | string,
|
|
226
|
+
) {
|
|
227
|
+
const [signature, message, publicKey] = [sig, msg, pk].map(x => {
|
|
228
|
+
if (typeof x === 'string') {
|
|
229
|
+
x = hexToBytes(x);
|
|
230
|
+
}
|
|
231
|
+
return uint8FromBufLike(x);
|
|
232
|
+
});
|
|
233
|
+
return ed25519.verify(signature, message, publicKey);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
type PublicKeyHex = string;
|
|
238
|
+
type SecretKeyHex = string;
|
|
239
|
+
export type JsonnableEd25519KeyIdentity = [PublicKeyHex, SecretKeyHex];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Identity, type PublicKey } from '#agent';
|
|
2
|
+
import { Principal } from '#principal';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A partial delegated identity, representing a delegation chain and the public key that it targets
|
|
6
|
+
*/
|
|
7
|
+
export class PartialIdentity implements Identity {
|
|
8
|
+
#inner: PublicKey;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The raw public key of this identity.
|
|
12
|
+
*/
|
|
13
|
+
get rawKey(): Uint8Array | undefined {
|
|
14
|
+
return this.#inner.rawKey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The DER-encoded public key of this identity.
|
|
19
|
+
*/
|
|
20
|
+
get derKey(): Uint8Array | undefined {
|
|
21
|
+
return this.#inner.derKey;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The DER-encoded public key of this identity.
|
|
26
|
+
*/
|
|
27
|
+
public toDer(): Uint8Array {
|
|
28
|
+
return this.#inner.toDer();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The inner {@link PublicKey} used by this identity.
|
|
33
|
+
*/
|
|
34
|
+
public getPublicKey(): PublicKey {
|
|
35
|
+
return this.#inner;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The {@link Principal} of this identity.
|
|
40
|
+
*/
|
|
41
|
+
public getPrincipal(): Principal {
|
|
42
|
+
if (!this.#inner.rawKey) {
|
|
43
|
+
throw new Error('Cannot get principal from a public key without a raw key.');
|
|
44
|
+
}
|
|
45
|
+
return Principal.fromUint8Array(new Uint8Array(this.#inner.rawKey));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Required for the Identity interface, but cannot implemented for just a public key.
|
|
50
|
+
*/
|
|
51
|
+
public transformRequest(): Promise<never> {
|
|
52
|
+
return Promise.reject(
|
|
53
|
+
'Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor(inner: PublicKey) {
|
|
58
|
+
this.#inner = inner;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DerEncodedPublicKey,
|
|
3
|
+
type PublicKey,
|
|
4
|
+
type Signature,
|
|
5
|
+
SignIdentity,
|
|
6
|
+
wrapDER,
|
|
7
|
+
DER_COSE_OID,
|
|
8
|
+
Cbor,
|
|
9
|
+
} from '#agent';
|
|
10
|
+
import { bytesToHex, hexToBytes, randomBytes, bytesToUtf8 } from '@noble/hashes/utils';
|
|
11
|
+
import { uint8FromBufLike } from '#candid';
|
|
12
|
+
|
|
13
|
+
function _coseToDerEncodedBlob(cose: Uint8Array): DerEncodedPublicKey {
|
|
14
|
+
return wrapDER(cose, DER_COSE_OID) as DerEncodedPublicKey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type PublicKeyCredentialWithAttachment = PublicKeyCredential & {
|
|
18
|
+
// Extends `PublicKeyCredential` with an optional field introduced in the WebAuthn level 3 spec:
|
|
19
|
+
// https://w3c.github.io/webauthn/#dom-publickeycredential-authenticatorattachment
|
|
20
|
+
// Already supported by Chrome, Safari and Edge
|
|
21
|
+
// Note: `null` is included here as a possible value because Edge set this value to null in the
|
|
22
|
+
// past.
|
|
23
|
+
authenticatorAttachment: AuthenticatorAttachment | undefined | null;
|
|
24
|
+
// Explicitly including toJSON method from the base PublicKeyCredential interface
|
|
25
|
+
toJSON: () => Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* From the documentation;
|
|
30
|
+
* The authData is a byte array described in the spec. Parsing it will involve slicing bytes from
|
|
31
|
+
* the array and converting them into usable objects.
|
|
32
|
+
*
|
|
33
|
+
* See https://webauthn.guide/#registration (subsection "Example: Parsing the authenticator data").
|
|
34
|
+
* @param authData The authData field of the attestation response.
|
|
35
|
+
* @returns The COSE key of the authData.
|
|
36
|
+
*/
|
|
37
|
+
function _authDataToCose(authData: Uint8Array): Uint8Array {
|
|
38
|
+
const dataView = new DataView(new ArrayBuffer(2));
|
|
39
|
+
const idLenBytes = authData.slice(53, 55);
|
|
40
|
+
[...new Uint8Array(idLenBytes)].forEach((v, i) => dataView.setUint8(i, v));
|
|
41
|
+
const credentialIdLength = dataView.getUint16(0);
|
|
42
|
+
|
|
43
|
+
// Get the public key object.
|
|
44
|
+
return authData.slice(55 + credentialIdLength);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class CosePublicKey implements PublicKey {
|
|
48
|
+
protected _encodedKey: DerEncodedPublicKey;
|
|
49
|
+
|
|
50
|
+
public constructor(protected _cose: Uint8Array) {
|
|
51
|
+
this._encodedKey = _coseToDerEncodedBlob(_cose);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public toDer(): DerEncodedPublicKey {
|
|
55
|
+
return this._encodedKey;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public getCose(): Uint8Array {
|
|
59
|
+
return this._cose;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create a challenge from a string or array. The default challenge is always the same
|
|
65
|
+
* because we don't need to verify the authenticity of the key on the server (we don't
|
|
66
|
+
* register our keys with the IC). Any challenge would do, even one per key, randomly
|
|
67
|
+
* generated.
|
|
68
|
+
* @param challenge The challenge to transform into a byte array. By default a hard
|
|
69
|
+
* coded string.
|
|
70
|
+
*/
|
|
71
|
+
function _createChallengeBuffer(challenge: string | Uint8Array = '<ic0.app>'): Uint8Array {
|
|
72
|
+
if (typeof challenge === 'string') {
|
|
73
|
+
return Uint8Array.from(challenge, c => c.charCodeAt(0));
|
|
74
|
+
} else {
|
|
75
|
+
return challenge;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a credentials to authenticate with a server. This is necessary in order in
|
|
81
|
+
* WebAuthn to get credentials IDs (which give us the public key and allow us to
|
|
82
|
+
* sign), but in the case of the Internet Computer, we don't actually need to register
|
|
83
|
+
* it, so we don't.
|
|
84
|
+
* @param credentialCreationOptions an optional CredentialCreationOptions object
|
|
85
|
+
*/
|
|
86
|
+
async function _createCredential(
|
|
87
|
+
credentialCreationOptions?: CredentialCreationOptions,
|
|
88
|
+
): Promise<PublicKeyCredentialWithAttachment | null> {
|
|
89
|
+
const creds = (await navigator.credentials.create(
|
|
90
|
+
credentialCreationOptions ?? {
|
|
91
|
+
publicKey: {
|
|
92
|
+
authenticatorSelection: {
|
|
93
|
+
userVerification: 'preferred',
|
|
94
|
+
},
|
|
95
|
+
attestation: 'direct',
|
|
96
|
+
challenge: _createChallengeBuffer(),
|
|
97
|
+
pubKeyCredParams: [{ type: 'public-key', alg: PubKeyCoseAlgo.ECDSA_WITH_SHA256 }],
|
|
98
|
+
rp: {
|
|
99
|
+
name: 'Internet Identity Service',
|
|
100
|
+
},
|
|
101
|
+
user: {
|
|
102
|
+
id: randomBytes(16),
|
|
103
|
+
name: 'Internet Identity',
|
|
104
|
+
displayName: 'Internet Identity',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
)) as PublicKeyCredentialWithAttachment | null;
|
|
109
|
+
|
|
110
|
+
if (creds === null) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
// do _not_ use ...creds here, as creds is not enumerable in all cases
|
|
116
|
+
id: creds.id,
|
|
117
|
+
response: creds.response,
|
|
118
|
+
type: creds.type,
|
|
119
|
+
authenticatorAttachment: creds.authenticatorAttachment,
|
|
120
|
+
getClientExtensionResults: creds.getClientExtensionResults,
|
|
121
|
+
// Some password managers will return a Uint8Array, so we ensure we return an ArrayBuffer.
|
|
122
|
+
rawId: creds.rawId,
|
|
123
|
+
toJSON: creds.toJSON.bind(creds), // Ensure the toJSON method is included
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// See https://www.iana.org/assignments/cose/cose.xhtml#algorithms for a complete
|
|
128
|
+
// list of these algorithms. We only list the ones we support here.
|
|
129
|
+
enum PubKeyCoseAlgo {
|
|
130
|
+
ECDSA_WITH_SHA256 = -7,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A SignIdentity that uses `navigator.credentials`. See https://webauthn.guide/ for
|
|
135
|
+
* more information about WebAuthentication.
|
|
136
|
+
*/
|
|
137
|
+
export class WebAuthnIdentity extends SignIdentity {
|
|
138
|
+
/**
|
|
139
|
+
* Create an identity from a JSON serialization.
|
|
140
|
+
* @param json - json to parse
|
|
141
|
+
*/
|
|
142
|
+
public static fromJSON(json: string): WebAuthnIdentity {
|
|
143
|
+
const { publicKey, rawId } = JSON.parse(json);
|
|
144
|
+
|
|
145
|
+
if (typeof publicKey !== 'string' || typeof rawId !== 'string') {
|
|
146
|
+
throw new Error('Invalid JSON string.');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return new this(hexToBytes(rawId), hexToBytes(publicKey), undefined);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Create an identity.
|
|
154
|
+
* @param credentialCreationOptions an optional CredentialCreationOptions Challenge
|
|
155
|
+
*/
|
|
156
|
+
public static async create(
|
|
157
|
+
credentialCreationOptions?: CredentialCreationOptions,
|
|
158
|
+
): Promise<WebAuthnIdentity> {
|
|
159
|
+
const creds = await _createCredential(credentialCreationOptions);
|
|
160
|
+
|
|
161
|
+
if (!creds || creds.type !== 'public-key') {
|
|
162
|
+
throw new Error('Could not create credentials.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const response = creds.response as AuthenticatorAttestationResponse;
|
|
166
|
+
if (response.attestationObject === undefined) {
|
|
167
|
+
throw new Error('Was expecting an attestation response.');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Parse the attestationObject as CBOR.
|
|
171
|
+
const attObject = Cbor.decode<{ authData: Uint8Array }>(
|
|
172
|
+
new Uint8Array(response.attestationObject),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return new this(
|
|
176
|
+
uint8FromBufLike(creds.rawId),
|
|
177
|
+
_authDataToCose(attObject.authData),
|
|
178
|
+
creds.authenticatorAttachment ?? undefined,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
protected _publicKey: CosePublicKey;
|
|
183
|
+
|
|
184
|
+
public constructor(
|
|
185
|
+
public readonly rawId: Uint8Array,
|
|
186
|
+
cose: Uint8Array,
|
|
187
|
+
protected authenticatorAttachment: AuthenticatorAttachment | undefined,
|
|
188
|
+
) {
|
|
189
|
+
super();
|
|
190
|
+
this._publicKey = new CosePublicKey(cose);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public getPublicKey(): PublicKey {
|
|
194
|
+
return this._publicKey;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* WebAuthn level 3 spec introduces a new attribute on successful WebAuthn interactions,
|
|
199
|
+
* see https://w3c.github.io/webauthn/#dom-publickeycredential-authenticatorattachment.
|
|
200
|
+
* This attribute is already implemented for Chrome, Safari and Edge.
|
|
201
|
+
*
|
|
202
|
+
* Given the attribute is only available after a successful interaction, the information is
|
|
203
|
+
* provided opportunistically and might also be `undefined`.
|
|
204
|
+
*/
|
|
205
|
+
public getAuthenticatorAttachment(): AuthenticatorAttachment | undefined {
|
|
206
|
+
return this.authenticatorAttachment;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public async sign(blob: Uint8Array): Promise<Signature> {
|
|
210
|
+
const result = (await navigator.credentials.get({
|
|
211
|
+
publicKey: {
|
|
212
|
+
allowCredentials: [
|
|
213
|
+
{
|
|
214
|
+
type: 'public-key',
|
|
215
|
+
id: this.rawId,
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
challenge: blob,
|
|
219
|
+
userVerification: 'preferred',
|
|
220
|
+
},
|
|
221
|
+
})) as PublicKeyCredentialWithAttachment;
|
|
222
|
+
|
|
223
|
+
if (result.authenticatorAttachment !== null) {
|
|
224
|
+
this.authenticatorAttachment = result.authenticatorAttachment;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const response = result.response as AuthenticatorAssertionResponse;
|
|
228
|
+
|
|
229
|
+
const encoded = Cbor.encode({
|
|
230
|
+
authenticator_data: response.authenticatorData,
|
|
231
|
+
client_data_json: bytesToUtf8(new Uint8Array(response.clientDataJSON)),
|
|
232
|
+
signature: response.signature,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
if (!encoded) {
|
|
236
|
+
throw new Error('failed to encode cbor');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
Object.assign(encoded, {
|
|
240
|
+
__signature__: undefined,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return encoded as Signature;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Allow for JSON serialization of all information needed to reuse this identity.
|
|
248
|
+
*/
|
|
249
|
+
public toJSON(): JsonnableWebAuthnIdentity {
|
|
250
|
+
return {
|
|
251
|
+
publicKey: bytesToHex(this._publicKey.getCose()),
|
|
252
|
+
rawId: bytesToHex(this.rawId),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* ReturnType<WebAuthnIdentity.toJSON>
|
|
259
|
+
*/
|
|
260
|
+
export interface JsonnableWebAuthnIdentity {
|
|
261
|
+
// The hexadecimal representation of the DER encoded public key.
|
|
262
|
+
publicKey: string;
|
|
263
|
+
// The string representation of the local WebAuthn Credential.id (base64url encoded).
|
|
264
|
+
rawId: string;
|
|
265
|
+
}
|
package/src/identity/index.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module api
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './identity/ed25519.ts';
|
|
6
|
+
export * from './identity/ecdsa.ts';
|
|
7
|
+
export * from './identity/delegation.ts';
|
|
8
|
+
export * from './identity/partial.ts';
|
|
9
|
+
export { WebAuthnIdentity } from './identity/webauthn.ts';
|
|
10
|
+
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '#agent';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated due to size of dependencies. Use `@icp-sdk/identity/secp256k1` instead.
|
|
14
|
+
*/
|
|
15
|
+
export class Secp256k1KeyIdentity {
|
|
16
|
+
constructor() {
|
|
17
|
+
throw new Error('Secp256k1KeyIdentity is available in @icp-sdk/identity/secp256k1');
|
|
18
|
+
}
|
|
19
|
+
}
|