@icp-sdk/core 4.2.2 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent/actor.d.ts +203 -0
- package/lib/cjs/agent/actor.d.ts.map +1 -0
- package/lib/cjs/agent/actor.js +341 -0
- package/lib/cjs/agent/actor.js.map +1 -0
- package/lib/cjs/agent/agent/api.d.ts +216 -0
- package/lib/cjs/agent/agent/api.d.ts.map +1 -0
- package/lib/cjs/agent/agent/api.js +39 -0
- package/lib/cjs/agent/agent/api.js.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +19 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +171 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/index.js +1079 -0
- package/lib/cjs/agent/agent/http/index.js.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/transforms.js +135 -0
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
- package/lib/cjs/agent/agent/http/types.d.ts +81 -0
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/types.js +43 -0
- package/lib/cjs/agent/agent/http/types.js.map +1 -0
- package/lib/cjs/agent/agent/index.d.ts +3 -0
- package/lib/cjs/agent/agent/index.d.ts.map +1 -0
- package/lib/cjs/agent/agent/index.js +19 -0
- package/lib/cjs/agent/agent/index.js.map +1 -0
- package/lib/cjs/agent/auth.d.ts +91 -0
- package/lib/cjs/agent/auth.d.ts.map +1 -0
- package/lib/cjs/agent/auth.js +65 -0
- package/lib/cjs/agent/auth.js.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts +93 -0
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/canisterStatus/index.js +301 -0
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
- package/lib/cjs/agent/cbor.d.ts +26 -0
- package/lib/cjs/agent/cbor.d.ts.map +1 -0
- package/lib/cjs/agent/cbor.js +93 -0
- package/lib/cjs/agent/cbor.js.map +1 -0
- package/lib/cjs/agent/certificate.d.ts +228 -0
- package/lib/cjs/agent/certificate.d.ts.map +1 -0
- package/lib/cjs/agent/certificate.js +591 -0
- package/lib/cjs/agent/certificate.js.map +1 -0
- package/lib/cjs/agent/constants.d.ts +14 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -0
- package/lib/cjs/agent/constants.js +18 -0
- package/lib/cjs/agent/constants.js.map +1 -0
- package/lib/cjs/agent/der.d.ts +34 -0
- package/lib/cjs/agent/der.d.ts.map +1 -0
- package/lib/cjs/agent/der.js +175 -0
- package/lib/cjs/agent/der.js.map +1 -0
- package/lib/cjs/agent/errors.d.ts +380 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -0
- package/lib/cjs/agent/errors.js +733 -0
- package/lib/cjs/agent/errors.js.map +1 -0
- package/lib/cjs/agent/fetch_candid.d.ts +9 -0
- package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
- package/lib/cjs/agent/fetch_candid.js +69 -0
- package/lib/cjs/agent/fetch_candid.js.map +1 -0
- package/lib/cjs/agent/index.d.ts +31 -1
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +59 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +24 -0
- package/lib/cjs/agent/observable.d.ts.map +1 -0
- package/lib/cjs/agent/observable.js +34 -0
- package/lib/cjs/agent/observable.js.map +1 -0
- package/lib/cjs/agent/polling/backoff.d.ts +50 -0
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
- package/lib/cjs/agent/polling/backoff.js +90 -0
- package/lib/cjs/agent/polling/backoff.js.map +1 -0
- package/lib/cjs/agent/polling/index.d.ts +63 -0
- package/lib/cjs/agent/polling/index.d.ts.map +1 -0
- package/lib/cjs/agent/polling/index.js +183 -0
- package/lib/cjs/agent/polling/index.js.map +1 -0
- package/lib/cjs/agent/polling/strategy.d.ts +52 -0
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
- package/lib/cjs/agent/polling/strategy.js +104 -0
- package/lib/cjs/agent/polling/strategy.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +16 -0
- package/lib/cjs/agent/public_key.d.ts.map +1 -0
- package/lib/cjs/agent/public_key.js +52 -0
- package/lib/cjs/agent/public_key.js.map +1 -0
- package/lib/cjs/agent/request_id.d.ts +24 -0
- package/lib/cjs/agent/request_id.d.ts.map +1 -0
- package/lib/cjs/agent/request_id.js +88 -0
- package/lib/cjs/agent/request_id.js.map +1 -0
- package/lib/cjs/agent/utils/bls.d.ts +10 -0
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
- package/lib/cjs/agent/utils/bls.js +20 -0
- package/lib/cjs/agent/utils/bls.js.map +1 -0
- package/lib/cjs/agent/utils/buffer.d.ts +22 -0
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/agent/utils/buffer.js +55 -0
- package/lib/cjs/agent/utils/buffer.js.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.js +148 -0
- package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
- package/lib/cjs/agent/utils/leb.d.ts +3 -0
- package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
- package/lib/cjs/agent/utils/leb.js +17 -0
- package/lib/cjs/agent/utils/leb.js.map +1 -0
- package/lib/cjs/agent/utils/random.d.ts +6 -0
- package/lib/cjs/agent/utils/random.d.ts.map +1 -0
- package/lib/cjs/agent/utils/random.js +29 -0
- package/lib/cjs/agent/utils/random.js.map +1 -0
- package/lib/cjs/candid/candid-core.d.ts +72 -0
- package/lib/cjs/candid/candid-core.d.ts.map +1 -0
- package/lib/cjs/candid/candid-core.js +251 -0
- package/lib/cjs/candid/candid-core.js.map +1 -0
- package/lib/cjs/candid/candid-ui.d.ts +35 -0
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
- package/lib/cjs/candid/candid-ui.js +317 -0
- package/lib/cjs/candid/candid-ui.js.map +1 -0
- package/lib/cjs/candid/idl.d.ts +579 -0
- package/lib/cjs/candid/idl.d.ts.map +1 -0
- package/lib/cjs/candid/idl.js +2228 -0
- package/lib/cjs/candid/idl.js.map +1 -0
- package/lib/cjs/candid/index.d.ts +11 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +33 -1
- package/lib/cjs/candid/index.js.map +1 -1
- package/lib/cjs/candid/types.d.ts +6 -0
- package/lib/cjs/candid/types.d.ts.map +1 -0
- package/lib/cjs/candid/types.js +4 -0
- package/lib/cjs/candid/types.js.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
- package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/cjs/candid/utils/bigint-math.js +30 -0
- package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +86 -0
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
- package/lib/cjs/candid/utils/buffer.js +191 -0
- package/lib/cjs/candid/utils/buffer.js.map +1 -0
- package/lib/cjs/candid/utils/hash.d.ts +7 -0
- package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
- package/lib/cjs/candid/utils/hash.js +33 -0
- package/lib/cjs/candid/utils/hash.js.map +1 -0
- package/lib/cjs/candid/utils/leb128.d.ts +65 -0
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
- package/lib/cjs/candid/utils/leb128.js +228 -0
- package/lib/cjs/candid/utils/leb128.js.map +1 -0
- package/lib/cjs/identity/identity/delegation.d.ts +164 -0
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
- package/lib/cjs/identity/identity/delegation.js +302 -0
- package/lib/cjs/identity/identity/delegation.js.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ecdsa.js +117 -0
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
- package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/cjs/identity/identity/ed25519.js +200 -0
- package/lib/cjs/identity/identity/ed25519.js.map +1 -0
- package/lib/cjs/identity/identity/partial.d.ts +34 -0
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
- package/lib/cjs/identity/identity/partial.js +54 -0
- package/lib/cjs/identity/identity/partial.js.map +1 -0
- package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/cjs/identity/identity/webauthn.js +197 -0
- package/lib/cjs/identity/identity/webauthn.js.map +1 -0
- package/lib/cjs/identity/index.d.ts +15 -1
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +24 -1
- package/lib/cjs/identity/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/der.js +165 -0
- package/lib/cjs/identity/secp256k1/der.js.map +1 -0
- package/lib/cjs/identity/secp256k1/index.d.ts +4 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +4 -1
- package/lib/cjs/identity/secp256k1/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/pem.js +75 -0
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/cjs/principal/index.d.ts +3 -1
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +7 -1
- package/lib/cjs/principal/index.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +50 -0
- package/lib/cjs/principal/principal.d.ts.map +1 -0
- package/lib/cjs/principal/principal.js +148 -0
- package/lib/cjs/principal/principal.js.map +1 -0
- package/lib/cjs/principal/utils/base32.d.ts +10 -0
- package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
- package/lib/cjs/principal/utils/base32.js +90 -0
- package/lib/cjs/principal/utils/base32.js.map +1 -0
- package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
- package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/cjs/principal/utils/getCrc.js +53 -0
- package/lib/cjs/principal/utils/getCrc.js.map +1 -0
- package/lib/esm/agent/actor.d.ts +203 -0
- package/lib/esm/agent/actor.d.ts.map +1 -0
- package/lib/esm/agent/actor.js +337 -0
- package/lib/esm/agent/actor.js.map +1 -0
- package/lib/esm/agent/agent/api.d.ts +216 -0
- package/lib/esm/agent/agent/api.d.ts.map +1 -0
- package/lib/esm/agent/agent/api.js +34 -0
- package/lib/esm/agent/agent/api.js.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +16 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +171 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/index.js +1037 -0
- package/lib/esm/agent/agent/http/index.js.map +1 -0
- package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/transforms.js +128 -0
- package/lib/esm/agent/agent/http/transforms.js.map +1 -0
- package/lib/esm/agent/agent/http/types.d.ts +81 -0
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/types.js +39 -0
- package/lib/esm/agent/agent/http/types.js.map +1 -0
- package/lib/esm/agent/agent/index.d.ts +3 -0
- package/lib/esm/agent/agent/index.d.ts.map +1 -0
- package/lib/esm/agent/agent/index.js +3 -0
- package/lib/esm/agent/agent/index.js.map +1 -0
- package/lib/esm/agent/auth.d.ts +91 -0
- package/lib/esm/agent/auth.d.ts.map +1 -0
- package/lib/esm/agent/auth.js +59 -0
- package/lib/esm/agent/auth.js.map +1 -0
- package/lib/esm/agent/canister-env/index.d.ts +110 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +110 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +93 -0
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/canisterStatus/index.js +261 -0
- package/lib/esm/agent/canisterStatus/index.js.map +1 -0
- package/lib/esm/agent/cbor.d.ts +26 -0
- package/lib/esm/agent/cbor.d.ts.map +1 -0
- package/lib/esm/agent/cbor.js +54 -0
- package/lib/esm/agent/cbor.js.map +1 -0
- package/lib/esm/agent/certificate.d.ts +228 -0
- package/lib/esm/agent/certificate.d.ts.map +1 -0
- package/lib/esm/agent/certificate.js +545 -0
- package/lib/esm/agent/certificate.js.map +1 -0
- package/lib/esm/agent/constants.d.ts +14 -0
- package/lib/esm/agent/constants.d.ts.map +1 -0
- package/lib/esm/agent/constants.js +15 -0
- package/lib/esm/agent/constants.js.map +1 -0
- package/lib/esm/agent/der.d.ts +34 -0
- package/lib/esm/agent/der.d.ts.map +1 -0
- package/lib/esm/agent/der.js +166 -0
- package/lib/esm/agent/der.js.map +1 -0
- package/lib/esm/agent/errors.d.ts +380 -0
- package/lib/esm/agent/errors.d.ts.map +1 -0
- package/lib/esm/agent/errors.js +678 -0
- package/lib/esm/agent/errors.js.map +1 -0
- package/lib/esm/agent/fetch_candid.d.ts +9 -0
- package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
- package/lib/esm/agent/fetch_candid.js +33 -0
- package/lib/esm/agent/fetch_candid.js.map +1 -0
- package/lib/esm/agent/index.d.ts +31 -1
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +31 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +24 -0
- package/lib/esm/agent/observable.d.ts.map +1 -0
- package/lib/esm/agent/observable.js +29 -0
- package/lib/esm/agent/observable.js.map +1 -0
- package/lib/esm/agent/polling/backoff.d.ts +50 -0
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
- package/lib/esm/agent/polling/backoff.js +85 -0
- package/lib/esm/agent/polling/backoff.js.map +1 -0
- package/lib/esm/agent/polling/index.d.ts +63 -0
- package/lib/esm/agent/polling/index.d.ts.map +1 -0
- package/lib/esm/agent/polling/index.js +144 -0
- package/lib/esm/agent/polling/index.js.map +1 -0
- package/lib/esm/agent/polling/strategy.d.ts +52 -0
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
- package/lib/esm/agent/polling/strategy.js +94 -0
- package/lib/esm/agent/polling/strategy.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +16 -0
- package/lib/esm/agent/public_key.d.ts.map +1 -0
- package/lib/esm/agent/public_key.js +48 -0
- package/lib/esm/agent/public_key.js.map +1 -0
- package/lib/esm/agent/request_id.d.ts +24 -0
- package/lib/esm/agent/request_id.d.ts.map +1 -0
- package/lib/esm/agent/request_id.js +83 -0
- package/lib/esm/agent/request_id.js.map +1 -0
- package/lib/esm/agent/utils/bls.d.ts +10 -0
- package/lib/esm/agent/utils/bls.d.ts.map +1 -0
- package/lib/esm/agent/utils/bls.js +17 -0
- package/lib/esm/agent/utils/bls.js.map +1 -0
- package/lib/esm/agent/utils/buffer.d.ts +22 -0
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
- package/lib/esm/agent/utils/buffer.js +50 -0
- package/lib/esm/agent/utils/buffer.js.map +1 -0
- package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableMap.js +144 -0
- package/lib/esm/agent/utils/expirableMap.js.map +1 -0
- package/lib/esm/agent/utils/leb.d.ts +3 -0
- package/lib/esm/agent/utils/leb.d.ts.map +1 -0
- package/lib/esm/agent/utils/leb.js +12 -0
- package/lib/esm/agent/utils/leb.js.map +1 -0
- package/lib/esm/agent/utils/random.d.ts +6 -0
- package/lib/esm/agent/utils/random.d.ts.map +1 -0
- package/lib/esm/agent/utils/random.js +25 -0
- package/lib/esm/agent/utils/random.js.map +1 -0
- package/lib/esm/candid/candid-core.d.ts +72 -0
- package/lib/esm/candid/candid-core.d.ts.map +1 -0
- package/lib/esm/candid/candid-core.js +241 -0
- package/lib/esm/candid/candid-core.js.map +1 -0
- package/lib/esm/candid/candid-ui.d.ts +35 -0
- package/lib/esm/candid/candid-ui.d.ts.map +1 -0
- package/lib/esm/candid/candid-ui.js +272 -0
- package/lib/esm/candid/candid-ui.js.map +1 -0
- package/lib/esm/candid/idl.d.ts +579 -0
- package/lib/esm/candid/idl.d.ts.map +1 -0
- package/lib/esm/candid/idl.js +2189 -0
- package/lib/esm/candid/idl.js.map +1 -0
- package/lib/esm/candid/index.d.ts +11 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +10 -1
- package/lib/esm/candid/index.js.map +1 -1
- package/lib/esm/candid/types.d.ts +6 -0
- package/lib/esm/candid/types.d.ts.map +1 -0
- package/lib/esm/candid/types.js +3 -0
- package/lib/esm/candid/types.js.map +1 -0
- package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
- package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
- package/lib/esm/candid/utils/bigint-math.js +26 -0
- package/lib/esm/candid/utils/bigint-math.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +86 -0
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
- package/lib/esm/candid/utils/buffer.js +182 -0
- package/lib/esm/candid/utils/buffer.js.map +1 -0
- package/lib/esm/candid/utils/hash.d.ts +7 -0
- package/lib/esm/candid/utils/hash.d.ts.map +1 -0
- package/lib/esm/candid/utils/hash.js +30 -0
- package/lib/esm/candid/utils/hash.js.map +1 -0
- package/lib/esm/candid/utils/leb128.d.ts +65 -0
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
- package/lib/esm/candid/utils/leb128.js +216 -0
- package/lib/esm/candid/utils/leb128.js.map +1 -0
- package/lib/esm/identity/identity/delegation.d.ts +164 -0
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
- package/lib/esm/identity/identity/delegation.js +294 -0
- package/lib/esm/identity/identity/delegation.js.map +1 -0
- package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
- package/lib/esm/identity/identity/ecdsa.js +112 -0
- package/lib/esm/identity/identity/ecdsa.js.map +1 -0
- package/lib/esm/identity/identity/ed25519.d.ts +67 -0
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
- package/lib/esm/identity/identity/ed25519.js +195 -0
- package/lib/esm/identity/identity/ed25519.js.map +1 -0
- package/lib/esm/identity/identity/partial.d.ts +34 -0
- package/lib/esm/identity/identity/partial.d.ts.map +1 -0
- package/lib/esm/identity/identity/partial.js +50 -0
- package/lib/esm/identity/identity/partial.js.map +1 -0
- package/lib/esm/identity/identity/webauthn.d.ts +51 -0
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
- package/lib/esm/identity/identity/webauthn.js +192 -0
- package/lib/esm/identity/identity/webauthn.js.map +1 -0
- package/lib/esm/identity/index.d.ts +15 -1
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +17 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +33 -0
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/der.js +156 -0
- package/lib/esm/identity/secp256k1/der.js.map +1 -0
- package/lib/esm/identity/secp256k1/index.d.ts +4 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +4 -1
- package/lib/esm/identity/secp256k1/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/pem.js +39 -0
- package/lib/esm/identity/secp256k1/pem.js.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
- package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
- package/lib/esm/principal/index.d.ts +3 -1
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +3 -1
- package/lib/esm/principal/index.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +50 -0
- package/lib/esm/principal/principal.d.ts.map +1 -0
- package/lib/esm/principal/principal.js +144 -0
- package/lib/esm/principal/principal.js.map +1 -0
- package/lib/esm/principal/utils/base32.d.ts +10 -0
- package/lib/esm/principal/utils/base32.d.ts.map +1 -0
- package/lib/esm/principal/utils/base32.js +86 -0
- package/lib/esm/principal/utils/base32.js.map +1 -0
- package/lib/esm/principal/utils/getCrc.d.ts +6 -0
- package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
- package/lib/esm/principal/utils/getCrc.js +50 -0
- package/lib/esm/principal/utils/getCrc.js.map +1 -0
- package/package.json +17 -11
- package/src/agent/actor.ts +576 -0
- package/src/agent/agent/api.ts +262 -0
- package/src/agent/agent/http/index.ts +1405 -0
- package/src/agent/agent/http/transforms.ts +158 -0
- package/src/agent/agent/http/types.ts +126 -0
- package/src/agent/agent/index.ts +2 -0
- package/src/agent/auth.ts +147 -0
- package/src/agent/canister-env/index.ts +191 -1
- package/src/agent/canisterStatus/index.ts +412 -0
- package/src/agent/cbor.ts +63 -0
- package/src/agent/certificate.ts +841 -0
- package/src/agent/constants.ts +19 -0
- package/src/agent/der.ts +170 -0
- package/src/agent/errors.ts +868 -0
- package/src/agent/fetch_candid.ts +37 -0
- package/src/agent/index.ts +37 -1
- package/src/agent/observable.ts +49 -0
- package/src/agent/polling/backoff.ts +130 -0
- package/src/agent/polling/index.ts +250 -0
- package/src/agent/polling/strategy.ts +144 -0
- package/src/agent/public_key.ts +65 -0
- package/src/agent/request_id.ts +92 -0
- package/src/agent/utils/bls.ts +18 -0
- package/src/agent/utils/buffer.ts +60 -0
- package/src/agent/utils/expirableMap.ts +163 -0
- package/src/agent/utils/leb.ts +14 -0
- package/src/agent/utils/random.ts +30 -0
- package/src/candid/candid-core.ts +276 -0
- package/src/candid/candid-ui.ts +289 -0
- package/src/candid/idl.ts +2556 -0
- package/src/candid/index.ts +16 -1
- package/src/candid/types.ts +7 -0
- package/src/candid/utils/bigint-math.ts +26 -0
- package/src/candid/utils/buffer.ts +221 -0
- package/src/candid/utils/hash.ts +31 -0
- package/src/candid/utils/leb128.ts +234 -0
- package/src/identity/identity/delegation.ts +411 -0
- package/src/identity/identity/ecdsa.ts +158 -0
- package/src/identity/identity/ed25519.ts +239 -0
- package/src/identity/identity/partial.ts +60 -0
- package/src/identity/identity/webauthn.ts +265 -0
- package/src/identity/index.ts +19 -1
- package/src/identity/secp256k1/der.ts +156 -0
- package/src/identity/secp256k1/index.ts +5 -1
- package/src/identity/secp256k1/pem.ts +40 -0
- package/src/identity/secp256k1/secp256k1.ts +270 -0
- package/src/package.json +4 -0
- package/src/principal/index.ts +3 -1
- package/src/principal/principal.ts +171 -0
- package/src/principal/utils/base32.ts +101 -0
- package/src/principal/utils/getCrc.ts +52 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { uint8Equals } from '#candid';
|
|
2
|
+
|
|
3
|
+
export const encodeLenBytes = (len: number): number => {
|
|
4
|
+
if (len <= 0x7f) {
|
|
5
|
+
return 1;
|
|
6
|
+
} else if (len <= 0xff) {
|
|
7
|
+
return 2;
|
|
8
|
+
} else if (len <= 0xffff) {
|
|
9
|
+
return 3;
|
|
10
|
+
} else if (len <= 0xffffff) {
|
|
11
|
+
return 4;
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error('Length too long (> 4 bytes)');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const encodeLen = (buf: Uint8Array, offset: number, len: number): number => {
|
|
18
|
+
if (len <= 0x7f) {
|
|
19
|
+
buf[offset] = len;
|
|
20
|
+
return 1;
|
|
21
|
+
} else if (len <= 0xff) {
|
|
22
|
+
buf[offset] = 0x81;
|
|
23
|
+
buf[offset + 1] = len;
|
|
24
|
+
return 2;
|
|
25
|
+
} else if (len <= 0xffff) {
|
|
26
|
+
buf[offset] = 0x82;
|
|
27
|
+
buf[offset + 1] = len >> 8;
|
|
28
|
+
buf[offset + 2] = len;
|
|
29
|
+
return 3;
|
|
30
|
+
} else if (len <= 0xffffff) {
|
|
31
|
+
buf[offset] = 0x83;
|
|
32
|
+
buf[offset + 1] = len >> 16;
|
|
33
|
+
buf[offset + 2] = len >> 8;
|
|
34
|
+
buf[offset + 3] = len;
|
|
35
|
+
return 4;
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error('Length too long (> 4 bytes)');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const decodeLenBytes = (buf: Uint8Array, offset: number): number => {
|
|
42
|
+
if (buf[offset] < 0x80) return 1;
|
|
43
|
+
if (buf[offset] === 0x80) throw new Error('Invalid length 0');
|
|
44
|
+
if (buf[offset] === 0x81) return 2;
|
|
45
|
+
if (buf[offset] === 0x82) return 3;
|
|
46
|
+
if (buf[offset] === 0x83) return 4;
|
|
47
|
+
throw new Error('Length too long (> 4 bytes)');
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const decodeLen = (buf: Uint8Array, offset: number): number => {
|
|
51
|
+
const lenBytes = decodeLenBytes(buf, offset);
|
|
52
|
+
if (lenBytes === 1) return buf[offset];
|
|
53
|
+
else if (lenBytes === 2) return buf[offset + 1];
|
|
54
|
+
else if (lenBytes === 3) return (buf[offset + 1] << 8) + buf[offset + 2];
|
|
55
|
+
else if (lenBytes === 4)
|
|
56
|
+
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
|
|
57
|
+
throw new Error('Length too long (> 4 bytes)');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE
|
|
62
|
+
*/
|
|
63
|
+
export const DER_COSE_OID = Uint8Array.from([
|
|
64
|
+
...[0x30, 0x0c], // SEQUENCE
|
|
65
|
+
...[0x06, 0x0a], // OID with 10 bytes
|
|
66
|
+
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x83, 0xb8, 0x43, 0x01, 0x01], // DER encoded COSE
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A DER encoded `SEQUENCE(OID)` for the Ed25519 algorithm
|
|
71
|
+
*/
|
|
72
|
+
export const ED25519_OID = Uint8Array.from([
|
|
73
|
+
...[0x30, 0x05], // SEQUENCE
|
|
74
|
+
...[0x06, 0x03], // OID with 3 bytes
|
|
75
|
+
...[0x2b, 0x65, 0x70], // id-Ed25519 OID
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm
|
|
80
|
+
*/
|
|
81
|
+
export const SECP256K1_OID = Uint8Array.from([
|
|
82
|
+
...[0x30, 0x10], // SEQUENCE
|
|
83
|
+
...[0x06, 0x07], // OID with 7 bytes
|
|
84
|
+
...[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], // OID ECDSA
|
|
85
|
+
...[0x06, 0x05], // OID with 5 bytes
|
|
86
|
+
...[0x2b, 0x81, 0x04, 0x00, 0x0a], // OID secp256k1
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so:
|
|
91
|
+
* `SEQUENCE(oid, BITSTRING(payload))`
|
|
92
|
+
* @param payload The payload to encode as the bit string
|
|
93
|
+
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
|
|
94
|
+
*/
|
|
95
|
+
export function wrapDER(payload: Uint8Array, oid: Uint8Array): Uint8Array {
|
|
96
|
+
// The Bit String header needs to include the unused bit count byte in its length
|
|
97
|
+
const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1);
|
|
98
|
+
const len = oid.byteLength + bitStringHeaderLength + payload.byteLength;
|
|
99
|
+
let offset = 0;
|
|
100
|
+
const buf = new Uint8Array(1 + encodeLenBytes(len) + len);
|
|
101
|
+
// Sequence
|
|
102
|
+
buf[offset++] = 0x30;
|
|
103
|
+
// Sequence Length
|
|
104
|
+
offset += encodeLen(buf, offset, len);
|
|
105
|
+
|
|
106
|
+
// OID
|
|
107
|
+
buf.set(oid, offset);
|
|
108
|
+
offset += oid.byteLength;
|
|
109
|
+
|
|
110
|
+
// Bit String Header
|
|
111
|
+
buf[offset++] = 0x03;
|
|
112
|
+
offset += encodeLen(buf, offset, payload.byteLength + 1);
|
|
113
|
+
// 0 padding
|
|
114
|
+
buf[offset++] = 0x00;
|
|
115
|
+
buf.set(new Uint8Array(payload), offset);
|
|
116
|
+
|
|
117
|
+
return buf;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Extracts a payload from the given `derEncoded` data, and checks that it was tagged with the given `oid`.
|
|
122
|
+
*
|
|
123
|
+
* `derEncoded = SEQUENCE(oid, BITSTRING(payload))`
|
|
124
|
+
* @param derEncoded The DER encoded and tagged data
|
|
125
|
+
* @param oid The DER encoded (and SEQUENCE wrapped!) expected OID
|
|
126
|
+
* @returns The unwrapped payload
|
|
127
|
+
*/
|
|
128
|
+
export const unwrapDER = (derEncoded: Uint8Array, oid: Uint8Array): Uint8Array => {
|
|
129
|
+
let offset = 0;
|
|
130
|
+
const expect = (n: number, msg: string) => {
|
|
131
|
+
if (buf[offset++] !== n) {
|
|
132
|
+
throw new Error('Expected: ' + msg);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const buf = new Uint8Array(derEncoded);
|
|
137
|
+
expect(0x30, 'sequence');
|
|
138
|
+
offset += decodeLenBytes(buf, offset);
|
|
139
|
+
|
|
140
|
+
if (!uint8Equals(buf.slice(offset, offset + oid.byteLength), oid)) {
|
|
141
|
+
throw new Error('Not the expected OID.');
|
|
142
|
+
}
|
|
143
|
+
offset += oid.byteLength;
|
|
144
|
+
|
|
145
|
+
expect(0x03, 'bit string');
|
|
146
|
+
const payloadLen = decodeLen(buf, offset) - 1; // Subtracting 1 to account for the 0 padding
|
|
147
|
+
offset += decodeLenBytes(buf, offset);
|
|
148
|
+
expect(0x00, '0 padding');
|
|
149
|
+
const result = buf.slice(offset);
|
|
150
|
+
if (payloadLen !== result.length) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`DER payload mismatch: Expected length ${payloadLen} actual length ${result.length}`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as asn1js from 'asn1js';
|
|
2
|
+
|
|
3
|
+
const HEADER = `-----BEGIN EC PRIVATE KEY-----`;
|
|
4
|
+
const FOOTER = `-----END EC PRIVATE KEY-----`;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parse a PEM-encoded key into a Uint8Array
|
|
8
|
+
* @param pem - the PEM-encoded key
|
|
9
|
+
* @returns secret key as a Uint8Array
|
|
10
|
+
*/
|
|
11
|
+
export function pemToSecretKey(pem: string): Uint8Array {
|
|
12
|
+
const lines = pem.trim().split('\n');
|
|
13
|
+
const header = lines[0].trim();
|
|
14
|
+
const footer = lines[lines.length - 1].trim();
|
|
15
|
+
if (lines.length < 3) {
|
|
16
|
+
throw new Error('Invalid PEM format');
|
|
17
|
+
}
|
|
18
|
+
if (!header.startsWith(HEADER)) {
|
|
19
|
+
throw new Error('Invalid PEM header');
|
|
20
|
+
}
|
|
21
|
+
if (!footer.startsWith(FOOTER)) {
|
|
22
|
+
throw new Error('Invalid PEM footer');
|
|
23
|
+
}
|
|
24
|
+
const base64Data = lines.slice(1, -1).join('').replace(/\r?\n/g, '');
|
|
25
|
+
const rawKey = Uint8Array.from(atob(base64Data), c => c.charCodeAt(0));
|
|
26
|
+
|
|
27
|
+
// Parse the key as ASN.1 object
|
|
28
|
+
try {
|
|
29
|
+
const asn1 = asn1js.fromBER(rawKey);
|
|
30
|
+
// OID for secp256k1
|
|
31
|
+
if (!asn1.result.toString().includes(`OBJECT IDENTIFIER : 1.3.132.0.10`)) {
|
|
32
|
+
throw new Error('Invalid curve, must be secp256k1');
|
|
33
|
+
}
|
|
34
|
+
// Returns the 32-byte raw private key at the appropriate offset
|
|
35
|
+
return rawKey.slice(7, 39);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(error);
|
|
38
|
+
throw new Error('Encountered error while parsing PEM key');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DerEncodedPublicKey,
|
|
3
|
+
type KeyPair,
|
|
4
|
+
type Signature,
|
|
5
|
+
type PublicKey,
|
|
6
|
+
SignIdentity,
|
|
7
|
+
} from '#agent';
|
|
8
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
9
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
10
|
+
import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';
|
|
11
|
+
import * as bip39 from '@scure/bip39';
|
|
12
|
+
import { HDKey } from '@scure/bip32';
|
|
13
|
+
import { SECP256K1_OID, unwrapDER, wrapDER } from './der.ts';
|
|
14
|
+
import { pemToSecretKey } from './pem.ts';
|
|
15
|
+
import { uint8FromBufLike } from '#candid';
|
|
16
|
+
|
|
17
|
+
declare type PublicKeyHex = string;
|
|
18
|
+
declare type SecretKeyHex = string;
|
|
19
|
+
export declare type JsonableSecp256k1Identity = [PublicKeyHex, SecretKeyHex];
|
|
20
|
+
|
|
21
|
+
declare type KeyLike = PublicKey | DerEncodedPublicKey | ArrayBuffer | ArrayBufferView | Uint8Array;
|
|
22
|
+
|
|
23
|
+
function isObject(value: unknown) {
|
|
24
|
+
return value !== null && typeof value === 'object';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Secp256k1PublicKey implements PublicKey {
|
|
28
|
+
public static fromRaw(rawKey: Uint8Array): Secp256k1PublicKey {
|
|
29
|
+
return new Secp256k1PublicKey(rawKey);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static fromDer(derKey: DerEncodedPublicKey): Secp256k1PublicKey {
|
|
33
|
+
return new Secp256k1PublicKey(this.derDecode(derKey));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Construct Secp256k1PublicKey from an existing PublicKey
|
|
38
|
+
* @param {unknown} maybeKey - existing PublicKey, ArrayBuffer, DerEncodedPublicKey, or hex string
|
|
39
|
+
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
|
40
|
+
*/
|
|
41
|
+
public static from(maybeKey: unknown): Secp256k1PublicKey {
|
|
42
|
+
if (typeof maybeKey === 'string') {
|
|
43
|
+
const key = hexToBytes(maybeKey);
|
|
44
|
+
return this.fromRaw(key);
|
|
45
|
+
} else if (isObject(maybeKey)) {
|
|
46
|
+
const key = maybeKey as KeyLike;
|
|
47
|
+
if (isObject(key) && Object.hasOwnProperty.call(key, '__derEncodedPublicKey__')) {
|
|
48
|
+
return this.fromDer(key as DerEncodedPublicKey);
|
|
49
|
+
} else if (ArrayBuffer.isView(key)) {
|
|
50
|
+
const view = key as ArrayBufferView;
|
|
51
|
+
return this.fromRaw(uint8FromBufLike(view.buffer));
|
|
52
|
+
} else if (key instanceof ArrayBuffer) {
|
|
53
|
+
return this.fromRaw(uint8FromBufLike(key));
|
|
54
|
+
} else if ('rawKey' in key && key['rawKey'] !== undefined) {
|
|
55
|
+
return this.fromRaw(key.rawKey);
|
|
56
|
+
} else if ('derKey' in key) {
|
|
57
|
+
return this.fromDer(key.derKey as DerEncodedPublicKey);
|
|
58
|
+
} else if ('toDer' in key) {
|
|
59
|
+
return this.fromDer(key.toDer());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Cannot construct Secp256k1PublicKey from the provided key.');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private static derEncode(publicKey: Uint8Array): DerEncodedPublicKey {
|
|
66
|
+
const key = uint8FromBufLike(wrapDER(publicKey, SECP256K1_OID).buffer) as DerEncodedPublicKey;
|
|
67
|
+
key.__derEncodedPublicKey__ = undefined;
|
|
68
|
+
return key;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private static derDecode(key: DerEncodedPublicKey): Uint8Array {
|
|
72
|
+
return unwrapDER(key, SECP256K1_OID);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#rawKey: Uint8Array;
|
|
76
|
+
|
|
77
|
+
public get rawKey(): Uint8Array {
|
|
78
|
+
return this.#rawKey;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#derKey: DerEncodedPublicKey;
|
|
82
|
+
|
|
83
|
+
public get derKey(): DerEncodedPublicKey {
|
|
84
|
+
return this.#derKey;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
|
88
|
+
private constructor(key: Uint8Array) {
|
|
89
|
+
this.#rawKey = key;
|
|
90
|
+
this.#derKey = Secp256k1PublicKey.derEncode(key);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public toDer(): DerEncodedPublicKey {
|
|
94
|
+
return this.derKey;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public toRaw(): Uint8Array {
|
|
98
|
+
return this.rawKey;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class Secp256k1KeyIdentity extends SignIdentity {
|
|
103
|
+
/**
|
|
104
|
+
* Generates an identity. If a seed is provided, the keys are generated from the
|
|
105
|
+
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
|
106
|
+
* This method throws an error in case the seed is not 32 bytes long or invalid
|
|
107
|
+
* for use as a private key.
|
|
108
|
+
* @param {Uint8Array} seed the optional seed
|
|
109
|
+
* @returns {Secp256k1KeyIdentity} Secp256k1KeyIdentity
|
|
110
|
+
*/
|
|
111
|
+
public static generate(seed?: Uint8Array): Secp256k1KeyIdentity {
|
|
112
|
+
if (seed && seed.byteLength !== 32) {
|
|
113
|
+
throw new Error('Secp256k1 Seed needs to be 32 bytes long.');
|
|
114
|
+
}
|
|
115
|
+
let privateKey: Uint8Array;
|
|
116
|
+
|
|
117
|
+
if (seed) {
|
|
118
|
+
// private key from seed according to https://en.bitcoin.it/wiki/BIP_0032
|
|
119
|
+
// master key generation:
|
|
120
|
+
privateKey = seed;
|
|
121
|
+
if (!secp256k1.utils.isValidPrivateKey(privateKey)) {
|
|
122
|
+
throw new Error('The seed is invalid.');
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
privateKey = randomBytes(32);
|
|
126
|
+
while (!secp256k1.utils.isValidPrivateKey(privateKey)) {
|
|
127
|
+
privateKey = randomBytes(32);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const publicKeyRaw = secp256k1.getPublicKey(privateKey, false);
|
|
132
|
+
|
|
133
|
+
const publicKey = Secp256k1PublicKey.fromRaw(publicKeyRaw);
|
|
134
|
+
return new this(publicKey, privateKey);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public static fromParsedJson(obj: JsonableSecp256k1Identity): Secp256k1KeyIdentity {
|
|
138
|
+
const [publicKeyRaw, privateKeyRaw] = obj;
|
|
139
|
+
return new Secp256k1KeyIdentity(
|
|
140
|
+
Secp256k1PublicKey.fromRaw(hexToBytes(publicKeyRaw)),
|
|
141
|
+
hexToBytes(privateKeyRaw),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public static fromJSON(json: string): Secp256k1KeyIdentity {
|
|
146
|
+
const parsed = JSON.parse(json);
|
|
147
|
+
if (Array.isArray(parsed)) {
|
|
148
|
+
if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
|
|
149
|
+
return this.fromParsedJson([parsed[0], parsed[1]]);
|
|
150
|
+
}
|
|
151
|
+
throw new Error('Deserialization error: JSON must have at least 2 items.');
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
|
158
|
+
* @param {Uint8Array} publicKey - Uint8Array
|
|
159
|
+
* @param {Uint8Array} privateKey - Uint8Array
|
|
160
|
+
* @returns {Secp256k1KeyIdentity} Secp256k1KeyIdentity
|
|
161
|
+
*/
|
|
162
|
+
public static fromKeyPair(publicKey: Uint8Array, privateKey: Uint8Array): Secp256k1KeyIdentity {
|
|
163
|
+
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(publicKey), privateKey);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
|
168
|
+
* @param {Uint8Array} secretKey - Uint8Array
|
|
169
|
+
* @returns {Secp256k1KeyIdentity} - Secp256k1KeyIdentity
|
|
170
|
+
*/
|
|
171
|
+
public static fromSecretKey(secretKey: Uint8Array): Secp256k1KeyIdentity {
|
|
172
|
+
const publicKey = secp256k1.getPublicKey(secretKey, false);
|
|
173
|
+
const identity = Secp256k1KeyIdentity.fromKeyPair(publicKey, secretKey);
|
|
174
|
+
return identity;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Generates an identity from a seed phrase. Use carefully - seed phrases should only be used in secure contexts, and you should avoid having users copying and pasting seed phrases as much as possible.
|
|
179
|
+
* @param {string | string[]} seedPhrase - either an array of words or a string of words separated by spaces.
|
|
180
|
+
* @param password - optional password to be used by bip39
|
|
181
|
+
* @returns Secp256k1KeyIdentity
|
|
182
|
+
*/
|
|
183
|
+
public static fromSeedPhrase(
|
|
184
|
+
seedPhrase: string | string[],
|
|
185
|
+
password?: string | undefined,
|
|
186
|
+
): Secp256k1KeyIdentity {
|
|
187
|
+
// Convert to string for convenience
|
|
188
|
+
const phrase = Array.isArray(seedPhrase) ? seedPhrase.join(' ') : seedPhrase;
|
|
189
|
+
// Warn if provided phrase is not conventional
|
|
190
|
+
if (phrase.split(' ').length < 12 || phrase.split(' ').length > 24) {
|
|
191
|
+
console.warn(
|
|
192
|
+
'Warning - an unusually formatted seed phrase has been provided. Decoding may not work as expected',
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const seed = bip39.mnemonicToSeedSync(phrase, password);
|
|
197
|
+
// Ensure the seed is 64 bytes long
|
|
198
|
+
if (seed.byteLength !== 64) {
|
|
199
|
+
throw new Error('Derived seed must be 64 bytes long.');
|
|
200
|
+
}
|
|
201
|
+
const root = HDKey.fromMasterSeed(seed);
|
|
202
|
+
const addrnode = root.derive("m/44'/223'/0'/0/0");
|
|
203
|
+
|
|
204
|
+
if (!addrnode.privateKey) {
|
|
205
|
+
throw new Error('Failed to derive private key from seed phrase');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return Secp256k1KeyIdentity.fromSecretKey(addrnode.privateKey);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Utility method to create a Secp256k1KeyIdentity from a PEM-encoded key.
|
|
213
|
+
* @param pemKey - PEM-encoded key as a string
|
|
214
|
+
* @returns - Secp256k1KeyIdentity
|
|
215
|
+
*/
|
|
216
|
+
public static fromPem(pemKey: string): Secp256k1KeyIdentity {
|
|
217
|
+
const secretKey = pemToSecretKey(pemKey);
|
|
218
|
+
return this.fromSecretKey(secretKey);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_publicKey: Secp256k1PublicKey;
|
|
222
|
+
|
|
223
|
+
protected constructor(
|
|
224
|
+
publicKey: Secp256k1PublicKey,
|
|
225
|
+
protected _privateKey: Uint8Array,
|
|
226
|
+
) {
|
|
227
|
+
super();
|
|
228
|
+
this._publicKey = publicKey;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Serialize this key to JSON-serializable object.
|
|
233
|
+
* @returns {JsonableSecp256k1Identity} JsonableSecp256k1Identity
|
|
234
|
+
*/
|
|
235
|
+
public toJSON(): JsonableSecp256k1Identity {
|
|
236
|
+
return [bytesToHex(this._publicKey.toRaw()), bytesToHex(this._privateKey)];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Return a copy of the key pair.
|
|
241
|
+
* @returns {KeyPair} KeyPair
|
|
242
|
+
*/
|
|
243
|
+
public getKeyPair(): KeyPair {
|
|
244
|
+
return {
|
|
245
|
+
secretKey: this._privateKey,
|
|
246
|
+
publicKey: this._publicKey,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Return the public key.
|
|
252
|
+
* @returns {Required<PublicKey>} Required<PublicKey>
|
|
253
|
+
*/
|
|
254
|
+
public getPublicKey(): Required<PublicKey> {
|
|
255
|
+
return this._publicKey;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Signs a blob of data, with this identity's private key.
|
|
260
|
+
* @param {Uint8Array} data - bytes to hash and sign with this identity's secretKey, producing a signature
|
|
261
|
+
* @returns {Promise<Signature>} signature
|
|
262
|
+
*/
|
|
263
|
+
public async sign(data: Uint8Array): Promise<Signature> {
|
|
264
|
+
const challenge = sha256(data);
|
|
265
|
+
const signature = secp256k1.sign(challenge, this._privateKey).toCompactRawBytes();
|
|
266
|
+
return signature as Signature;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export default Secp256k1KeyIdentity;
|
package/src/package.json
ADDED
package/src/principal/index.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { base32Decode, base32Encode } from './utils/base32.ts';
|
|
2
|
+
import { getCrc32 } from './utils/getCrc.ts';
|
|
3
|
+
import { sha224 } from '@noble/hashes/sha2';
|
|
4
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
5
|
+
|
|
6
|
+
export const JSON_KEY_PRINCIPAL = '__principal__';
|
|
7
|
+
const SELF_AUTHENTICATING_SUFFIX = 2;
|
|
8
|
+
const ANONYMOUS_SUFFIX = 4;
|
|
9
|
+
|
|
10
|
+
const MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR = 'aaaaa-aa';
|
|
11
|
+
|
|
12
|
+
export type JsonnablePrincipal = {
|
|
13
|
+
[JSON_KEY_PRINCIPAL]: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class Principal {
|
|
17
|
+
public static anonymous(): Principal {
|
|
18
|
+
return new this(new Uint8Array([ANONYMOUS_SUFFIX]));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`
|
|
23
|
+
* @returns {Principal} principal of the management canister
|
|
24
|
+
*/
|
|
25
|
+
public static managementCanister(): Principal {
|
|
26
|
+
return this.fromText(MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static selfAuthenticating(publicKey: Uint8Array): Principal {
|
|
30
|
+
const sha = sha224(publicKey);
|
|
31
|
+
return new this(new Uint8Array([...sha, SELF_AUTHENTICATING_SUFFIX]));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static from(other: unknown): Principal {
|
|
35
|
+
if (typeof other === 'string') {
|
|
36
|
+
return Principal.fromText(other);
|
|
37
|
+
} else if (Object.getPrototypeOf(other) === Uint8Array.prototype) {
|
|
38
|
+
return new Principal(other as Uint8Array);
|
|
39
|
+
} else if (Principal.isPrincipal(other)) {
|
|
40
|
+
return new Principal(other._arr);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
throw new Error(`Impossible to convert ${JSON.stringify(other)} to Principal.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static fromHex(hex: string): Principal {
|
|
47
|
+
return new this(hexToBytes(hex));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static fromText(text: string): Principal {
|
|
51
|
+
let maybePrincipal = text;
|
|
52
|
+
// If formatted as JSON string, parse it first
|
|
53
|
+
if (text.includes(JSON_KEY_PRINCIPAL)) {
|
|
54
|
+
const obj = JSON.parse(text);
|
|
55
|
+
if (JSON_KEY_PRINCIPAL in obj) {
|
|
56
|
+
maybePrincipal = obj[JSON_KEY_PRINCIPAL];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');
|
|
61
|
+
|
|
62
|
+
let arr = base32Decode(canisterIdNoDash);
|
|
63
|
+
arr = arr.slice(4, arr.length);
|
|
64
|
+
|
|
65
|
+
const principal = new this(arr);
|
|
66
|
+
if (principal.toText() !== maybePrincipal) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Principal "${principal.toText()}" does not have a valid checksum (original value "${maybePrincipal}" may not be a valid Principal ID).`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return principal;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public static fromUint8Array(arr: Uint8Array): Principal {
|
|
76
|
+
return new this(arr);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static isPrincipal(other: unknown): other is Principal {
|
|
80
|
+
return (
|
|
81
|
+
other instanceof Principal ||
|
|
82
|
+
(typeof other === 'object' &&
|
|
83
|
+
other !== null &&
|
|
84
|
+
'_isPrincipal' in other &&
|
|
85
|
+
(other as { _isPrincipal: boolean })['_isPrincipal'] === true &&
|
|
86
|
+
'_arr' in other &&
|
|
87
|
+
(other as { _arr: Uint8Array })['_arr'] instanceof Uint8Array)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public readonly _isPrincipal = true;
|
|
92
|
+
|
|
93
|
+
protected constructor(private _arr: Uint8Array) {}
|
|
94
|
+
|
|
95
|
+
public isAnonymous(): boolean {
|
|
96
|
+
return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public toUint8Array(): Uint8Array {
|
|
100
|
+
return this._arr;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public toHex(): string {
|
|
104
|
+
return bytesToHex(this._arr).toUpperCase();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public toText(): string {
|
|
108
|
+
const checksumArrayBuf = new ArrayBuffer(4);
|
|
109
|
+
const view = new DataView(checksumArrayBuf);
|
|
110
|
+
view.setUint32(0, getCrc32(this._arr));
|
|
111
|
+
const checksum = new Uint8Array(checksumArrayBuf);
|
|
112
|
+
|
|
113
|
+
const array = new Uint8Array([...checksum, ...this._arr]);
|
|
114
|
+
|
|
115
|
+
const result = base32Encode(array);
|
|
116
|
+
const matches = result.match(/.{1,5}/g);
|
|
117
|
+
if (!matches) {
|
|
118
|
+
// This should only happen if there's no character, which is unreachable.
|
|
119
|
+
throw new Error();
|
|
120
|
+
}
|
|
121
|
+
return matches.join('-');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public toString(): string {
|
|
125
|
+
return this.toText();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Serializes to JSON
|
|
130
|
+
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
|
|
131
|
+
*/
|
|
132
|
+
public toJSON(): JsonnablePrincipal {
|
|
133
|
+
return { [JSON_KEY_PRINCIPAL]: this.toText() };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification
|
|
138
|
+
* @param {Principal} other - a {@link Principal} to compare
|
|
139
|
+
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than
|
|
140
|
+
*/
|
|
141
|
+
public compareTo(other: Principal): 'lt' | 'eq' | 'gt' {
|
|
142
|
+
for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {
|
|
143
|
+
if (this._arr[i] < other._arr[i]) return 'lt';
|
|
144
|
+
else if (this._arr[i] > other._arr[i]) return 'gt';
|
|
145
|
+
}
|
|
146
|
+
// Here, at least one principal is a prefix of the other principal (they could be the same)
|
|
147
|
+
if (this._arr.length < other._arr.length) return 'lt';
|
|
148
|
+
if (this._arr.length > other._arr.length) return 'gt';
|
|
149
|
+
return 'eq';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method
|
|
154
|
+
* @param other a {@link Principal} to compare
|
|
155
|
+
* @returns {boolean} boolean
|
|
156
|
+
*/
|
|
157
|
+
public ltEq(other: Principal): boolean {
|
|
158
|
+
const cmp = this.compareTo(other);
|
|
159
|
+
return cmp == 'lt' || cmp == 'eq';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method
|
|
164
|
+
* @param other a {@link Principal} to compare
|
|
165
|
+
* @returns {boolean} boolean
|
|
166
|
+
*/
|
|
167
|
+
public gtEq(other: Principal): boolean {
|
|
168
|
+
const cmp = this.compareTo(other);
|
|
169
|
+
return cmp == 'gt' || cmp == 'eq';
|
|
170
|
+
}
|
|
171
|
+
}
|