@ternent/core 0.0.1
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/.changeset/README.md +8 -0
- package/.changeset/config.json +17 -0
- package/.github/workflows/deploy-armour.yml +42 -0
- package/.github/workflows/deploy-identity.yml +42 -0
- package/.github/workflows/deploy-seal.yml +42 -0
- package/.github/workflows/deploy-ui.yml +42 -0
- package/.github/workflows/deploy-utils.yml +42 -0
- package/.github/workflows/release-create.yml +59 -0
- package/.github/workflows/release-publish.yml +54 -0
- package/.nvmrc +1 -0
- package/.ops/publish.mjs +31 -0
- package/package.json +16 -0
- package/packages/README.md +0 -0
- package/packages/armour/CHANGELOG.md +66 -0
- package/packages/armour/CLAUDE.md +8 -0
- package/packages/armour/README.md +103 -0
- package/packages/armour/SPEC.md +92 -0
- package/packages/armour/package.json +45 -0
- package/packages/armour/src/constants.ts +5 -0
- package/packages/armour/src/deps.d.ts +56 -0
- package/packages/armour/src/errors.ts +172 -0
- package/packages/armour/src/files.ts +73 -0
- package/packages/armour/src/identity.ts +72 -0
- package/packages/armour/src/index.ts +56 -0
- package/packages/armour/src/init.ts +10 -0
- package/packages/armour/src/passphrase.ts +33 -0
- package/packages/armour/src/recipients.ts +73 -0
- package/packages/armour/src/text.ts +68 -0
- package/packages/armour/src/types.ts +93 -0
- package/packages/armour/test/armour.test.ts +270 -0
- package/packages/armour/tsconfig.build.json +12 -0
- package/packages/armour/tsconfig.json +12 -0
- package/packages/armour/vite.config.ts +29 -0
- package/packages/concord/CHANGELOG.md +83 -0
- package/packages/concord/CLAUDE.md +9 -0
- package/packages/concord/README.md +146 -0
- package/packages/concord/SPEC.md +287 -0
- package/packages/concord/package.json +51 -0
- package/packages/concord/src/app.ts +717 -0
- package/packages/concord/src/errors.ts +9 -0
- package/packages/concord/src/index.ts +20 -0
- package/packages/concord/src/types.ts +127 -0
- package/packages/concord/test/concord.test.ts +978 -0
- package/packages/concord/tsconfig.json +12 -0
- package/packages/concord/vite.browser.config.ts +27 -0
- package/packages/concord/vite.config.ts +35 -0
- package/packages/concord/vite.config.ts.timestamp-1774262297922-ffd76e35ea668.mjs +83 -0
- package/packages/identity/CHANGELOG.md +47 -0
- package/packages/identity/README.md +236 -0
- package/packages/identity/package.json +41 -0
- package/packages/identity/src/index.ts +538 -0
- package/packages/identity/test/identity.test.ts +172 -0
- package/packages/identity/tsconfig.build.json +12 -0
- package/packages/identity/vite.config.ts +17 -0
- package/packages/ledger/CHANGELOG.md +69 -0
- package/packages/ledger/CLAUDE.md +9 -0
- package/packages/ledger/SPEC.md +304 -0
- package/packages/ledger/package.json +48 -0
- package/packages/ledger/src/index.ts +2 -0
- package/packages/ledger/src/ledger.ts +1286 -0
- package/packages/ledger/src/seal-cli.d.ts +25 -0
- package/packages/ledger/src/types.ts +294 -0
- package/packages/ledger/test/ledger.test.ts +838 -0
- package/packages/ledger/tsconfig.json +12 -0
- package/packages/ledger/vite.browser.config.ts +27 -0
- package/packages/ledger/vite.config.ts +39 -0
- package/packages/seal/CHANGELOG.md +137 -0
- package/packages/seal/CLAUDE.md +8 -0
- package/packages/seal/README.md +258 -0
- package/packages/seal/bin/seal +6 -0
- package/packages/seal/package.json +59 -0
- package/packages/seal/src/artifact.ts +380 -0
- package/packages/seal/src/cli.ts +372 -0
- package/packages/seal/src/commands/identity.ts +52 -0
- package/packages/seal/src/commands/manifest.ts +71 -0
- package/packages/seal/src/commands/publicKey.ts +7 -0
- package/packages/seal/src/commands/sign.ts +56 -0
- package/packages/seal/src/commands/verify.ts +54 -0
- package/packages/seal/src/crypto.ts +85 -0
- package/packages/seal/src/errors.ts +88 -0
- package/packages/seal/src/index.ts +5 -0
- package/packages/seal/src/manifest.ts +114 -0
- package/packages/seal/src/node.ts +18 -0
- package/packages/seal/src/proof.ts +344 -0
- package/packages/seal/test/artifact.test.ts +86 -0
- package/packages/seal/test/cli.test.ts +208 -0
- package/packages/seal/test/crypto.test.ts +21 -0
- package/packages/seal/test/manifest.test.ts +32 -0
- package/packages/seal/test/proof.test.ts +60 -0
- package/packages/seal/tsconfig.json +12 -0
- package/packages/seal/vite.config.ts +54 -0
- package/packages/ui/CHANGELOG.md +393 -0
- package/packages/ui/README.md +57 -0
- package/packages/ui/jsconfig.json +19 -0
- package/packages/ui/package.json +64 -0
- package/packages/ui/scripts/check-tokens.js +56 -0
- package/packages/ui/scripts/generate-theme-css.mjs +85 -0
- package/packages/ui/src/design-system/base.css +8 -0
- package/packages/ui/src/design-system/docs/ACCESSIBILITY_RULES.md +186 -0
- package/packages/ui/src/design-system/docs/AI_SYSTEM.md +281 -0
- package/packages/ui/src/design-system/docs/PATTERN_RULES.md +83 -0
- package/packages/ui/src/design-system/docs/PRIMITIVE_RULES.md +258 -0
- package/packages/ui/src/design-system/docs/TOKEN_RULES.md +235 -0
- package/packages/ui/src/design-system/docs/VISUAL_DIRECTION.md +68 -0
- package/packages/ui/src/design-system/foundation.js +420 -0
- package/packages/ui/src/design-system/tokens.css +140 -0
- package/packages/ui/src/design-system/tokens.js +327 -0
- package/packages/ui/src/design-system/utils.js +246 -0
- package/packages/ui/src/main.js +4 -0
- package/packages/ui/src/patterns/FeatureCard/FeatureCard.spec.md +24 -0
- package/packages/ui/src/patterns/FeatureCard/FeatureCard.types.ts +8 -0
- package/packages/ui/src/patterns/FeatureCard/FeatureCard.vue +175 -0
- package/packages/ui/src/patterns/FormField/FormField.spec.md +65 -0
- package/packages/ui/src/patterns/FormField/FormField.types.ts +11 -0
- package/packages/ui/src/patterns/FormField/FormField.vue +87 -0
- package/packages/ui/src/patterns/IdentityGlyph/IdentityGlyph.vue +61 -0
- package/packages/ui/src/patterns/IdentityGlyph/IdentityHandle.vue +58 -0
- package/packages/ui/src/patterns/IdentityGlyph/identityGlyph.types.ts +36 -0
- package/packages/ui/src/patterns/IdentityGlyph/identityGlyph.utils.ts +585 -0
- package/packages/ui/src/patterns/IdentityGlyph/index.ts +5 -0
- package/packages/ui/src/patterns/KeyValueList/KeyValueList.spec.md +28 -0
- package/packages/ui/src/patterns/KeyValueList/KeyValueList.types.ts +16 -0
- package/packages/ui/src/patterns/KeyValueList/KeyValueList.vue +50 -0
- package/packages/ui/src/patterns/LandingPage/LandingIcon.vue +90 -0
- package/packages/ui/src/patterns/LandingPage/LandingPage.spec.md +24 -0
- package/packages/ui/src/patterns/LandingPage/LandingPage.types.ts +212 -0
- package/packages/ui/src/patterns/LandingPage/LandingPage.vue +599 -0
- package/packages/ui/src/patterns/ListWorkspaceLayout/ListWorkspaceLayout.test.ts +33 -0
- package/packages/ui/src/patterns/ListWorkspaceLayout/ListWorkspaceLayout.vue +44 -0
- package/packages/ui/src/patterns/Logo/Logo.spec.md +22 -0
- package/packages/ui/src/patterns/Logo/Logo.vue +160 -0
- package/packages/ui/src/patterns/PageSurface/PageSurface.spec.md +15 -0
- package/packages/ui/src/patterns/PageSurface/PageSurface.vue +85 -0
- package/packages/ui/src/patterns/PanelChrome/PanelChrome.spec.md +39 -0
- package/packages/ui/src/patterns/PanelChrome/PanelChrome.types.ts +1 -0
- package/packages/ui/src/patterns/PanelChrome/PanelChrome.vue +187 -0
- package/packages/ui/src/patterns/PreviewPanel/PreviewPanel.spec.md +31 -0
- package/packages/ui/src/patterns/PreviewPanel/PreviewPanel.types.ts +23 -0
- package/packages/ui/src/patterns/PreviewPanel/PreviewPanel.vue +354 -0
- package/packages/ui/src/patterns/RecordList/RecordList.spec.md +35 -0
- package/packages/ui/src/patterns/RecordList/RecordList.test.ts +42 -0
- package/packages/ui/src/patterns/RecordList/RecordList.types.ts +9 -0
- package/packages/ui/src/patterns/RecordList/RecordList.utils.ts +5 -0
- package/packages/ui/src/patterns/RecordList/RecordList.vue +134 -0
- package/packages/ui/src/patterns/SectionClarifier/SectionClarifier.vue +85 -0
- package/packages/ui/src/patterns/SectionIntro/SectionIntro.spec.md +25 -0
- package/packages/ui/src/patterns/SectionIntro/SectionIntro.types.ts +7 -0
- package/packages/ui/src/patterns/SectionIntro/SectionIntro.vue +141 -0
- package/packages/ui/src/patterns/SidebarNav/SidebarNav.spec.md +34 -0
- package/packages/ui/src/patterns/SidebarNav/SidebarNav.types.ts +17 -0
- package/packages/ui/src/patterns/SidebarNav/SidebarNav.vue +110 -0
- package/packages/ui/src/patterns/SplitView/SplitView.spec.md +28 -0
- package/packages/ui/src/patterns/SplitView/SplitView.test.ts +22 -0
- package/packages/ui/src/patterns/SplitView/SplitView.types.ts +3 -0
- package/packages/ui/src/patterns/SplitView/SplitView.utils.ts +13 -0
- package/packages/ui/src/patterns/SplitView/SplitView.vue +39 -0
- package/packages/ui/src/patterns/StepList/StepList.spec.md +15 -0
- package/packages/ui/src/patterns/StepList/StepList.types.ts +4 -0
- package/packages/ui/src/patterns/StepList/StepList.vue +91 -0
- package/packages/ui/src/patterns/Verification/VerificationBadge.vue +97 -0
- package/packages/ui/src/patterns/Verification/VerificationComponents.test.ts +153 -0
- package/packages/ui/src/patterns/Verification/VerificationDetailsPanel.vue +270 -0
- package/packages/ui/src/patterns/Verification/VerificationSummary.vue +171 -0
- package/packages/ui/src/patterns/Verification/index.ts +6 -0
- package/packages/ui/src/patterns/Verification/verification.types.ts +8 -0
- package/packages/ui/src/patterns/Verification/verification.utils.test.ts +37 -0
- package/packages/ui/src/patterns/Verification/verification.utils.ts +75 -0
- package/packages/ui/src/patterns/index.ts +25 -0
- package/packages/ui/src/primitives/Accordian/Accordian.vue +11 -0
- package/packages/ui/src/primitives/Accordian/AccordianItem.vue +14 -0
- package/packages/ui/src/primitives/Accordion/Accordion.props.ts +21 -0
- package/packages/ui/src/primitives/Accordion/Accordion.spec.md +50 -0
- package/packages/ui/src/primitives/Accordion/Accordion.types.ts +4 -0
- package/packages/ui/src/primitives/Accordion/Accordion.variants.ts +12 -0
- package/packages/ui/src/primitives/Accordion/Accordion.vue +71 -0
- package/packages/ui/src/primitives/Accordion/AccordionItem.props.ts +14 -0
- package/packages/ui/src/primitives/Accordion/AccordionItem.vue +40 -0
- package/packages/ui/src/primitives/Badge/Badge.props.ts +17 -0
- package/packages/ui/src/primitives/Badge/Badge.spec.md +17 -0
- package/packages/ui/src/primitives/Badge/Badge.types.ts +15 -0
- package/packages/ui/src/primitives/Badge/Badge.variants.ts +48 -0
- package/packages/ui/src/primitives/Badge/Badge.vue +31 -0
- package/packages/ui/src/primitives/Button/Button.props.ts +29 -0
- package/packages/ui/src/primitives/Button/Button.spec.md +139 -0
- package/packages/ui/src/primitives/Button/Button.types.ts +19 -0
- package/packages/ui/src/primitives/Button/Button.variants.ts +72 -0
- package/packages/ui/src/primitives/Button/Button.vue +90 -0
- package/packages/ui/src/primitives/Card/Card.props.ts +17 -0
- package/packages/ui/src/primitives/Card/Card.spec.md +29 -0
- package/packages/ui/src/primitives/Card/Card.types.ts +12 -0
- package/packages/ui/src/primitives/Card/Card.variants.ts +27 -0
- package/packages/ui/src/primitives/Card/Card.vue +37 -0
- package/packages/ui/src/primitives/Checkbox/Checkbox.props.ts +21 -0
- package/packages/ui/src/primitives/Checkbox/Checkbox.spec.md +51 -0
- package/packages/ui/src/primitives/Checkbox/Checkbox.types.ts +4 -0
- package/packages/ui/src/primitives/Checkbox/Checkbox.variants.ts +34 -0
- package/packages/ui/src/primitives/Checkbox/Checkbox.vue +92 -0
- package/packages/ui/src/primitives/Dialog/Dialog.props.ts +29 -0
- package/packages/ui/src/primitives/Dialog/Dialog.spec.md +52 -0
- package/packages/ui/src/primitives/Dialog/Dialog.types.ts +3 -0
- package/packages/ui/src/primitives/Dialog/Dialog.variants.ts +27 -0
- package/packages/ui/src/primitives/Dialog/Dialog.vue +78 -0
- package/packages/ui/src/primitives/Drawer/Drawer.props.ts +33 -0
- package/packages/ui/src/primitives/Drawer/Drawer.spec.md +50 -0
- package/packages/ui/src/primitives/Drawer/Drawer.types.ts +5 -0
- package/packages/ui/src/primitives/Drawer/Drawer.variants.ts +35 -0
- package/packages/ui/src/primitives/Drawer/Drawer.vue +88 -0
- package/packages/ui/src/primitives/FieldMessage/FieldMessage.props.ts +17 -0
- package/packages/ui/src/primitives/FieldMessage/FieldMessage.spec.md +35 -0
- package/packages/ui/src/primitives/FieldMessage/FieldMessage.types.ts +5 -0
- package/packages/ui/src/primitives/FieldMessage/FieldMessage.variants.ts +14 -0
- package/packages/ui/src/primitives/FieldMessage/FieldMessage.vue +40 -0
- package/packages/ui/src/primitives/FileInput/FileInput.props.ts +41 -0
- package/packages/ui/src/primitives/FileInput/FileInput.types.ts +6 -0
- package/packages/ui/src/primitives/FileInput/FileInput.variants.ts +46 -0
- package/packages/ui/src/primitives/FileInput/FileInput.vue +163 -0
- package/packages/ui/src/primitives/Input/Input.props.ts +29 -0
- package/packages/ui/src/primitives/Input/Input.spec.md +79 -0
- package/packages/ui/src/primitives/Input/Input.types.ts +13 -0
- package/packages/ui/src/primitives/Input/Input.variants.ts +54 -0
- package/packages/ui/src/primitives/Input/Input.vue +99 -0
- package/packages/ui/src/primitives/Label/Label.props.ts +25 -0
- package/packages/ui/src/primitives/Label/Label.spec.md +31 -0
- package/packages/ui/src/primitives/Label/Label.types.ts +3 -0
- package/packages/ui/src/primitives/Label/Label.variants.ts +17 -0
- package/packages/ui/src/primitives/Label/Label.vue +38 -0
- package/packages/ui/src/primitives/Menu/Menu.props.ts +17 -0
- package/packages/ui/src/primitives/Menu/Menu.spec.md +38 -0
- package/packages/ui/src/primitives/Menu/Menu.types.ts +10 -0
- package/packages/ui/src/primitives/Menu/Menu.variants.ts +10 -0
- package/packages/ui/src/primitives/Menu/Menu.vue +57 -0
- package/packages/ui/src/primitives/Popover/Popover.props.ts +25 -0
- package/packages/ui/src/primitives/Popover/Popover.spec.md +49 -0
- package/packages/ui/src/primitives/Popover/Popover.types.ts +3 -0
- package/packages/ui/src/primitives/Popover/Popover.variants.ts +18 -0
- package/packages/ui/src/primitives/Popover/Popover.vue +74 -0
- package/packages/ui/src/primitives/RadioGroup/RadioGroup.props.ts +29 -0
- package/packages/ui/src/primitives/RadioGroup/RadioGroup.spec.md +50 -0
- package/packages/ui/src/primitives/RadioGroup/RadioGroup.types.ts +12 -0
- package/packages/ui/src/primitives/RadioGroup/RadioGroup.variants.ts +48 -0
- package/packages/ui/src/primitives/RadioGroup/RadioGroup.vue +87 -0
- package/packages/ui/src/primitives/Separator/Separator.props.ts +9 -0
- package/packages/ui/src/primitives/Separator/Separator.spec.md +15 -0
- package/packages/ui/src/primitives/Separator/Separator.types.ts +3 -0
- package/packages/ui/src/primitives/Separator/Separator.variants.ts +8 -0
- package/packages/ui/src/primitives/Separator/Separator.vue +23 -0
- package/packages/ui/src/primitives/Skeleton/Skeleton.props.ts +21 -0
- package/packages/ui/src/primitives/Skeleton/Skeleton.spec.md +18 -0
- package/packages/ui/src/primitives/Skeleton/Skeleton.types.ts +5 -0
- package/packages/ui/src/primitives/Skeleton/Skeleton.variants.ts +18 -0
- package/packages/ui/src/primitives/Skeleton/Skeleton.vue +37 -0
- package/packages/ui/src/primitives/Spinner/Spinner.props.ts +13 -0
- package/packages/ui/src/primitives/Spinner/Spinner.spec.md +16 -0
- package/packages/ui/src/primitives/Spinner/Spinner.types.ts +5 -0
- package/packages/ui/src/primitives/Spinner/Spinner.variants.ts +15 -0
- package/packages/ui/src/primitives/Spinner/Spinner.vue +33 -0
- package/packages/ui/src/primitives/SplitButton/SplitButton.vue +108 -0
- package/packages/ui/src/primitives/Switch/Switch.props.ts +21 -0
- package/packages/ui/src/primitives/Switch/Switch.spec.md +49 -0
- package/packages/ui/src/primitives/Switch/Switch.types.ts +3 -0
- package/packages/ui/src/primitives/Switch/Switch.variants.ts +34 -0
- package/packages/ui/src/primitives/Switch/Switch.vue +71 -0
- package/packages/ui/src/primitives/Tabs/Tabs.props.ts +25 -0
- package/packages/ui/src/primitives/Tabs/Tabs.spec.md +48 -0
- package/packages/ui/src/primitives/Tabs/Tabs.types.ts +11 -0
- package/packages/ui/src/primitives/Tabs/Tabs.variants.ts +28 -0
- package/packages/ui/src/primitives/Tabs/Tabs.vue +59 -0
- package/packages/ui/src/primitives/Textarea/Textarea.props.ts +33 -0
- package/packages/ui/src/primitives/Textarea/Textarea.spec.md +59 -0
- package/packages/ui/src/primitives/Textarea/Textarea.types.ts +5 -0
- package/packages/ui/src/primitives/Textarea/Textarea.variants.ts +27 -0
- package/packages/ui/src/primitives/Textarea/Textarea.vue +74 -0
- package/packages/ui/src/primitives/Tooltip/Tooltip.props.ts +21 -0
- package/packages/ui/src/primitives/Tooltip/Tooltip.spec.md +45 -0
- package/packages/ui/src/primitives/Tooltip/Tooltip.types.ts +3 -0
- package/packages/ui/src/primitives/Tooltip/Tooltip.variants.ts +4 -0
- package/packages/ui/src/primitives/Tooltip/Tooltip.vue +31 -0
- package/packages/ui/src/primitives/TreeView/TreeView.types.ts +10 -0
- package/packages/ui/src/primitives/TreeView/TreeView.vue +113 -0
- package/packages/ui/src/primitives/TreeView/TreeViewNode.vue +190 -0
- package/packages/ui/src/primitives/index.ts +29 -0
- package/packages/ui/src/style.css +7 -0
- package/packages/ui/src/style.js +1 -0
- package/packages/ui/src/themes/armour.css +147 -0
- package/packages/ui/src/themes/aurora.css +147 -0
- package/packages/ui/src/themes/citrine-ash.css +147 -0
- package/packages/ui/src/themes/concord.css +147 -0
- package/packages/ui/src/themes/garnet-honey.css +147 -0
- package/packages/ui/src/themes/harbor-rose.css +147 -0
- package/packages/ui/src/themes/ledger.css +147 -0
- package/packages/ui/src/themes/neon-noir.css +74 -0
- package/packages/ui/src/themes/obsidian-iris.css +147 -0
- package/packages/ui/src/themes/pixpax.css +147 -0
- package/packages/ui/src/themes/print.css +147 -0
- package/packages/ui/src/themes/prism.css +147 -0
- package/packages/ui/src/themes/proof.css +145 -0
- package/packages/ui/src/themes/semanticThemeContract.js +2256 -0
- package/packages/ui/src/themes/spruce-ink.css +147 -0
- package/packages/ui/src/themes/sunset.css +147 -0
- package/packages/ui/tailwind.config.js +64 -0
- package/packages/ui/vite.config.js +35 -0
- package/packages/ui/vite.config.js.timestamp-1780697224943-89fbc929987bc.mjs +38 -0
- package/packages/utils/CHANGELOG.md +111 -0
- package/packages/utils/README.md +3 -0
- package/packages/utils/package.json +46 -0
- package/packages/utils/src/index.test.js +39 -0
- package/packages/utils/src/index.ts +289 -0
- package/packages/utils/tsconfig.build.json +12 -0
- package/packages/utils/vite.config.js +28 -0
- package/pnpm-workspace.yaml +8 -0
- package/scripts/vite/package-lib-config.ts +59 -0
- package/tsconfig.json +24 -0
- package/tsconfig.node.json +9 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decryptWithIdentity,
|
|
3
|
+
encryptForRecipients,
|
|
4
|
+
initArmour,
|
|
5
|
+
type ArmourIdentityInput,
|
|
6
|
+
} from "@ternent/armour";
|
|
7
|
+
import { canonicalStringify } from "ternent-utils";
|
|
8
|
+
import type { SealHash } from "./manifest";
|
|
9
|
+
import {
|
|
10
|
+
createSealHash,
|
|
11
|
+
createSealProof,
|
|
12
|
+
validateSealProofShape,
|
|
13
|
+
verifySealProofSignature,
|
|
14
|
+
type SealProofV1,
|
|
15
|
+
} from "./proof";
|
|
16
|
+
import type { SealSignerInput } from "./crypto";
|
|
17
|
+
import {
|
|
18
|
+
toSealDecryptionError,
|
|
19
|
+
toSealEncryptionError,
|
|
20
|
+
unsupportedEncryptionModeError,
|
|
21
|
+
} from "./errors";
|
|
22
|
+
|
|
23
|
+
const utf8Encoder = new TextEncoder();
|
|
24
|
+
const utf8Decoder = new TextDecoder();
|
|
25
|
+
|
|
26
|
+
export const SEAL_ARTIFACT_VERSION = "1" as const;
|
|
27
|
+
export const SEAL_ARTIFACT_TYPE = "seal-artifact" as const;
|
|
28
|
+
export const SEAL_ARTIFACT_MANIFEST_VERSION = "1" as const;
|
|
29
|
+
|
|
30
|
+
export type SealArtifactManifestV1 = {
|
|
31
|
+
version: typeof SEAL_ARTIFACT_MANIFEST_VERSION;
|
|
32
|
+
payloadType: "encrypted";
|
|
33
|
+
payloadScheme: "age";
|
|
34
|
+
payloadMode: "recipients";
|
|
35
|
+
payloadEncoding: "armor";
|
|
36
|
+
payloadHash: SealHash;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type SealEncryptedPayloadV1 = {
|
|
40
|
+
type: "encrypted";
|
|
41
|
+
scheme: "age";
|
|
42
|
+
mode: "recipients";
|
|
43
|
+
encoding: "armor";
|
|
44
|
+
data: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type SealArtifactUnsignedV1 = {
|
|
48
|
+
version: typeof SEAL_ARTIFACT_VERSION;
|
|
49
|
+
type: typeof SEAL_ARTIFACT_TYPE;
|
|
50
|
+
manifest: SealArtifactManifestV1;
|
|
51
|
+
payload: SealEncryptedPayloadV1;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type SealArtifactV1 = SealArtifactUnsignedV1 & {
|
|
55
|
+
proof: SealProofV1;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type VerifySealArtifactResult = {
|
|
59
|
+
valid: boolean;
|
|
60
|
+
hashMatch: boolean;
|
|
61
|
+
signatureValid: boolean;
|
|
62
|
+
encrypted: boolean;
|
|
63
|
+
payloadScheme: "age";
|
|
64
|
+
payloadMode: "recipients";
|
|
65
|
+
keyId: string;
|
|
66
|
+
algorithm: SealProofV1["algorithm"];
|
|
67
|
+
subjectHash: SealHash;
|
|
68
|
+
errors: string[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
72
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hasOnlyKeys(value: Record<string, unknown>, allowed: string[]): boolean {
|
|
76
|
+
return Object.keys(value).every((key) => allowed.includes(key));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isSealHash(value: unknown): value is SealHash {
|
|
80
|
+
return typeof value === "string" && /^sha256:[0-9a-f]{64}$/.test(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function normalizeBytes(value: Uint8Array | ArrayBuffer): Uint8Array {
|
|
84
|
+
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function getSealArtifactUnsignedFields(
|
|
88
|
+
artifact: SealArtifactV1 | SealArtifactUnsignedV1,
|
|
89
|
+
): SealArtifactUnsignedV1 {
|
|
90
|
+
return {
|
|
91
|
+
version: artifact.version,
|
|
92
|
+
type: artifact.type,
|
|
93
|
+
manifest: artifact.manifest,
|
|
94
|
+
payload: artifact.payload,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getUnsignedArtifactBytes(artifact: SealArtifactV1 | SealArtifactUnsignedV1): Uint8Array {
|
|
99
|
+
return utf8Encoder.encode(canonicalStringify(getSealArtifactUnsignedFields(artifact)));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function createSealArtifact(input: {
|
|
103
|
+
createdAt?: string;
|
|
104
|
+
signer: SealSignerInput;
|
|
105
|
+
subjectPath: string;
|
|
106
|
+
payload: Uint8Array | ArrayBuffer;
|
|
107
|
+
recipients: string[];
|
|
108
|
+
}): Promise<SealArtifactV1> {
|
|
109
|
+
const plaintext = normalizeBytes(input.payload);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
await initArmour();
|
|
113
|
+
|
|
114
|
+
const ciphertext = await encryptForRecipients({
|
|
115
|
+
recipients: input.recipients,
|
|
116
|
+
data: plaintext,
|
|
117
|
+
output: "armor",
|
|
118
|
+
});
|
|
119
|
+
const payloadData = utf8Decoder.decode(ciphertext);
|
|
120
|
+
const manifest: SealArtifactManifestV1 = {
|
|
121
|
+
version: SEAL_ARTIFACT_MANIFEST_VERSION,
|
|
122
|
+
payloadType: "encrypted",
|
|
123
|
+
payloadScheme: "age",
|
|
124
|
+
payloadMode: "recipients",
|
|
125
|
+
payloadEncoding: "armor",
|
|
126
|
+
payloadHash: await createSealHash(ciphertext),
|
|
127
|
+
};
|
|
128
|
+
const payload: SealEncryptedPayloadV1 = {
|
|
129
|
+
type: "encrypted",
|
|
130
|
+
scheme: "age",
|
|
131
|
+
mode: "recipients",
|
|
132
|
+
encoding: "armor",
|
|
133
|
+
data: payloadData,
|
|
134
|
+
};
|
|
135
|
+
const unsignedArtifact: SealArtifactUnsignedV1 = {
|
|
136
|
+
version: SEAL_ARTIFACT_VERSION,
|
|
137
|
+
type: SEAL_ARTIFACT_TYPE,
|
|
138
|
+
manifest,
|
|
139
|
+
payload,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const proof = await createSealProof({
|
|
143
|
+
createdAt: input.createdAt,
|
|
144
|
+
signer: input.signer,
|
|
145
|
+
subject: {
|
|
146
|
+
kind: "artifact",
|
|
147
|
+
path: input.subjectPath,
|
|
148
|
+
hash: await createSealHash(getUnsignedArtifactBytes(unsignedArtifact)),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
...unsignedArtifact,
|
|
154
|
+
proof,
|
|
155
|
+
};
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw toSealEncryptionError(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function validateSealArtifactShape(value: unknown): {
|
|
162
|
+
ok: boolean;
|
|
163
|
+
errors: string[];
|
|
164
|
+
artifact: SealArtifactV1 | null;
|
|
165
|
+
} {
|
|
166
|
+
if (!isRecord(value)) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
errors: ["Artifact must be a JSON object."],
|
|
170
|
+
artifact: null,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const errors: string[] = [];
|
|
175
|
+
|
|
176
|
+
if (!hasOnlyKeys(value, ["version", "type", "manifest", "payload", "proof"])) {
|
|
177
|
+
errors.push("Artifact contains unsupported fields.");
|
|
178
|
+
}
|
|
179
|
+
if (value.version !== SEAL_ARTIFACT_VERSION) {
|
|
180
|
+
errors.push(`Artifact version must be ${SEAL_ARTIFACT_VERSION}.`);
|
|
181
|
+
}
|
|
182
|
+
if (value.type !== SEAL_ARTIFACT_TYPE) {
|
|
183
|
+
errors.push(`Artifact type must be ${SEAL_ARTIFACT_TYPE}.`);
|
|
184
|
+
}
|
|
185
|
+
if (!isRecord(value.manifest)) {
|
|
186
|
+
errors.push("Artifact manifest must be an object.");
|
|
187
|
+
}
|
|
188
|
+
if (!isRecord(value.payload)) {
|
|
189
|
+
errors.push("Artifact payload must be an object.");
|
|
190
|
+
}
|
|
191
|
+
if (!isRecord(value.proof)) {
|
|
192
|
+
errors.push("Artifact proof must be an object.");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (
|
|
196
|
+
errors.length > 0 ||
|
|
197
|
+
!isRecord(value.manifest) ||
|
|
198
|
+
!isRecord(value.payload) ||
|
|
199
|
+
!isRecord(value.proof)
|
|
200
|
+
) {
|
|
201
|
+
return {
|
|
202
|
+
ok: false,
|
|
203
|
+
errors,
|
|
204
|
+
artifact: null,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (
|
|
209
|
+
!hasOnlyKeys(value.manifest, [
|
|
210
|
+
"version",
|
|
211
|
+
"payloadType",
|
|
212
|
+
"payloadScheme",
|
|
213
|
+
"payloadMode",
|
|
214
|
+
"payloadEncoding",
|
|
215
|
+
"payloadHash",
|
|
216
|
+
])
|
|
217
|
+
) {
|
|
218
|
+
errors.push("Artifact manifest contains unsupported fields.");
|
|
219
|
+
}
|
|
220
|
+
if (!hasOnlyKeys(value.payload, ["type", "scheme", "mode", "encoding", "data"])) {
|
|
221
|
+
errors.push("Artifact payload contains unsupported fields.");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (value.manifest.version !== SEAL_ARTIFACT_MANIFEST_VERSION) {
|
|
225
|
+
errors.push(`Artifact manifest version must be ${SEAL_ARTIFACT_MANIFEST_VERSION}.`);
|
|
226
|
+
}
|
|
227
|
+
if (value.manifest.payloadType !== "encrypted") {
|
|
228
|
+
errors.push("Artifact manifest payloadType must be encrypted.");
|
|
229
|
+
}
|
|
230
|
+
if (value.manifest.payloadScheme !== "age") {
|
|
231
|
+
errors.push("Artifact manifest payloadScheme must be age.");
|
|
232
|
+
}
|
|
233
|
+
if (value.manifest.payloadMode !== "recipients") {
|
|
234
|
+
errors.push("Artifact manifest payloadMode must be recipients.");
|
|
235
|
+
}
|
|
236
|
+
if (value.manifest.payloadEncoding !== "armor") {
|
|
237
|
+
errors.push("Artifact manifest payloadEncoding must be armor.");
|
|
238
|
+
}
|
|
239
|
+
if (!isSealHash(value.manifest.payloadHash)) {
|
|
240
|
+
errors.push("Artifact manifest payloadHash must be a sha256 hash.");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (value.payload.type !== "encrypted") {
|
|
244
|
+
errors.push("Artifact payload type must be encrypted.");
|
|
245
|
+
}
|
|
246
|
+
if (value.payload.scheme !== "age") {
|
|
247
|
+
errors.push("Artifact payload scheme must be age.");
|
|
248
|
+
}
|
|
249
|
+
if (value.payload.mode !== "recipients") {
|
|
250
|
+
errors.push("Artifact payload mode must be recipients.");
|
|
251
|
+
}
|
|
252
|
+
if (value.payload.encoding !== "armor") {
|
|
253
|
+
errors.push("Artifact payload encoding must be armor.");
|
|
254
|
+
}
|
|
255
|
+
if (typeof value.payload.data !== "string" || value.payload.data.length === 0) {
|
|
256
|
+
errors.push("Artifact payload data must be a non-empty string.");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (
|
|
260
|
+
value.manifest.payloadType !== value.payload.type ||
|
|
261
|
+
value.manifest.payloadScheme !== value.payload.scheme ||
|
|
262
|
+
value.manifest.payloadMode !== value.payload.mode ||
|
|
263
|
+
value.manifest.payloadEncoding !== value.payload.encoding
|
|
264
|
+
) {
|
|
265
|
+
errors.push("Artifact manifest and payload metadata must match.");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const proofValidation = validateSealProofShape(value.proof);
|
|
269
|
+
if (!proofValidation.ok || !proofValidation.proof) {
|
|
270
|
+
errors.push(...proofValidation.errors);
|
|
271
|
+
} else if (proofValidation.proof.subject.kind !== "artifact") {
|
|
272
|
+
errors.push("Artifact proof subject kind must be artifact.");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (errors.length > 0) {
|
|
276
|
+
return {
|
|
277
|
+
ok: false,
|
|
278
|
+
errors,
|
|
279
|
+
artifact: null,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
ok: true,
|
|
285
|
+
errors: [],
|
|
286
|
+
artifact: value as SealArtifactV1,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function parseSealArtifactJson(raw: string): {
|
|
291
|
+
ok: boolean;
|
|
292
|
+
errors: string[];
|
|
293
|
+
artifact: SealArtifactV1 | null;
|
|
294
|
+
} {
|
|
295
|
+
try {
|
|
296
|
+
return validateSealArtifactShape(JSON.parse(raw));
|
|
297
|
+
} catch {
|
|
298
|
+
return {
|
|
299
|
+
ok: false,
|
|
300
|
+
errors: ["Artifact JSON is not valid JSON."],
|
|
301
|
+
artifact: null,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export async function verifySealArtifact(
|
|
307
|
+
artifact: SealArtifactV1,
|
|
308
|
+
): Promise<VerifySealArtifactResult> {
|
|
309
|
+
const validation = validateSealArtifactShape(artifact);
|
|
310
|
+
if (!validation.ok || !validation.artifact) {
|
|
311
|
+
return {
|
|
312
|
+
valid: false,
|
|
313
|
+
hashMatch: false,
|
|
314
|
+
signatureValid: false,
|
|
315
|
+
encrypted: true,
|
|
316
|
+
payloadScheme: "age",
|
|
317
|
+
payloadMode: "recipients",
|
|
318
|
+
keyId: "",
|
|
319
|
+
algorithm: "Ed25519",
|
|
320
|
+
subjectHash: "sha256:0000000000000000000000000000000000000000000000000000000000000000",
|
|
321
|
+
errors: validation.errors,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const signatureCheck = await verifySealProofSignature(artifact.proof);
|
|
326
|
+
const subjectHash = await createSealHash(getUnsignedArtifactBytes(artifact));
|
|
327
|
+
const payloadHash = await createSealHash(utf8Encoder.encode(artifact.payload.data));
|
|
328
|
+
const artifactHashMatch = artifact.proof.subject.hash === subjectHash;
|
|
329
|
+
const payloadHashMatch = artifact.manifest.payloadHash === payloadHash;
|
|
330
|
+
const errors = [...signatureCheck.errors];
|
|
331
|
+
|
|
332
|
+
if (!artifactHashMatch) {
|
|
333
|
+
errors.push("Artifact hash does not match proof subject hash.");
|
|
334
|
+
}
|
|
335
|
+
if (!payloadHashMatch) {
|
|
336
|
+
errors.push("Encrypted payload hash does not match manifest payload hash.");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
valid: signatureCheck.ok && artifactHashMatch && payloadHashMatch,
|
|
341
|
+
hashMatch: artifactHashMatch && payloadHashMatch,
|
|
342
|
+
signatureValid: signatureCheck.ok,
|
|
343
|
+
encrypted: true,
|
|
344
|
+
payloadScheme: artifact.payload.scheme,
|
|
345
|
+
payloadMode: artifact.payload.mode,
|
|
346
|
+
keyId: artifact.proof.signer.keyId,
|
|
347
|
+
algorithm: artifact.proof.algorithm,
|
|
348
|
+
subjectHash,
|
|
349
|
+
errors,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export async function decryptSealArtifactPayload(input: {
|
|
354
|
+
artifact: SealArtifactV1;
|
|
355
|
+
identity: ArmourIdentityInput;
|
|
356
|
+
}): Promise<Uint8Array> {
|
|
357
|
+
const verification = await verifySealArtifact(input.artifact);
|
|
358
|
+
if (!verification.valid) {
|
|
359
|
+
throw new Error(verification.errors.join(" ") || "Artifact verification failed.");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (
|
|
363
|
+
input.artifact.payload.type !== "encrypted" ||
|
|
364
|
+
input.artifact.payload.scheme !== "age" ||
|
|
365
|
+
input.artifact.payload.mode !== "recipients" ||
|
|
366
|
+
input.artifact.payload.encoding !== "armor"
|
|
367
|
+
) {
|
|
368
|
+
throw unsupportedEncryptionModeError("Seal only supports age recipient-mode armored payloads.");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
await initArmour();
|
|
373
|
+
return await decryptWithIdentity({
|
|
374
|
+
identity: input.identity,
|
|
375
|
+
data: utf8Encoder.encode(input.artifact.payload.data),
|
|
376
|
+
});
|
|
377
|
+
} catch (error) {
|
|
378
|
+
throw toSealDecryptionError(error);
|
|
379
|
+
}
|
|
380
|
+
}
|