@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,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ternent/armour",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Opinionated identity-aware encryption bridge over @ternent/rage",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ternent/core.git",
|
|
9
|
+
"directory": "packages/armour"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"SPEC.md"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
33
|
+
"test": "pnpm run build && vitest run"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@ternent/identity": "workspace:*",
|
|
37
|
+
"@ternent/rage": "^0.1.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^24.3.0",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"vite": "^4.5.3",
|
|
43
|
+
"vitest": "^1.6.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
declare module "@ternent/identity" {
|
|
2
|
+
export type SerializedIdentity = {
|
|
3
|
+
format: "ternent-identity";
|
|
4
|
+
version: "2";
|
|
5
|
+
algorithm: "Ed25519";
|
|
6
|
+
createdAt: string;
|
|
7
|
+
publicKey: string;
|
|
8
|
+
keyId: string;
|
|
9
|
+
material: {
|
|
10
|
+
kind: "seed";
|
|
11
|
+
seed: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function parseIdentity(input: string | SerializedIdentity): SerializedIdentity;
|
|
16
|
+
|
|
17
|
+
export function deriveAgeRecipient(input: string | SerializedIdentity): Promise<string>;
|
|
18
|
+
|
|
19
|
+
export function deriveAgeSecretKey(input: string | SerializedIdentity): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module "@ternent/rage" {
|
|
23
|
+
export class RageError extends Error {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
readonly cause?: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class RageInitError extends RageError {}
|
|
29
|
+
export class RageValidationError extends RageError {}
|
|
30
|
+
export class RageEncryptionError extends RageError {}
|
|
31
|
+
export class RageDecryptionError extends RageError {}
|
|
32
|
+
|
|
33
|
+
export function initRage(): Promise<void>;
|
|
34
|
+
|
|
35
|
+
export function encryptWithRecipients(input: {
|
|
36
|
+
recipients: string[];
|
|
37
|
+
data: Uint8Array;
|
|
38
|
+
output?: "armor" | "binary";
|
|
39
|
+
}): Promise<Uint8Array>;
|
|
40
|
+
|
|
41
|
+
export function decryptWithIdentity(input: {
|
|
42
|
+
identity: string;
|
|
43
|
+
data: Uint8Array;
|
|
44
|
+
}): Promise<Uint8Array>;
|
|
45
|
+
|
|
46
|
+
export function encryptWithPassphrase(input: {
|
|
47
|
+
passphrase: string;
|
|
48
|
+
data: Uint8Array;
|
|
49
|
+
output?: "armor" | "binary";
|
|
50
|
+
}): Promise<Uint8Array>;
|
|
51
|
+
|
|
52
|
+
export function decryptWithPassphrase(input: {
|
|
53
|
+
passphrase: string;
|
|
54
|
+
data: Uint8Array;
|
|
55
|
+
}): Promise<Uint8Array>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RageDecryptionError,
|
|
3
|
+
RageEncryptionError,
|
|
4
|
+
RageError,
|
|
5
|
+
RageInitError,
|
|
6
|
+
RageValidationError,
|
|
7
|
+
} from "@ternent/rage";
|
|
8
|
+
import type { ArmourErrorCode } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export class ArmourError extends Error {
|
|
11
|
+
readonly code: ArmourErrorCode;
|
|
12
|
+
readonly cause?: unknown;
|
|
13
|
+
|
|
14
|
+
constructor(code: ArmourErrorCode, message: string, cause?: unknown) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = new.target.name;
|
|
17
|
+
this.code = code;
|
|
18
|
+
if (cause !== undefined) {
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ArmourInitError extends ArmourError {}
|
|
25
|
+
export class ArmourValidationError extends ArmourError {}
|
|
26
|
+
export class ArmourIdentityError extends ArmourError {}
|
|
27
|
+
export class ArmourEncryptionError extends ArmourError {}
|
|
28
|
+
export class ArmourDecryptionError extends ArmourError {}
|
|
29
|
+
|
|
30
|
+
function getMessage(error: unknown): string {
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
return error.message;
|
|
33
|
+
}
|
|
34
|
+
return String(error);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function toArmourInitError(error: unknown): ArmourInitError {
|
|
38
|
+
if (error instanceof ArmourInitError) {
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
return new ArmourInitError("ARMOUR_INIT_FAILED", "Failed to initialize Armour.", error);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function toArmourIdentityError(
|
|
45
|
+
error: unknown,
|
|
46
|
+
code: "ARMOUR_INVALID_IDENTITY" | "ARMOUR_IDENTITY_DERIVATION_FAILED",
|
|
47
|
+
fallbackMessage: string,
|
|
48
|
+
): ArmourIdentityError {
|
|
49
|
+
if (error instanceof ArmourIdentityError) {
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return new ArmourIdentityError(code, fallbackMessage, error);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function toArmourEncryptionError(error: unknown): ArmourError {
|
|
57
|
+
if (error instanceof ArmourError) {
|
|
58
|
+
return error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (error instanceof RageInitError) {
|
|
62
|
+
return new ArmourInitError(
|
|
63
|
+
"ARMOUR_INIT_FAILED",
|
|
64
|
+
"Armour is not initialized. Call initArmour() before encrypting or decrypting.",
|
|
65
|
+
error,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (error instanceof RageValidationError) {
|
|
70
|
+
switch (error.code) {
|
|
71
|
+
case "RAGE_EMPTY_DATA":
|
|
72
|
+
return new ArmourValidationError(
|
|
73
|
+
"ARMOUR_EMPTY_DATA",
|
|
74
|
+
"Data must be a non-empty Uint8Array.",
|
|
75
|
+
error,
|
|
76
|
+
);
|
|
77
|
+
case "RAGE_EMPTY_RECIPIENTS":
|
|
78
|
+
return new ArmourValidationError(
|
|
79
|
+
"ARMOUR_EMPTY_RECIPIENTS",
|
|
80
|
+
"At least one recipient is required.",
|
|
81
|
+
error,
|
|
82
|
+
);
|
|
83
|
+
case "RAGE_INVALID_RECIPIENT":
|
|
84
|
+
return new ArmourValidationError(
|
|
85
|
+
"ARMOUR_INVALID_RECIPIENT",
|
|
86
|
+
"Recipient must be an age recipient string.",
|
|
87
|
+
error,
|
|
88
|
+
);
|
|
89
|
+
case "RAGE_EMPTY_PASSPHRASE":
|
|
90
|
+
return new ArmourValidationError(
|
|
91
|
+
"ARMOUR_EMPTY_PASSPHRASE",
|
|
92
|
+
"Passphrase must not be empty.",
|
|
93
|
+
error,
|
|
94
|
+
);
|
|
95
|
+
case "RAGE_DATA_TOO_LARGE":
|
|
96
|
+
return new ArmourValidationError(
|
|
97
|
+
"ARMOUR_DATA_TOO_LARGE",
|
|
98
|
+
"Data exceeds the 64MB maximum message size.",
|
|
99
|
+
error,
|
|
100
|
+
);
|
|
101
|
+
default:
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (error instanceof RageEncryptionError || error instanceof RageError) {
|
|
107
|
+
return new ArmourEncryptionError("ARMOUR_ENCRYPT_FAILED", "Failed to encrypt data.", error);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return new ArmourEncryptionError("ARMOUR_ENCRYPT_FAILED", "Failed to encrypt data.", error);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function toArmourDecryptionError(error: unknown): ArmourError {
|
|
114
|
+
if (error instanceof ArmourError) {
|
|
115
|
+
return error;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (error instanceof RageInitError) {
|
|
119
|
+
return new ArmourInitError(
|
|
120
|
+
"ARMOUR_INIT_FAILED",
|
|
121
|
+
"Armour is not initialized. Call initArmour() before encrypting or decrypting.",
|
|
122
|
+
error,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (error instanceof RageValidationError) {
|
|
127
|
+
switch (error.code) {
|
|
128
|
+
case "RAGE_EMPTY_DATA":
|
|
129
|
+
return new ArmourValidationError(
|
|
130
|
+
"ARMOUR_EMPTY_DATA",
|
|
131
|
+
"Data must be a non-empty Uint8Array.",
|
|
132
|
+
error,
|
|
133
|
+
);
|
|
134
|
+
case "RAGE_INVALID_IDENTITY":
|
|
135
|
+
return new ArmourValidationError(
|
|
136
|
+
"ARMOUR_INVALID_SECRET_KEY",
|
|
137
|
+
"Secret key must be an age secret key string.",
|
|
138
|
+
error,
|
|
139
|
+
);
|
|
140
|
+
case "RAGE_EMPTY_PASSPHRASE":
|
|
141
|
+
return new ArmourValidationError(
|
|
142
|
+
"ARMOUR_EMPTY_PASSPHRASE",
|
|
143
|
+
"Passphrase must not be empty.",
|
|
144
|
+
error,
|
|
145
|
+
);
|
|
146
|
+
default:
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (error instanceof RageDecryptionError || error instanceof RageError) {
|
|
152
|
+
return new ArmourDecryptionError("ARMOUR_DECRYPT_FAILED", "Failed to decrypt data.", error);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return new ArmourDecryptionError("ARMOUR_DECRYPT_FAILED", "Failed to decrypt data.", error);
|
|
156
|
+
}
|
|
157
|
+
export function invalidUtf8Error(error: unknown): ArmourDecryptionError {
|
|
158
|
+
return new ArmourDecryptionError(
|
|
159
|
+
"ARMOUR_DECRYPT_FAILED",
|
|
160
|
+
"Decrypted data is not valid UTF-8.",
|
|
161
|
+
error,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function invalidBinaryInputError(value: unknown): ArmourValidationError {
|
|
166
|
+
const detail =
|
|
167
|
+
value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Blob
|
|
168
|
+
? "Data must be a non-empty Blob, File, ArrayBuffer, or Uint8Array."
|
|
169
|
+
: `Unsupported binary input type: ${getMessage(value)}`;
|
|
170
|
+
|
|
171
|
+
return new ArmourValidationError("ARMOUR_EMPTY_DATA", detail, value);
|
|
172
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { invalidBinaryInputError } from "./errors.js";
|
|
2
|
+
import { decryptWithIdentity, encryptForIdentities } from "./recipients.js";
|
|
3
|
+
import { decryptWithPassphrase, encryptWithPassphrase } from "./passphrase.js";
|
|
4
|
+
import type {
|
|
5
|
+
ArmourBinaryInput,
|
|
6
|
+
DecryptBinaryWithIdentityInput,
|
|
7
|
+
DecryptBinaryWithPassphraseInput,
|
|
8
|
+
EncryptBinaryForIdentitiesInput,
|
|
9
|
+
EncryptBinaryWithPassphraseInput,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
async function toUint8Array(data: ArmourBinaryInput): Promise<Uint8Array> {
|
|
13
|
+
if (data instanceof Uint8Array) {
|
|
14
|
+
if (data.byteLength === 0) {
|
|
15
|
+
throw invalidBinaryInputError(data);
|
|
16
|
+
}
|
|
17
|
+
return Uint8Array.from(data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (data instanceof ArrayBuffer) {
|
|
21
|
+
if (data.byteLength === 0) {
|
|
22
|
+
throw invalidBinaryInputError(data);
|
|
23
|
+
}
|
|
24
|
+
return new Uint8Array(data.slice(0));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (data instanceof Blob) {
|
|
28
|
+
if (data.size === 0) {
|
|
29
|
+
throw invalidBinaryInputError(data);
|
|
30
|
+
}
|
|
31
|
+
return new Uint8Array(await data.arrayBuffer());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw invalidBinaryInputError(data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function encryptBinaryForIdentities(
|
|
38
|
+
input: EncryptBinaryForIdentitiesInput,
|
|
39
|
+
): Promise<Uint8Array> {
|
|
40
|
+
return encryptForIdentities({
|
|
41
|
+
identities: input.identities,
|
|
42
|
+
data: await toUint8Array(input.data),
|
|
43
|
+
output: input.output,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function decryptBinaryWithIdentity(
|
|
48
|
+
input: DecryptBinaryWithIdentityInput,
|
|
49
|
+
): Promise<Uint8Array> {
|
|
50
|
+
return decryptWithIdentity({
|
|
51
|
+
identity: input.identity,
|
|
52
|
+
data: await toUint8Array(input.data),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function encryptBinaryWithPassphrase(
|
|
57
|
+
input: EncryptBinaryWithPassphraseInput,
|
|
58
|
+
): Promise<Uint8Array> {
|
|
59
|
+
return encryptWithPassphrase({
|
|
60
|
+
passphrase: input.passphrase,
|
|
61
|
+
data: await toUint8Array(input.data),
|
|
62
|
+
output: input.output,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function decryptBinaryWithPassphrase(
|
|
67
|
+
input: DecryptBinaryWithPassphraseInput,
|
|
68
|
+
): Promise<Uint8Array> {
|
|
69
|
+
return decryptWithPassphrase({
|
|
70
|
+
passphrase: input.passphrase,
|
|
71
|
+
data: await toUint8Array(input.data),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deriveAgeRecipient,
|
|
3
|
+
deriveAgeSecretKey,
|
|
4
|
+
parseIdentity,
|
|
5
|
+
type SerializedIdentity,
|
|
6
|
+
} from "@ternent/identity";
|
|
7
|
+
import { AGE_SECRET_KEY_PREFIX } from "./constants.js";
|
|
8
|
+
import { ArmourIdentityError, ArmourValidationError, toArmourIdentityError } from "./errors.js";
|
|
9
|
+
import type { ArmourIdentityInput } from "./types.js";
|
|
10
|
+
|
|
11
|
+
export async function resolveIdentity(input: ArmourIdentityInput): Promise<SerializedIdentity> {
|
|
12
|
+
try {
|
|
13
|
+
return parseIdentity(input);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw toArmourIdentityError(
|
|
16
|
+
error,
|
|
17
|
+
"ARMOUR_INVALID_IDENTITY",
|
|
18
|
+
"Identity input must be a valid @ternent/identity serialized identity.",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function recipientFromIdentity(input: ArmourIdentityInput): Promise<string> {
|
|
24
|
+
const identity = await resolveIdentity(input);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return await deriveAgeRecipient(identity);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw toArmourIdentityError(
|
|
30
|
+
error,
|
|
31
|
+
"ARMOUR_IDENTITY_DERIVATION_FAILED",
|
|
32
|
+
"Failed to derive an age recipient from the provided identity.",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function secretKeyFromIdentity(input: ArmourIdentityInput): Promise<string> {
|
|
38
|
+
const identity = await resolveIdentity(input);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
return await deriveAgeSecretKey(identity);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw toArmourIdentityError(
|
|
44
|
+
error,
|
|
45
|
+
"ARMOUR_IDENTITY_DERIVATION_FAILED",
|
|
46
|
+
"Failed to derive an age secret key from the provided identity.",
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function normalizeSecretKey(secretKey: string): Promise<string> {
|
|
52
|
+
const normalized = String(secretKey || "").trim();
|
|
53
|
+
|
|
54
|
+
if (!normalized.startsWith(AGE_SECRET_KEY_PREFIX)) {
|
|
55
|
+
throw new ArmourValidationError(
|
|
56
|
+
"ARMOUR_INVALID_SECRET_KEY",
|
|
57
|
+
"Secret key must be an age secret key string.",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function assertIdentityCapabilityRoot(
|
|
65
|
+
input: ArmourIdentityInput,
|
|
66
|
+
): Promise<SerializedIdentity> {
|
|
67
|
+
const identity = await resolveIdentity(input);
|
|
68
|
+
if (identity.algorithm !== "Ed25519") {
|
|
69
|
+
throw new ArmourIdentityError("ARMOUR_INVALID_IDENTITY", "Identity algorithm must be Ed25519.");
|
|
70
|
+
}
|
|
71
|
+
return identity;
|
|
72
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ArmourDecryptionError,
|
|
3
|
+
ArmourEncryptionError,
|
|
4
|
+
ArmourError,
|
|
5
|
+
ArmourIdentityError,
|
|
6
|
+
ArmourInitError,
|
|
7
|
+
ArmourValidationError,
|
|
8
|
+
} from "./errors.js";
|
|
9
|
+
export {
|
|
10
|
+
decryptBinaryWithIdentity,
|
|
11
|
+
decryptBinaryWithPassphrase,
|
|
12
|
+
encryptBinaryForIdentities,
|
|
13
|
+
encryptBinaryWithPassphrase,
|
|
14
|
+
} from "./files.js";
|
|
15
|
+
export {
|
|
16
|
+
assertIdentityCapabilityRoot,
|
|
17
|
+
recipientFromIdentity,
|
|
18
|
+
resolveIdentity,
|
|
19
|
+
secretKeyFromIdentity,
|
|
20
|
+
} from "./identity.js";
|
|
21
|
+
export { decryptWithPassphrase, encryptWithPassphrase } from "./passphrase.js";
|
|
22
|
+
export {
|
|
23
|
+
decryptWithIdentity,
|
|
24
|
+
decryptWithSecretKey,
|
|
25
|
+
encryptForIdentities,
|
|
26
|
+
encryptForRecipients,
|
|
27
|
+
recipientsFromIdentities,
|
|
28
|
+
} from "./recipients.js";
|
|
29
|
+
export {
|
|
30
|
+
decryptTextWithIdentity,
|
|
31
|
+
decryptTextWithPassphrase,
|
|
32
|
+
encryptTextForIdentities,
|
|
33
|
+
encryptTextWithPassphrase,
|
|
34
|
+
} from "./text.js";
|
|
35
|
+
export { initArmour } from "./init.js";
|
|
36
|
+
export type { SerializedIdentity } from "@ternent/identity";
|
|
37
|
+
export type {
|
|
38
|
+
ArmourBinaryInput,
|
|
39
|
+
ArmourErrorCode,
|
|
40
|
+
ArmourIdentityInput,
|
|
41
|
+
ArmourOutputFormat,
|
|
42
|
+
DecryptBinaryWithIdentityInput,
|
|
43
|
+
DecryptBinaryWithPassphraseInput,
|
|
44
|
+
DecryptTextWithIdentityInput,
|
|
45
|
+
DecryptTextWithPassphraseInput,
|
|
46
|
+
DecryptWithIdentityInput,
|
|
47
|
+
DecryptWithPassphraseInput,
|
|
48
|
+
DecryptWithSecretKeyInput,
|
|
49
|
+
EncryptBinaryForIdentitiesInput,
|
|
50
|
+
EncryptBinaryWithPassphraseInput,
|
|
51
|
+
EncryptForIdentitiesInput,
|
|
52
|
+
EncryptForRecipientsInput,
|
|
53
|
+
EncryptTextForIdentitiesInput,
|
|
54
|
+
EncryptTextWithPassphraseInput,
|
|
55
|
+
EncryptWithPassphraseInput,
|
|
56
|
+
} from "./types.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decryptWithPassphrase as rageDecryptWithPassphrase,
|
|
3
|
+
encryptWithPassphrase as rageEncryptWithPassphrase,
|
|
4
|
+
} from "@ternent/rage";
|
|
5
|
+
import { toArmourDecryptionError, toArmourEncryptionError } from "./errors.js";
|
|
6
|
+
import type { DecryptWithPassphraseInput, EncryptWithPassphraseInput } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export async function encryptWithPassphrase(
|
|
9
|
+
input: EncryptWithPassphraseInput,
|
|
10
|
+
): Promise<Uint8Array> {
|
|
11
|
+
try {
|
|
12
|
+
return await rageEncryptWithPassphrase({
|
|
13
|
+
passphrase: input.passphrase,
|
|
14
|
+
data: input.data,
|
|
15
|
+
output: input.output,
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw toArmourEncryptionError(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function decryptWithPassphrase(
|
|
23
|
+
input: DecryptWithPassphraseInput,
|
|
24
|
+
): Promise<Uint8Array> {
|
|
25
|
+
try {
|
|
26
|
+
return await rageDecryptWithPassphrase({
|
|
27
|
+
passphrase: input.passphrase,
|
|
28
|
+
data: input.data,
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw toArmourDecryptionError(error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decryptWithIdentity as rageDecryptWithIdentity,
|
|
3
|
+
encryptWithRecipients as rageEncryptWithRecipients,
|
|
4
|
+
} from "@ternent/rage";
|
|
5
|
+
import {
|
|
6
|
+
normalizeSecretKey,
|
|
7
|
+
recipientFromIdentity,
|
|
8
|
+
resolveIdentity,
|
|
9
|
+
secretKeyFromIdentity,
|
|
10
|
+
} from "./identity.js";
|
|
11
|
+
import { toArmourDecryptionError, toArmourEncryptionError } from "./errors.js";
|
|
12
|
+
import type {
|
|
13
|
+
ArmourIdentityInput,
|
|
14
|
+
DecryptWithIdentityInput,
|
|
15
|
+
DecryptWithSecretKeyInput,
|
|
16
|
+
EncryptForIdentitiesInput,
|
|
17
|
+
EncryptForRecipientsInput,
|
|
18
|
+
} from "./types.js";
|
|
19
|
+
|
|
20
|
+
export async function recipientsFromIdentities(
|
|
21
|
+
identities: ArmourIdentityInput[],
|
|
22
|
+
): Promise<string[]> {
|
|
23
|
+
const resolved: string[] = [];
|
|
24
|
+
|
|
25
|
+
for (const identity of identities) {
|
|
26
|
+
await resolveIdentity(identity);
|
|
27
|
+
resolved.push(await recipientFromIdentity(identity));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function encryptForRecipients(input: EncryptForRecipientsInput): Promise<Uint8Array> {
|
|
34
|
+
try {
|
|
35
|
+
return await rageEncryptWithRecipients({
|
|
36
|
+
recipients: input.recipients,
|
|
37
|
+
data: input.data,
|
|
38
|
+
output: input.output,
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw toArmourEncryptionError(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function decryptWithSecretKey(input: DecryptWithSecretKeyInput): Promise<Uint8Array> {
|
|
46
|
+
try {
|
|
47
|
+
return await rageDecryptWithIdentity({
|
|
48
|
+
identity: await normalizeSecretKey(input.secretKey),
|
|
49
|
+
data: input.data,
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw toArmourDecryptionError(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function encryptForIdentities(input: EncryptForIdentitiesInput): Promise<Uint8Array> {
|
|
57
|
+
return encryptForRecipients({
|
|
58
|
+
recipients: await recipientsFromIdentities(input.identities),
|
|
59
|
+
data: input.data,
|
|
60
|
+
output: input.output,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function decryptWithIdentity(input: DecryptWithIdentityInput): Promise<Uint8Array> {
|
|
65
|
+
try {
|
|
66
|
+
return await rageDecryptWithIdentity({
|
|
67
|
+
identity: await secretKeyFromIdentity(input.identity),
|
|
68
|
+
data: input.data,
|
|
69
|
+
});
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw toArmourDecryptionError(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { utf8Decoder, utf8Encoder } from "./constants.js";
|
|
2
|
+
import { invalidUtf8Error } from "./errors.js";
|
|
3
|
+
import { decryptWithIdentity, encryptForIdentities } from "./recipients.js";
|
|
4
|
+
import { decryptWithPassphrase, encryptWithPassphrase } from "./passphrase.js";
|
|
5
|
+
import type {
|
|
6
|
+
DecryptTextWithIdentityInput,
|
|
7
|
+
DecryptTextWithPassphraseInput,
|
|
8
|
+
EncryptTextForIdentitiesInput,
|
|
9
|
+
EncryptTextWithPassphraseInput,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
function decodeUtf8(data: Uint8Array): string {
|
|
13
|
+
try {
|
|
14
|
+
return utf8Decoder.decode(data);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw invalidUtf8Error(error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeCiphertext(data: string | Uint8Array): Uint8Array {
|
|
21
|
+
return typeof data === "string" ? utf8Encoder.encode(data) : data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function encryptTextForIdentities(
|
|
25
|
+
input: EncryptTextForIdentitiesInput,
|
|
26
|
+
): Promise<string> {
|
|
27
|
+
const ciphertext = await encryptForIdentities({
|
|
28
|
+
identities: input.identities,
|
|
29
|
+
data: utf8Encoder.encode(input.text),
|
|
30
|
+
output: "armor",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return utf8Decoder.decode(ciphertext);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function decryptTextWithIdentity(
|
|
37
|
+
input: DecryptTextWithIdentityInput,
|
|
38
|
+
): Promise<string> {
|
|
39
|
+
const plaintext = await decryptWithIdentity({
|
|
40
|
+
identity: input.identity,
|
|
41
|
+
data: normalizeCiphertext(input.data),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return decodeUtf8(plaintext);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function encryptTextWithPassphrase(
|
|
48
|
+
input: EncryptTextWithPassphraseInput,
|
|
49
|
+
): Promise<string> {
|
|
50
|
+
const ciphertext = await encryptWithPassphrase({
|
|
51
|
+
passphrase: input.passphrase,
|
|
52
|
+
data: utf8Encoder.encode(input.text),
|
|
53
|
+
output: "armor",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return utf8Decoder.decode(ciphertext);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function decryptTextWithPassphrase(
|
|
60
|
+
input: DecryptTextWithPassphraseInput,
|
|
61
|
+
): Promise<string> {
|
|
62
|
+
const plaintext = await decryptWithPassphrase({
|
|
63
|
+
passphrase: input.passphrase,
|
|
64
|
+
data: normalizeCiphertext(input.data),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return decodeUtf8(plaintext);
|
|
68
|
+
}
|