@weaveprotocol/core 0.1.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/README.md +1106 -0
- package/dist/elements/auth-styles.d.ts +18 -0
- package/dist/elements/auth-styles.d.ts.map +1 -0
- package/dist/elements/auth-styles.js +150 -0
- package/dist/elements/auth-styles.js.map +1 -0
- package/dist/elements/dom.d.ts +28 -0
- package/dist/elements/dom.d.ts.map +1 -0
- package/dist/elements/dom.js +74 -0
- package/dist/elements/dom.js.map +1 -0
- package/dist/elements/index.d.ts +13 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/index.js +11 -0
- package/dist/elements/index.js.map +1 -0
- package/dist/elements/weave-auth.d.ts +52 -0
- package/dist/elements/weave-auth.d.ts.map +1 -0
- package/dist/elements/weave-auth.js +427 -0
- package/dist/elements/weave-auth.js.map +1 -0
- package/dist/identity/account-store.d.ts +113 -0
- package/dist/identity/account-store.d.ts.map +1 -0
- package/dist/identity/account-store.js +305 -0
- package/dist/identity/account-store.js.map +1 -0
- package/dist/identity/account-vault.d.ts +199 -0
- package/dist/identity/account-vault.d.ts.map +1 -0
- package/dist/identity/account-vault.js +251 -0
- package/dist/identity/account-vault.js.map +1 -0
- package/dist/identity/agent-note.d.ts +19 -0
- package/dist/identity/agent-note.d.ts.map +1 -0
- package/dist/identity/agent-note.js +29 -0
- package/dist/identity/agent-note.js.map +1 -0
- package/dist/identity/crypto-p256.d.ts +7 -0
- package/dist/identity/crypto-p256.d.ts.map +1 -0
- package/dist/identity/crypto-p256.js +84 -0
- package/dist/identity/crypto-p256.js.map +1 -0
- package/dist/identity/device-key.d.ts +60 -0
- package/dist/identity/device-key.d.ts.map +1 -0
- package/dist/identity/device-key.js +103 -0
- package/dist/identity/device-key.js.map +1 -0
- package/dist/identity/did.d.ts +22 -0
- package/dist/identity/did.d.ts.map +1 -0
- package/dist/identity/did.js +37 -0
- package/dist/identity/did.js.map +1 -0
- package/dist/identity/folder-account.d.ts +65 -0
- package/dist/identity/folder-account.d.ts.map +1 -0
- package/dist/identity/folder-account.js +115 -0
- package/dist/identity/folder-account.js.map +1 -0
- package/dist/identity/identity-manager.d.ts +36 -0
- package/dist/identity/identity-manager.d.ts.map +1 -0
- package/dist/identity/identity-manager.js +115 -0
- package/dist/identity/identity-manager.js.map +1 -0
- package/dist/identity/index.d.ts +10 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +10 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/keys.d.ts +24 -0
- package/dist/identity/keys.d.ts.map +1 -0
- package/dist/identity/keys.js +38 -0
- package/dist/identity/keys.js.map +1 -0
- package/dist/identity/pairing.d.ts +83 -0
- package/dist/identity/pairing.d.ts.map +1 -0
- package/dist/identity/pairing.js +120 -0
- package/dist/identity/pairing.js.map +1 -0
- package/dist/identity/passkey-diagnostics.d.ts +54 -0
- package/dist/identity/passkey-diagnostics.d.ts.map +1 -0
- package/dist/identity/passkey-diagnostics.js +178 -0
- package/dist/identity/passkey-diagnostics.js.map +1 -0
- package/dist/identity/recovery-code.d.ts +50 -0
- package/dist/identity/recovery-code.d.ts.map +1 -0
- package/dist/identity/recovery-code.js +116 -0
- package/dist/identity/recovery-code.js.map +1 -0
- package/dist/identity/root-signer.d.ts +59 -0
- package/dist/identity/root-signer.d.ts.map +1 -0
- package/dist/identity/root-signer.js +44 -0
- package/dist/identity/root-signer.js.map +1 -0
- package/dist/identity/ucan.d.ts +164 -0
- package/dist/identity/ucan.d.ts.map +1 -0
- package/dist/identity/ucan.js +273 -0
- package/dist/identity/ucan.js.map +1 -0
- package/dist/identity/webauthn.d.ts +87 -0
- package/dist/identity/webauthn.d.ts.map +1 -0
- package/dist/identity/webauthn.js +155 -0
- package/dist/identity/webauthn.js.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/network/index.d.ts +17 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +10 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/introductions.d.ts +85 -0
- package/dist/network/introductions.d.ts.map +1 -0
- package/dist/network/introductions.js +94 -0
- package/dist/network/introductions.js.map +1 -0
- package/dist/network/local-transport.d.ts +22 -0
- package/dist/network/local-transport.d.ts.map +1 -0
- package/dist/network/local-transport.js +55 -0
- package/dist/network/local-transport.js.map +1 -0
- package/dist/network/mesh.d.ts +31 -0
- package/dist/network/mesh.d.ts.map +1 -0
- package/dist/network/mesh.js +332 -0
- package/dist/network/mesh.js.map +1 -0
- package/dist/network/multi-signaling.d.ts +29 -0
- package/dist/network/multi-signaling.d.ts.map +1 -0
- package/dist/network/multi-signaling.js +125 -0
- package/dist/network/multi-signaling.js.map +1 -0
- package/dist/network/network-manager.d.ts +37 -0
- package/dist/network/network-manager.d.ts.map +1 -0
- package/dist/network/network-manager.js +64 -0
- package/dist/network/network-manager.js.map +1 -0
- package/dist/network/peer-auth.d.ts +98 -0
- package/dist/network/peer-auth.d.ts.map +1 -0
- package/dist/network/peer-auth.js +86 -0
- package/dist/network/peer-auth.js.map +1 -0
- package/dist/network/rtc-transport.d.ts +18 -0
- package/dist/network/rtc-transport.d.ts.map +1 -0
- package/dist/network/rtc-transport.js +149 -0
- package/dist/network/rtc-transport.js.map +1 -0
- package/dist/network/signaling.d.ts +40 -0
- package/dist/network/signaling.d.ts.map +1 -0
- package/dist/network/signaling.js +124 -0
- package/dist/network/signaling.js.map +1 -0
- package/dist/network/transport.d.ts +50 -0
- package/dist/network/transport.d.ts.map +1 -0
- package/dist/network/transport.js +13 -0
- package/dist/network/transport.js.map +1 -0
- package/dist/network/ws-transport.d.ts +42 -0
- package/dist/network/ws-transport.d.ts.map +1 -0
- package/dist/network/ws-transport.js +194 -0
- package/dist/network/ws-transport.js.map +1 -0
- package/dist/node/actions.d.ts +62 -0
- package/dist/node/actions.d.ts.map +1 -0
- package/dist/node/actions.js +500 -0
- package/dist/node/actions.js.map +1 -0
- package/dist/node/carrier.d.ts +85 -0
- package/dist/node/carrier.d.ts.map +1 -0
- package/dist/node/carrier.js +192 -0
- package/dist/node/carrier.js.map +1 -0
- package/dist/node/copy.d.ts +38 -0
- package/dist/node/copy.d.ts.map +1 -0
- package/dist/node/copy.js +53 -0
- package/dist/node/copy.js.map +1 -0
- package/dist/node/index.d.ts +16 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +11 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/node.d.ts +12 -0
- package/dist/node/node.d.ts.map +1 -0
- package/dist/node/node.js +872 -0
- package/dist/node/node.js.map +1 -0
- package/dist/node/space-runtime.d.ts +144 -0
- package/dist/node/space-runtime.d.ts.map +1 -0
- package/dist/node/space-runtime.js +1221 -0
- package/dist/node/space-runtime.js.map +1 -0
- package/dist/node/stores.d.ts +45 -0
- package/dist/node/stores.d.ts.map +1 -0
- package/dist/node/stores.js +31 -0
- package/dist/node/stores.js.map +1 -0
- package/dist/node/types.d.ts +508 -0
- package/dist/node/types.d.ts.map +1 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/privacy/index.d.ts +4 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +4 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/key-distribution.d.ts +42 -0
- package/dist/privacy/key-distribution.d.ts.map +1 -0
- package/dist/privacy/key-distribution.js +50 -0
- package/dist/privacy/key-distribution.js.map +1 -0
- package/dist/privacy/privacy-guard.d.ts +24 -0
- package/dist/privacy/privacy-guard.d.ts.map +1 -0
- package/dist/privacy/privacy-guard.js +87 -0
- package/dist/privacy/privacy-guard.js.map +1 -0
- package/dist/privacy/space-encryption.d.ts +48 -0
- package/dist/privacy/space-encryption.d.ts.map +1 -0
- package/dist/privacy/space-encryption.js +61 -0
- package/dist/privacy/space-encryption.js.map +1 -0
- package/dist/query/engine.d.ts +27 -0
- package/dist/query/engine.d.ts.map +1 -0
- package/dist/query/engine.js +84 -0
- package/dist/query/engine.js.map +1 -0
- package/dist/query/filter.d.ts +15 -0
- package/dist/query/filter.d.ts.map +1 -0
- package/dist/query/filter.js +207 -0
- package/dist/query/filter.js.map +1 -0
- package/dist/query/types.d.ts +144 -0
- package/dist/query/types.d.ts.map +1 -0
- package/dist/query/types.js +22 -0
- package/dist/query/types.js.map +1 -0
- package/dist/react/context.d.ts +81 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +95 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +36 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/use-live.d.ts +16 -0
- package/dist/react/use-live.d.ts.map +1 -0
- package/dist/react/use-live.js +55 -0
- package/dist/react/use-live.js.map +1 -0
- package/dist/react/use-query.d.ts +17 -0
- package/dist/react/use-query.d.ts.map +1 -0
- package/dist/react/use-query.js +23 -0
- package/dist/react/use-query.js.map +1 -0
- package/dist/react/use-space.d.ts +29 -0
- package/dist/react/use-space.d.ts.map +1 -0
- package/dist/react/use-space.js +48 -0
- package/dist/react/use-space.js.map +1 -0
- package/dist/react/use-spaces.d.ts +19 -0
- package/dist/react/use-spaces.d.ts.map +1 -0
- package/dist/react/use-spaces.js +55 -0
- package/dist/react/use-spaces.js.map +1 -0
- package/dist/react/use-weave-auth.d.ts +10 -0
- package/dist/react/use-weave-auth.d.ts.map +1 -0
- package/dist/react/use-weave-auth.js +15 -0
- package/dist/react/use-weave-auth.js.map +1 -0
- package/dist/react/weave-auth.d.ts +17 -0
- package/dist/react/weave-auth.d.ts.map +1 -0
- package/dist/react/weave-auth.js +38 -0
- package/dist/react/weave-auth.js.map +1 -0
- package/dist/records/describe.d.ts +38 -0
- package/dist/records/describe.d.ts.map +1 -0
- package/dist/records/describe.js +101 -0
- package/dist/records/describe.js.map +1 -0
- package/dist/records/links.d.ts +14 -0
- package/dist/records/links.d.ts.map +1 -0
- package/dist/records/links.js +25 -0
- package/dist/records/links.js.map +1 -0
- package/dist/records/rules.d.ts +59 -0
- package/dist/records/rules.d.ts.map +1 -0
- package/dist/records/rules.js +118 -0
- package/dist/records/rules.js.map +1 -0
- package/dist/records/version.d.ts +54 -0
- package/dist/records/version.d.ts.map +1 -0
- package/dist/records/version.js +70 -0
- package/dist/records/version.js.map +1 -0
- package/dist/schema/collection-def.d.ts +96 -0
- package/dist/schema/collection-def.d.ts.map +1 -0
- package/dist/schema/collection-def.js +272 -0
- package/dist/schema/collection-def.js.map +1 -0
- package/dist/schema/expression.d.ts +69 -0
- package/dist/schema/expression.d.ts.map +1 -0
- package/dist/schema/expression.js +92 -0
- package/dist/schema/expression.js.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/schema-engine.d.ts +42 -0
- package/dist/schema/schema-engine.d.ts.map +1 -0
- package/dist/schema/schema-engine.js +36 -0
- package/dist/schema/schema-engine.js.map +1 -0
- package/dist/schema/signer.d.ts +27 -0
- package/dist/schema/signer.d.ts.map +1 -0
- package/dist/schema/signer.js +36 -0
- package/dist/schema/signer.js.map +1 -0
- package/dist/schemas/apps.d.ts +88 -0
- package/dist/schemas/apps.d.ts.map +1 -0
- package/dist/schemas/apps.js +168 -0
- package/dist/schemas/apps.js.map +1 -0
- package/dist/schemas/index.d.ts +410 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +208 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/screens.d.ts +67 -0
- package/dist/schemas/screens.d.ts.map +1 -0
- package/dist/schemas/screens.js +242 -0
- package/dist/schemas/screens.js.map +1 -0
- package/dist/session/agent-link.d.ts +79 -0
- package/dist/session/agent-link.d.ts.map +1 -0
- package/dist/session/agent-link.js +251 -0
- package/dist/session/agent-link.js.map +1 -0
- package/dist/session/auth.d.ts +233 -0
- package/dist/session/auth.d.ts.map +1 -0
- package/dist/session/auth.js +783 -0
- package/dist/session/auth.js.map +1 -0
- package/dist/session/connect.d.ts +211 -0
- package/dist/session/connect.d.ts.map +1 -0
- package/dist/session/connect.js +355 -0
- package/dist/session/connect.js.map +1 -0
- package/dist/session/connection.d.ts +70 -0
- package/dist/session/connection.d.ts.map +1 -0
- package/dist/session/connection.js +120 -0
- package/dist/session/connection.js.map +1 -0
- package/dist/session/credentials.d.ts +44 -0
- package/dist/session/credentials.d.ts.map +1 -0
- package/dist/session/credentials.js +60 -0
- package/dist/session/credentials.js.map +1 -0
- package/dist/session/index.d.ts +25 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +18 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/pairing.d.ts +59 -0
- package/dist/session/pairing.d.ts.map +1 -0
- package/dist/session/pairing.js +144 -0
- package/dist/session/pairing.js.map +1 -0
- package/dist/session/places.d.ts +62 -0
- package/dist/session/places.d.ts.map +1 -0
- package/dist/session/places.js +101 -0
- package/dist/session/places.js.map +1 -0
- package/dist/session/stay-signed-in.d.ts +37 -0
- package/dist/session/stay-signed-in.d.ts.map +1 -0
- package/dist/session/stay-signed-in.js +124 -0
- package/dist/session/stay-signed-in.js.map +1 -0
- package/dist/space/account-registry.d.ts +64 -0
- package/dist/space/account-registry.d.ts.map +1 -0
- package/dist/space/account-registry.js +66 -0
- package/dist/space/account-registry.js.map +1 -0
- package/dist/space/index.d.ts +3 -0
- package/dist/space/index.d.ts.map +1 -0
- package/dist/space/index.js +3 -0
- package/dist/space/index.js.map +1 -0
- package/dist/space/pass.d.ts +63 -0
- package/dist/space/pass.d.ts.map +1 -0
- package/dist/space/pass.js +54 -0
- package/dist/space/pass.js.map +1 -0
- package/dist/space/presets.d.ts +31 -0
- package/dist/space/presets.d.ts.map +1 -0
- package/dist/space/presets.js +24 -0
- package/dist/space/presets.js.map +1 -0
- package/dist/space/roles.d.ts +186 -0
- package/dist/space/roles.d.ts.map +1 -0
- package/dist/space/roles.js +500 -0
- package/dist/space/roles.js.map +1 -0
- package/dist/space/space-access.d.ts +80 -0
- package/dist/space/space-access.d.ts.map +1 -0
- package/dist/space/space-access.js +135 -0
- package/dist/space/space-access.js.map +1 -0
- package/dist/space/space-manager.d.ts +87 -0
- package/dist/space/space-manager.d.ts.map +1 -0
- package/dist/space/space-manager.js +187 -0
- package/dist/space/space-manager.js.map +1 -0
- package/dist/storage/directory-access.d.ts +78 -0
- package/dist/storage/directory-access.d.ts.map +1 -0
- package/dist/storage/directory-access.js +164 -0
- package/dist/storage/directory-access.js.map +1 -0
- package/dist/storage/encrypted-adapter.d.ts +49 -0
- package/dist/storage/encrypted-adapter.d.ts.map +1 -0
- package/dist/storage/encrypted-adapter.js +106 -0
- package/dist/storage/encrypted-adapter.js.map +1 -0
- package/dist/storage/folder-adapter.d.ts +105 -0
- package/dist/storage/folder-adapter.d.ts.map +1 -0
- package/dist/storage/folder-adapter.js +280 -0
- package/dist/storage/folder-adapter.js.map +1 -0
- package/dist/storage/folder-reconcile.d.ts +53 -0
- package/dist/storage/folder-reconcile.d.ts.map +1 -0
- package/dist/storage/folder-reconcile.js +65 -0
- package/dist/storage/folder-reconcile.js.map +1 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexeddb-adapter.d.ts +12 -0
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -0
- package/dist/storage/indexeddb-adapter.js +190 -0
- package/dist/storage/indexeddb-adapter.js.map +1 -0
- package/dist/storage/mst.d.ts +121 -0
- package/dist/storage/mst.d.ts.map +1 -0
- package/dist/storage/mst.js +402 -0
- package/dist/storage/mst.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +85 -0
- package/dist/storage/storage-provider.d.ts.map +1 -0
- package/dist/storage/storage-provider.js +220 -0
- package/dist/storage/storage-provider.js.map +1 -0
- package/dist/sync/anti-entropy.d.ts +49 -0
- package/dist/sync/anti-entropy.d.ts.map +1 -0
- package/dist/sync/anti-entropy.js +62 -0
- package/dist/sync/anti-entropy.js.map +1 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +4 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/sync-engine.d.ts +71 -0
- package/dist/sync/sync-engine.d.ts.map +1 -0
- package/dist/sync/sync-engine.js +309 -0
- package/dist/sync/sync-engine.js.map +1 -0
- package/dist/sync/sync-messages.d.ts +75 -0
- package/dist/sync/sync-messages.d.ts.map +1 -0
- package/dist/sync/sync-messages.js +12 -0
- package/dist/sync/sync-messages.js.map +1 -0
- package/dist/types.d.ts +243 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/encoding.d.ts +63 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +130 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/errors.d.ts +43 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +28 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +19 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +27 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/hash.d.ts +23 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +49 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/validation/capability-gate.d.ts +50 -0
- package/dist/validation/capability-gate.d.ts.map +1 -0
- package/dist/validation/capability-gate.js +71 -0
- package/dist/validation/capability-gate.js.map +1 -0
- package/dist/validation/crypto-gate.d.ts +16 -0
- package/dist/validation/crypto-gate.d.ts.map +1 -0
- package/dist/validation/crypto-gate.js +37 -0
- package/dist/validation/crypto-gate.js.map +1 -0
- package/dist/validation/index.d.ts +6 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +6 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/stateful-gate.d.ts +15 -0
- package/dist/validation/stateful-gate.d.ts.map +1 -0
- package/dist/validation/stateful-gate.js +50 -0
- package/dist/validation/stateful-gate.js.map +1 -0
- package/dist/validation/structural-gate.d.ts +18 -0
- package/dist/validation/structural-gate.d.ts.map +1 -0
- package/dist/validation/structural-gate.js +54 -0
- package/dist/validation/structural-gate.js.map +1 -0
- package/dist/validation/validation-engine.d.ts +28 -0
- package/dist/validation/validation-engine.d.ts.map +1 -0
- package/dist/validation/validation-engine.js +38 -0
- package/dist/validation/validation-engine.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module root-signer
|
|
3
|
+
* Who holds the identity key, and how a session gets permission from it.
|
|
4
|
+
*
|
|
5
|
+
* The root key signs exactly one thing: a note saying "this session key may
|
|
6
|
+
* write for me, until this time". Everything else is signed by the session key.
|
|
7
|
+
* That one signature is the only reason an app needs the identity at all — so
|
|
8
|
+
* it is the only thing that has to be abstracted for the key to live somewhere
|
|
9
|
+
* other than the page.
|
|
10
|
+
*
|
|
11
|
+
* Somewhere else means an account home in another window, or anything that
|
|
12
|
+
* will hold a secret and answer questions about it. The page asks for a delegation
|
|
13
|
+
* and gets back a token; the seed never crosses the boundary.
|
|
14
|
+
*
|
|
15
|
+
* Everything downstream — DIDs, expressions, validation, sync — is unchanged by
|
|
16
|
+
* this, because none of it ever sees the root key either.
|
|
17
|
+
*/
|
|
18
|
+
import { issueUCAN } from './ucan.js';
|
|
19
|
+
/**
|
|
20
|
+
* A signer for a key this page is holding.
|
|
21
|
+
*
|
|
22
|
+
* The ordinary case: the seed was unlocked here, so the key is in memory and
|
|
23
|
+
* signing is a local operation.
|
|
24
|
+
*
|
|
25
|
+
* @param identity The unlocked identity
|
|
26
|
+
* @param provider Crypto provider for signing
|
|
27
|
+
* @returns A signer over it
|
|
28
|
+
*/
|
|
29
|
+
export function createLocalRootSigner(identity, provider) {
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
did: identity.did,
|
|
32
|
+
custody: 'local',
|
|
33
|
+
async delegate(params) {
|
|
34
|
+
return issueUCAN({
|
|
35
|
+
issuer: { did: identity.did, privateKey: identity.privateKey },
|
|
36
|
+
audience: params.audience,
|
|
37
|
+
capabilities: params.capabilities,
|
|
38
|
+
expiration: params.expiration,
|
|
39
|
+
...(params.facts?.length ? { facts: params.facts } : {}),
|
|
40
|
+
}, provider);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=root-signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-signer.js","sourceRoot":"","sources":["../../src/identity/root-signer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AA4BtC;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAgD,EAChD,QAAwB;IAExB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,OAAO,EAAE,OAAgB;QAEzB,KAAK,CAAC,QAAQ,CAAC,MAKd;YACC,OAAO,SAAS,CACd;gBACE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE;gBAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACzD,EACD,QAAQ,CACT,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { CryptoProvider } from '../types.js';
|
|
2
|
+
/** UCAN header */
|
|
3
|
+
export interface UCANHeader {
|
|
4
|
+
readonly alg: string;
|
|
5
|
+
readonly typ: 'JWT';
|
|
6
|
+
readonly ucv: '0.10.0';
|
|
7
|
+
}
|
|
8
|
+
/** A capability (attenuation) */
|
|
9
|
+
export interface Capability {
|
|
10
|
+
readonly with: string;
|
|
11
|
+
readonly can: string;
|
|
12
|
+
}
|
|
13
|
+
/** Optional fact attached to UCAN */
|
|
14
|
+
export interface Fact {
|
|
15
|
+
readonly [key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** UCAN payload */
|
|
18
|
+
export interface UCANPayload {
|
|
19
|
+
readonly iss: string;
|
|
20
|
+
readonly aud: string;
|
|
21
|
+
readonly exp: number;
|
|
22
|
+
readonly nbf?: number;
|
|
23
|
+
readonly nnc?: string;
|
|
24
|
+
readonly att: ReadonlyArray<Capability>;
|
|
25
|
+
readonly prf: ReadonlyArray<string>;
|
|
26
|
+
readonly fct?: ReadonlyArray<Fact>;
|
|
27
|
+
}
|
|
28
|
+
/** A complete encoded UCAN token */
|
|
29
|
+
export interface UCANToken {
|
|
30
|
+
readonly header: UCANHeader;
|
|
31
|
+
readonly payload: UCANPayload;
|
|
32
|
+
readonly signature: string;
|
|
33
|
+
readonly encoded: string;
|
|
34
|
+
readonly cid: string;
|
|
35
|
+
}
|
|
36
|
+
/** Options for issuing a UCAN */
|
|
37
|
+
export interface IssueUCANOptions {
|
|
38
|
+
readonly issuer: {
|
|
39
|
+
readonly did: string;
|
|
40
|
+
readonly privateKey: CryptoKey;
|
|
41
|
+
};
|
|
42
|
+
readonly audience: string;
|
|
43
|
+
readonly capabilities: ReadonlyArray<Capability>;
|
|
44
|
+
readonly expiration?: number;
|
|
45
|
+
readonly notBefore?: number;
|
|
46
|
+
readonly nonce?: string;
|
|
47
|
+
readonly proofs?: ReadonlyArray<string>;
|
|
48
|
+
readonly facts?: ReadonlyArray<Fact>;
|
|
49
|
+
}
|
|
50
|
+
/** Result of UCAN validation */
|
|
51
|
+
export interface UCANValidation {
|
|
52
|
+
readonly valid: boolean;
|
|
53
|
+
readonly issuer: string;
|
|
54
|
+
readonly audience: string;
|
|
55
|
+
readonly capabilities: ReadonlyArray<Capability>;
|
|
56
|
+
readonly reason?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Options for delegating capabilities */
|
|
59
|
+
export interface DelegateOptions {
|
|
60
|
+
readonly parent: UCANToken;
|
|
61
|
+
readonly issuer: {
|
|
62
|
+
readonly did: string;
|
|
63
|
+
readonly privateKey: CryptoKey;
|
|
64
|
+
};
|
|
65
|
+
readonly audience: string;
|
|
66
|
+
readonly capabilities: ReadonlyArray<Capability>;
|
|
67
|
+
readonly expiration?: number;
|
|
68
|
+
}
|
|
69
|
+
/** How far a token's start is set back for clocks that disagree — the allowance peers give a record's date. */
|
|
70
|
+
export declare const UCAN_CLOCK_SKEW_SECONDS = 300;
|
|
71
|
+
/**
|
|
72
|
+
* Creates and signs a UCAN token.
|
|
73
|
+
*
|
|
74
|
+
* @param {IssueUCANOptions} options Options for issuing the token
|
|
75
|
+
* @param {CryptoProvider} provider Crypto provider for signing
|
|
76
|
+
* @returns {Promise<UCANToken>} The created UCAN token
|
|
77
|
+
*/
|
|
78
|
+
export declare function issueUCAN(options: IssueUCANOptions, provider: CryptoProvider): Promise<UCANToken>;
|
|
79
|
+
/**
|
|
80
|
+
* Parses an encoded UCAN string without verifying its signature.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} encoded The JWT string to parse
|
|
83
|
+
* @returns {{ header: UCANHeader, payload: UCANPayload, signature: string }} The parsed UCAN parts
|
|
84
|
+
*/
|
|
85
|
+
export declare function parseUCAN(encoded: string): {
|
|
86
|
+
readonly header: UCANHeader;
|
|
87
|
+
readonly payload: UCANPayload;
|
|
88
|
+
readonly signature: string;
|
|
89
|
+
};
|
|
90
|
+
/** When to judge a token's time bounds */
|
|
91
|
+
export interface VerifyOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Unix seconds to check `exp` and `nbf` against. Default: now.
|
|
94
|
+
*
|
|
95
|
+
* A record is judged at the moment it was signed, not the moment someone
|
|
96
|
+
* reads it. Checking against now would make every record stop verifying
|
|
97
|
+
* the hour its session's delegation ran out — and a peer arriving later
|
|
98
|
+
* would refuse all of it.
|
|
99
|
+
*/
|
|
100
|
+
readonly at?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Verifies a UCAN token's signature and time bounds.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} encoded The encoded UCAN token
|
|
106
|
+
* @param {CryptoProvider} provider Crypto provider for verifying
|
|
107
|
+
* @param {VerifyOptions} options When to judge expiry
|
|
108
|
+
* @returns {Promise<UCANValidation>} The validation result
|
|
109
|
+
*/
|
|
110
|
+
export declare function verifyUCAN(encoded: string, provider: CryptoProvider, options?: VerifyOptions): Promise<UCANValidation>;
|
|
111
|
+
/**
|
|
112
|
+
* Checks if a child capability is a valid subset of a parent capability.
|
|
113
|
+
*
|
|
114
|
+
* @param {Capability} parent The parent capability
|
|
115
|
+
* @param {Capability} child The child capability
|
|
116
|
+
* @returns {boolean} True if child is a valid subset of parent
|
|
117
|
+
*/
|
|
118
|
+
export declare function isCapabilitySubset(parent: Capability, child: Capability): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Validates a complete delegation chain of UCAN tokens.
|
|
121
|
+
*
|
|
122
|
+
* @param {string} token The leaf UCAN token to validate
|
|
123
|
+
* @param {ReadonlyArray<string>} proofTokens Array of encoded parent UCANs forming the proof chain
|
|
124
|
+
* @param {CryptoProvider} provider Crypto provider for verifying
|
|
125
|
+
* @returns {Promise<UCANValidation>} The chain validation result
|
|
126
|
+
*/
|
|
127
|
+
export declare function validateDelegationChain(token: string, proofTokens: ReadonlyArray<string>, provider: CryptoProvider, options?: VerifyOptions): Promise<UCANValidation>;
|
|
128
|
+
/**
|
|
129
|
+
* Helper to delegate capabilities from a parent UCAN token.
|
|
130
|
+
*
|
|
131
|
+
* @param {DelegateOptions} options Delegation options
|
|
132
|
+
* @param {CryptoProvider} provider Crypto provider for signing
|
|
133
|
+
* @returns {Promise<UCANToken>} The delegated UCAN token
|
|
134
|
+
*/
|
|
135
|
+
export declare function delegateCapabilities(options: DelegateOptions, provider: CryptoProvider): Promise<UCANToken>;
|
|
136
|
+
/** Resolves a proof token by its CID, returning null when it cannot be found. */
|
|
137
|
+
export type ProofResolver = (cid: string) => Promise<string | null> | string | null;
|
|
138
|
+
/** The outcome of walking a delegation chain back to its root */
|
|
139
|
+
export interface ChainResolution {
|
|
140
|
+
readonly valid: boolean;
|
|
141
|
+
/** The DID at the root of the chain — the identity ultimately being acted for */
|
|
142
|
+
readonly rootDid: string | null;
|
|
143
|
+
/** Capabilities the leaf token holds, once the chain is known to be sound */
|
|
144
|
+
readonly capabilities: ReadonlyArray<Capability>;
|
|
145
|
+
/** Audience of the leaf: the key allowed to use these capabilities */
|
|
146
|
+
readonly audience: string | null;
|
|
147
|
+
readonly reason?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Walks a delegation chain from a leaf token back to its root, verifying every
|
|
151
|
+
* link: each token's signature, each parent's audience matching its child's
|
|
152
|
+
* issuer, and attenuation at every step.
|
|
153
|
+
*
|
|
154
|
+
* Each token is followed through the first entry of its `prf` array, so this
|
|
155
|
+
* resolves single-parent chains — the shape delegation takes in practice.
|
|
156
|
+
*
|
|
157
|
+
* @param encoded The leaf UCAN
|
|
158
|
+
* @param resolveProof Looks up a parent token by CID (from local storage, a peer, …)
|
|
159
|
+
* @param provider Crypto provider for signature verification
|
|
160
|
+
* @param options When to judge expiry — for a record, when it was signed
|
|
161
|
+
* @returns What the chain grants, and the root DID behind it
|
|
162
|
+
*/
|
|
163
|
+
export declare function resolveDelegationRoot(encoded: string, resolveProof: ProofResolver, provider: CryptoProvider, options?: VerifyOptions): Promise<ChainResolution>;
|
|
164
|
+
//# sourceMappingURL=ucan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ucan.d.ts","sourceRoot":"","sources":["../../src/identity/ucan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMlD,kBAAkB;AAClB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;CACxB;AAED,iCAAiC;AACjC,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,qCAAqC;AACrC,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,mBAAmB;AACnB,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,oCAAoC;AACpC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,M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EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CA0BjH;AAED,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;AAEpF,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACjD,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,aAAa,EAC3B,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,eAAe,CAAC,CAsC1B"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { base64UrlEncode, base64UrlDecode, utf8Encode, utf8Decode } from '../utils/encoding.js';
|
|
2
|
+
import { cidFromBytes } from '../utils/hash.js';
|
|
3
|
+
import { canonicalize } from '../schema/expression.js';
|
|
4
|
+
import { didToPublicKey } from './did.js';
|
|
5
|
+
/** How far a token's start is set back for clocks that disagree — the allowance peers give a record's date. */
|
|
6
|
+
export const UCAN_CLOCK_SKEW_SECONDS = 300;
|
|
7
|
+
/**
|
|
8
|
+
* Creates and signs a UCAN token.
|
|
9
|
+
*
|
|
10
|
+
* @param {IssueUCANOptions} options Options for issuing the token
|
|
11
|
+
* @param {CryptoProvider} provider Crypto provider for signing
|
|
12
|
+
* @returns {Promise<UCANToken>} The created UCAN token
|
|
13
|
+
*/
|
|
14
|
+
export async function issueUCAN(options, provider) {
|
|
15
|
+
const header = { alg: 'ES256', typ: 'JWT', ucv: '0.10.0' };
|
|
16
|
+
const now = Math.floor(Date.now() / 1000);
|
|
17
|
+
const exp = options.expiration ?? (now + 3600);
|
|
18
|
+
// Records are judged at the time they claim to have been signed, so a token
|
|
19
|
+
// with no start would let a leaked key write "last year" for as long as the
|
|
20
|
+
// token lives. Set back by the clock skew peers already allow for.
|
|
21
|
+
const nbf = options.notBefore ?? now - UCAN_CLOCK_SKEW_SECONDS;
|
|
22
|
+
let nnc = options.nonce;
|
|
23
|
+
if (!nnc) {
|
|
24
|
+
const bytes = new Uint8Array(8);
|
|
25
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
26
|
+
nnc = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
27
|
+
}
|
|
28
|
+
const payload = {
|
|
29
|
+
iss: options.issuer.did,
|
|
30
|
+
aud: options.audience,
|
|
31
|
+
exp,
|
|
32
|
+
nbf,
|
|
33
|
+
nnc,
|
|
34
|
+
att: options.capabilities,
|
|
35
|
+
prf: options.proofs ?? [],
|
|
36
|
+
fct: options.facts
|
|
37
|
+
};
|
|
38
|
+
// Clean up undefined properties for deterministic encoding
|
|
39
|
+
const cleanPayload = JSON.parse(JSON.stringify(payload));
|
|
40
|
+
const encodedHeader = base64UrlEncode(utf8Encode(canonicalize(header)));
|
|
41
|
+
const encodedPayload = base64UrlEncode(utf8Encode(canonicalize(cleanPayload)));
|
|
42
|
+
const dataToSign = `${encodedHeader}.${encodedPayload}`;
|
|
43
|
+
const signatureBytes = await provider.sign(options.issuer.privateKey, utf8Encode(dataToSign));
|
|
44
|
+
const signature = base64UrlEncode(signatureBytes);
|
|
45
|
+
const encoded = `${dataToSign}.${signature}`;
|
|
46
|
+
const cid = await cidFromBytes(utf8Encode(encoded));
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
header: Object.freeze(header),
|
|
49
|
+
payload: Object.freeze(cleanPayload),
|
|
50
|
+
signature,
|
|
51
|
+
encoded,
|
|
52
|
+
cid
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parses an encoded UCAN string without verifying its signature.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} encoded The JWT string to parse
|
|
59
|
+
* @returns {{ header: UCANHeader, payload: UCANPayload, signature: string }} The parsed UCAN parts
|
|
60
|
+
*/
|
|
61
|
+
export function parseUCAN(encoded) {
|
|
62
|
+
const parts = encoded.split('.');
|
|
63
|
+
if (parts.length !== 3) {
|
|
64
|
+
throw new Error('Invalid UCAN token format');
|
|
65
|
+
}
|
|
66
|
+
const headerStr = utf8Decode(base64UrlDecode(parts[0]));
|
|
67
|
+
const payloadStr = utf8Decode(base64UrlDecode(parts[1]));
|
|
68
|
+
const header = JSON.parse(headerStr);
|
|
69
|
+
const payload = JSON.parse(payloadStr);
|
|
70
|
+
return {
|
|
71
|
+
header,
|
|
72
|
+
payload,
|
|
73
|
+
signature: parts[2]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Verifies a UCAN token's signature and time bounds.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} encoded The encoded UCAN token
|
|
80
|
+
* @param {CryptoProvider} provider Crypto provider for verifying
|
|
81
|
+
* @param {VerifyOptions} options When to judge expiry
|
|
82
|
+
* @returns {Promise<UCANValidation>} The validation result
|
|
83
|
+
*/
|
|
84
|
+
export async function verifyUCAN(encoded, provider, options = {}) {
|
|
85
|
+
try {
|
|
86
|
+
const parts = encoded.split('.');
|
|
87
|
+
if (parts.length !== 3) {
|
|
88
|
+
return { valid: false, issuer: '', audience: '', capabilities: [], reason: 'Invalid UCAN token format' };
|
|
89
|
+
}
|
|
90
|
+
const { header: _header, payload, signature } = parseUCAN(encoded);
|
|
91
|
+
const now = options.at ?? Math.floor(Date.now() / 1000);
|
|
92
|
+
// Both bounds are required: a token without `exp` would never expire
|
|
93
|
+
// (`undefined <= now` is false), and one without `nbf` could vouch for
|
|
94
|
+
// records dated any time before it was issued.
|
|
95
|
+
if (typeof payload.exp !== 'number' || !Number.isFinite(payload.exp) || typeof payload.nbf !== 'number' || !Number.isFinite(payload.nbf)) {
|
|
96
|
+
return { valid: false, issuer: payload.iss, audience: payload.aud, capabilities: payload.att, reason: 'Token must say when it starts and ends' };
|
|
97
|
+
}
|
|
98
|
+
if (payload.exp <= now) {
|
|
99
|
+
return { valid: false, issuer: payload.iss, audience: payload.aud, capabilities: payload.att, reason: 'Token has expired' };
|
|
100
|
+
}
|
|
101
|
+
if (payload.nbf > now) {
|
|
102
|
+
return { valid: false, issuer: payload.iss, audience: payload.aud, capabilities: payload.att, reason: 'Token not yet valid' };
|
|
103
|
+
}
|
|
104
|
+
const { publicKeyBytes } = didToPublicKey(payload.iss);
|
|
105
|
+
const publicKey = await provider.importPublicKey(publicKeyBytes);
|
|
106
|
+
const dataToVerify = `${parts[0]}.${parts[1]}`;
|
|
107
|
+
const signatureBytes = base64UrlDecode(signature);
|
|
108
|
+
const isValid = await provider.verify(publicKey, signatureBytes, utf8Encode(dataToVerify));
|
|
109
|
+
if (!isValid) {
|
|
110
|
+
return { valid: false, issuer: payload.iss, audience: payload.aud, capabilities: payload.att, reason: 'Invalid signature' };
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
valid: true,
|
|
114
|
+
issuer: payload.iss,
|
|
115
|
+
audience: payload.aud,
|
|
116
|
+
capabilities: payload.att
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const reason = error instanceof Error ? error.message : 'Unknown verification error';
|
|
121
|
+
return { valid: false, issuer: '', audience: '', capabilities: [], reason };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Checks if a child capability is a valid subset of a parent capability.
|
|
126
|
+
*
|
|
127
|
+
* @param {Capability} parent The parent capability
|
|
128
|
+
* @param {Capability} child The child capability
|
|
129
|
+
* @returns {boolean} True if child is a valid subset of parent
|
|
130
|
+
*/
|
|
131
|
+
export function isCapabilitySubset(parent, child) {
|
|
132
|
+
const withMatch = parent.with === '*' || parent.with === child.with;
|
|
133
|
+
if (!withMatch) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (parent.can === '*' || parent.can === child.can) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (parent.can.endsWith('/*')) {
|
|
140
|
+
const prefix = parent.can.slice(0, -1);
|
|
141
|
+
return child.can.startsWith(prefix);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Validates a complete delegation chain of UCAN tokens.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} token The leaf UCAN token to validate
|
|
149
|
+
* @param {ReadonlyArray<string>} proofTokens Array of encoded parent UCANs forming the proof chain
|
|
150
|
+
* @param {CryptoProvider} provider Crypto provider for verifying
|
|
151
|
+
* @returns {Promise<UCANValidation>} The chain validation result
|
|
152
|
+
*/
|
|
153
|
+
export async function validateDelegationChain(token, proofTokens, provider, options = {}) {
|
|
154
|
+
const leafValidation = await verifyUCAN(token, provider, options);
|
|
155
|
+
if (!leafValidation.valid) {
|
|
156
|
+
return leafValidation;
|
|
157
|
+
}
|
|
158
|
+
const parsedLeaf = parseUCAN(token);
|
|
159
|
+
// Base case: No proofs required if the token has no parent references
|
|
160
|
+
if (parsedLeaf.payload.prf.length === 0) {
|
|
161
|
+
return leafValidation;
|
|
162
|
+
}
|
|
163
|
+
// Parse all proof tokens
|
|
164
|
+
const proofs = await Promise.all(proofTokens.map(async (encoded) => {
|
|
165
|
+
const validation = await verifyUCAN(encoded, provider, options);
|
|
166
|
+
const parsed = parseUCAN(encoded);
|
|
167
|
+
const cid = await cidFromBytes(utf8Encode(encoded));
|
|
168
|
+
return { validation, parsed, encoded, cid };
|
|
169
|
+
}));
|
|
170
|
+
// Ensure all required proofs by CID are provided and valid
|
|
171
|
+
for (const requiredCid of parsedLeaf.payload.prf) {
|
|
172
|
+
const proof = proofs.find(p => p.cid === requiredCid);
|
|
173
|
+
if (!proof) {
|
|
174
|
+
return { ...leafValidation, valid: false, reason: `Missing proof token with CID: ${requiredCid}` };
|
|
175
|
+
}
|
|
176
|
+
if (!proof.validation.valid) {
|
|
177
|
+
return { ...leafValidation, valid: false, reason: `Invalid proof token in chain: ${proof.validation.reason}` };
|
|
178
|
+
}
|
|
179
|
+
// Check delegation linkage (parent audience must equal child issuer)
|
|
180
|
+
if (proof.parsed.payload.aud !== parsedLeaf.payload.iss) {
|
|
181
|
+
return { ...leafValidation, valid: false, reason: 'Delegation chain broken: audience/issuer mismatch' };
|
|
182
|
+
}
|
|
183
|
+
// Check capabilities attenuation
|
|
184
|
+
for (const childCap of parsedLeaf.payload.att) {
|
|
185
|
+
const isSubset = proof.parsed.payload.att.some(parentCap => isCapabilitySubset(parentCap, childCap));
|
|
186
|
+
if (!isSubset) {
|
|
187
|
+
return { ...leafValidation, valid: false, reason: 'Delegated capability is not a subset of parent capability' };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// All checks passed
|
|
192
|
+
return leafValidation;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Helper to delegate capabilities from a parent UCAN token.
|
|
196
|
+
*
|
|
197
|
+
* @param {DelegateOptions} options Delegation options
|
|
198
|
+
* @param {CryptoProvider} provider Crypto provider for signing
|
|
199
|
+
* @returns {Promise<UCANToken>} The delegated UCAN token
|
|
200
|
+
*/
|
|
201
|
+
export async function delegateCapabilities(options, provider) {
|
|
202
|
+
// The delegator must be the audience of the parent token
|
|
203
|
+
if (options.parent.payload.aud !== options.issuer.did) {
|
|
204
|
+
throw new Error('Delegation chain broken: issuer must be the audience of the parent UCAN');
|
|
205
|
+
}
|
|
206
|
+
// Validate capabilities attenuation
|
|
207
|
+
for (const childCap of options.capabilities) {
|
|
208
|
+
const isSubset = options.parent.payload.att.some(parentCap => isCapabilitySubset(parentCap, childCap));
|
|
209
|
+
if (!isSubset) {
|
|
210
|
+
throw new Error(`Capability ${JSON.stringify(childCap)} is not a subset of parent capabilities`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Validate expiration
|
|
214
|
+
if (options.expiration !== undefined && options.expiration > options.parent.payload.exp) {
|
|
215
|
+
throw new Error('Delegated expiration cannot exceed parent expiration');
|
|
216
|
+
}
|
|
217
|
+
return await issueUCAN({
|
|
218
|
+
issuer: options.issuer,
|
|
219
|
+
audience: options.audience,
|
|
220
|
+
capabilities: options.capabilities,
|
|
221
|
+
expiration: options.expiration ?? options.parent.payload.exp,
|
|
222
|
+
proofs: [options.parent.cid]
|
|
223
|
+
}, provider);
|
|
224
|
+
}
|
|
225
|
+
/** Guards against a cyclic or absurdly deep proof chain. */
|
|
226
|
+
const MAX_CHAIN_DEPTH = 10;
|
|
227
|
+
/**
|
|
228
|
+
* Walks a delegation chain from a leaf token back to its root, verifying every
|
|
229
|
+
* link: each token's signature, each parent's audience matching its child's
|
|
230
|
+
* issuer, and attenuation at every step.
|
|
231
|
+
*
|
|
232
|
+
* Each token is followed through the first entry of its `prf` array, so this
|
|
233
|
+
* resolves single-parent chains — the shape delegation takes in practice.
|
|
234
|
+
*
|
|
235
|
+
* @param encoded The leaf UCAN
|
|
236
|
+
* @param resolveProof Looks up a parent token by CID (from local storage, a peer, …)
|
|
237
|
+
* @param provider Crypto provider for signature verification
|
|
238
|
+
* @param options When to judge expiry — for a record, when it was signed
|
|
239
|
+
* @returns What the chain grants, and the root DID behind it
|
|
240
|
+
*/
|
|
241
|
+
export async function resolveDelegationRoot(encoded, resolveProof, provider, options = {}) {
|
|
242
|
+
const leafValidation = await verifyUCAN(encoded, provider, options);
|
|
243
|
+
if (!leafValidation.valid) {
|
|
244
|
+
return { valid: false, rootDid: null, capabilities: [], audience: null, reason: leafValidation.reason ?? 'Invalid token' };
|
|
245
|
+
}
|
|
246
|
+
const leaf = parseUCAN(encoded);
|
|
247
|
+
let current = { encoded, payload: leaf.payload };
|
|
248
|
+
for (let depth = 0; depth < MAX_CHAIN_DEPTH; depth++) {
|
|
249
|
+
const parentCid = current.payload.prf[0];
|
|
250
|
+
// No proof left to follow: this issuer is the root of the chain.
|
|
251
|
+
if (parentCid === undefined) {
|
|
252
|
+
return {
|
|
253
|
+
valid: true,
|
|
254
|
+
rootDid: current.payload.iss,
|
|
255
|
+
capabilities: leaf.payload.att,
|
|
256
|
+
audience: leaf.payload.aud
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const parentEncoded = await resolveProof(parentCid);
|
|
260
|
+
if (!parentEncoded) {
|
|
261
|
+
return { valid: false, rootDid: null, capabilities: [], audience: null, reason: `Missing proof token with CID: ${parentCid}` };
|
|
262
|
+
}
|
|
263
|
+
// validateDelegationChain checks this single link: parent signature,
|
|
264
|
+
// audience → issuer linkage, and capability attenuation.
|
|
265
|
+
const link = await validateDelegationChain(current.encoded, [parentEncoded], provider, options);
|
|
266
|
+
if (!link.valid) {
|
|
267
|
+
return { valid: false, rootDid: null, capabilities: [], audience: null, reason: link.reason ?? 'Broken delegation chain' };
|
|
268
|
+
}
|
|
269
|
+
current = { encoded: parentEncoded, payload: parseUCAN(parentEncoded).payload };
|
|
270
|
+
}
|
|
271
|
+
return { valid: false, rootDid: null, capabilities: [], audience: null, reason: `Delegation chain deeper than ${MAX_CHAIN_DEPTH} links` };
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=ucan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ucan.js","sourceRoot":"","sources":["../../src/identity/ucan.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD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E,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,yBAAyB,EAAE,CAAC;QAC7H,CAAC;QAED,OAAO,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC;IAClF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,gCAAgC,eAAe,QAAQ,EAAE,CAAC;AAC5I,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface PasskeyOptions {
|
|
2
|
+
readonly rpId: string;
|
|
3
|
+
readonly rpName: string;
|
|
4
|
+
readonly userName: string;
|
|
5
|
+
readonly userId?: Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* WebAuthn L3 hints steering which authenticator the browser offers first.
|
|
8
|
+
* `client-device` favours the platform passkey (Touch ID, Windows Hello) —
|
|
9
|
+
* useful when an installed credential manager handles passkeys by default but
|
|
10
|
+
* does not support PRF.
|
|
11
|
+
*/
|
|
12
|
+
readonly hints?: ReadonlyArray<'client-device' | 'security-key' | 'hybrid'>;
|
|
13
|
+
/** Restrict to platform or roaming authenticators */
|
|
14
|
+
readonly attachment?: AuthenticatorAttachment;
|
|
15
|
+
}
|
|
16
|
+
export interface PasskeyRegistration {
|
|
17
|
+
readonly credentialId: string;
|
|
18
|
+
/**
|
|
19
|
+
* The user handle the passkey was made for, base64url. Keep it: it is the
|
|
20
|
+
* only way to ask the provider to relabel the passkey later
|
|
21
|
+
* ({@link renamePasskey}).
|
|
22
|
+
*/
|
|
23
|
+
readonly userHandle: string;
|
|
24
|
+
readonly publicKey: Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* What the client reported about PRF at creation time: true, false, or
|
|
27
|
+
* undefined when it said nothing at all.
|
|
28
|
+
*
|
|
29
|
+
* This is a weak signal. Several credential providers — Bitwarden among them —
|
|
30
|
+
* omit or deny it here and still evaluate PRF perfectly well during an
|
|
31
|
+
* assertion, so it must never be treated as a final answer. The only reliable
|
|
32
|
+
* test is asking for the secret and seeing whether one comes back.
|
|
33
|
+
*/
|
|
34
|
+
readonly prfDeclared: boolean | undefined;
|
|
35
|
+
/** PRF output, when the authenticator already evaluates it during creation */
|
|
36
|
+
readonly prfOutput: Uint8Array | null;
|
|
37
|
+
}
|
|
38
|
+
export interface AuthOptions {
|
|
39
|
+
readonly rpId?: string;
|
|
40
|
+
/** See {@link PasskeyOptions.hints} */
|
|
41
|
+
readonly hints?: ReadonlyArray<'client-device' | 'security-key' | 'hybrid'>;
|
|
42
|
+
}
|
|
43
|
+
export interface PasskeyAuth {
|
|
44
|
+
readonly credentialId: string;
|
|
45
|
+
readonly prfOutput: Uint8Array | null;
|
|
46
|
+
readonly authenticatorData: Uint8Array;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether this device has a built-in authenticator — Touch ID, Windows Hello.
|
|
50
|
+
*
|
|
51
|
+
* Worth knowing before asking for one: `attachment: 'platform'` is a filter
|
|
52
|
+
* rather than a preference, so requesting it on a machine that has none fails
|
|
53
|
+
* outright instead of falling back.
|
|
54
|
+
*
|
|
55
|
+
* @returns Whether a platform authenticator can be used here
|
|
56
|
+
*/
|
|
57
|
+
export declare function hasPlatformAuthenticator(): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Registers a new passkey with PRF extension.
|
|
60
|
+
* @param {PasskeyOptions} options Registration options.
|
|
61
|
+
* @returns {Promise<PasskeyRegistration>} Registration result.
|
|
62
|
+
*/
|
|
63
|
+
export declare function registerPasskey(options: PasskeyOptions): Promise<PasskeyRegistration>;
|
|
64
|
+
/**
|
|
65
|
+
* Asks the passkey provider to show a passkey under a new name.
|
|
66
|
+
*
|
|
67
|
+
* A site cannot edit a password manager, so after an account is renamed its
|
|
68
|
+
* passkey would keep the old label and look like a different account. The
|
|
69
|
+
* WebAuthn Signal API lets a site *ask*; the provider decides. Where the
|
|
70
|
+
* browser does not have it, this does nothing.
|
|
71
|
+
*
|
|
72
|
+
* @returns Whether the browser accepted the request — not whether the provider acted on it
|
|
73
|
+
*/
|
|
74
|
+
export declare function renamePasskey(params: {
|
|
75
|
+
rpId: string;
|
|
76
|
+
userHandle: string;
|
|
77
|
+
name: string;
|
|
78
|
+
}): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Authenticates using an existing passkey with PRF extension.
|
|
81
|
+
* @param {string} [credentialId] The credential to use. Omit to let the user pick
|
|
82
|
+
* any discoverable passkey for this origin.
|
|
83
|
+
* @param {AuthOptions} [options] Authentication options.
|
|
84
|
+
* @returns {Promise<PasskeyAuth>} Authentication result.
|
|
85
|
+
*/
|
|
86
|
+
export declare function authenticatePasskey(credentialId?: string, options?: AuthOptions): Promise<PasskeyAuth>;
|
|
87
|
+
//# sourceMappingURL=webauthn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.d.ts","sourceRoot":"","sources":["../../src/identity/webauthn.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,eAAe,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC;IAC5E,qDAAqD;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,uBAAuB,CAAC;CAC/C;AAED,MAAM,WAAW,mBAAmB;IAClC,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