@attocash/cli 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/LICENSE +28 -0
- package/README.md +707 -0
- package/dist/application/app.d.ts +138 -0
- package/dist/application/app.js +654 -0
- package/dist/application/operations.d.ts +9 -0
- package/dist/application/operations.js +96 -0
- package/dist/cli/cli.d.ts +1 -0
- package/dist/cli/cli.js +460 -0
- package/dist/cli/help.d.ts +4 -0
- package/dist/cli/help.js +49 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +13 -0
- package/dist/cli/onboarding.d.ts +14 -0
- package/dist/cli/onboarding.js +144 -0
- package/dist/cli/output.d.ts +2 -0
- package/dist/cli/output.js +231 -0
- package/dist/cli/terminal.d.ts +6 -0
- package/dist/cli/terminal.js +92 -0
- package/dist/cli/update-check.d.ts +1 -0
- package/dist/cli/update-check.js +12 -0
- package/dist/cli/updates.d.ts +2 -0
- package/dist/cli/updates.js +98 -0
- package/dist/core.d.ts +14 -0
- package/dist/core.js +14 -0
- package/dist/doctor/credential-probe.d.ts +7 -0
- package/dist/doctor/credential-probe.js +49 -0
- package/dist/doctor/doctor.d.ts +4 -0
- package/dist/doctor/doctor.js +213 -0
- package/dist/doctor/keyring.d.ts +7 -0
- package/dist/doctor/keyring.js +150 -0
- package/dist/doctor/profile.d.ts +19 -0
- package/dist/doctor/profile.js +73 -0
- package/dist/doctor/types.d.ts +40 -0
- package/dist/doctor/types.js +1 -0
- package/dist/domain/amount.d.ts +6 -0
- package/dist/domain/amount.js +27 -0
- package/dist/domain/errors.d.ts +10 -0
- package/dist/domain/errors.js +16 -0
- package/dist/labels/directory.d.ts +87 -0
- package/dist/labels/directory.js +140 -0
- package/dist/labels/personal.d.ts +17 -0
- package/dist/labels/personal.js +56 -0
- package/dist/labels/presentation.d.ts +154 -0
- package/dist/labels/presentation.js +90 -0
- package/dist/network/reader.d.ts +31 -0
- package/dist/network/reader.js +370 -0
- package/dist/network/retry.d.ts +7 -0
- package/dist/network/retry.js +53 -0
- package/dist/network/work.d.ts +3 -0
- package/dist/network/work.js +66 -0
- package/dist/pricing/market.d.ts +29 -0
- package/dist/pricing/market.js +150 -0
- package/dist/pricing/terms.d.ts +6 -0
- package/dist/pricing/terms.js +12 -0
- package/dist/spending/destination.d.ts +16 -0
- package/dist/spending/destination.js +42 -0
- package/dist/spending/journal.d.ts +28 -0
- package/dist/spending/journal.js +69 -0
- package/dist/spending/ledger.d.ts +118 -0
- package/dist/spending/ledger.js +444 -0
- package/dist/spending/payments.d.ts +67 -0
- package/dist/spending/payments.js +424 -0
- package/dist/spending/pool.d.ts +13 -0
- package/dist/spending/pool.js +38 -0
- package/dist/spending/reconcile.d.ts +18 -0
- package/dist/spending/reconcile.js +64 -0
- package/dist/storage/profiles.d.ts +13 -0
- package/dist/storage/profiles.js +86 -0
- package/dist/storage/secrets.d.ts +16 -0
- package/dist/storage/secrets.js +104 -0
- package/dist/storage/state.d.ts +32 -0
- package/dist/storage/state.js +255 -0
- package/dist/wallet/auto-receive.d.ts +57 -0
- package/dist/wallet/auto-receive.js +140 -0
- package/dist/wallet/defaults.d.ts +3 -0
- package/dist/wallet/defaults.js +26 -0
- package/dist/wallet/signing.d.ts +17 -0
- package/dist/wallet/signing.js +128 -0
- package/dist/wallet/types.d.ts +65 -0
- package/dist/wallet/types.js +1 -0
- package/dist/wallet/work.d.ts +29 -0
- package/dist/wallet/work.js +154 -0
- package/dist/watches/manager.d.ts +75 -0
- package/dist/watches/manager.js +197 -0
- package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs +6678 -0
- package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/LICENSE +28 -0
- package/node_modules/@attocash/commons-core/README.md +118 -0
- package/node_modules/@attocash/commons-core/commons-commons-core.d.mts +1036 -0
- package/node_modules/@attocash/commons-core/commons-commons-core.mjs +7701 -0
- package/node_modules/@attocash/commons-core/commons-commons-core.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs +17681 -0
- package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs +4 -0
- package/node_modules/@attocash/commons-core/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs +209 -0
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs +2284 -0
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs +6042 -0
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-core/package.json +27 -0
- package/node_modules/@attocash/commons-node/LICENSE +28 -0
- package/node_modules/@attocash/commons-node/README.md +92 -0
- package/node_modules/@attocash/commons-node/commons-commons-node.d.mts +255 -0
- package/node_modules/@attocash/commons-node/commons-commons-node.mjs +2977 -0
- package/node_modules/@attocash/commons-node/commons-commons-node.mjs.map +1 -0
- package/node_modules/@attocash/commons-node/kotlin-logging.mjs +432 -0
- package/node_modules/@attocash/commons-node/kotlin-logging.mjs.map +1 -0
- package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-node/package.json +29 -0
- package/node_modules/@attocash/commons-node-remote/LICENSE +28 -0
- package/node_modules/@attocash/commons-node-remote/README.md +61 -0
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.d.mts +122 -0
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs +1810 -0
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs.map +1 -0
- package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs +432 -0
- package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs.map +1 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-browser.mjs +8 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-browser.mjs.map +1 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-node-remote/package.json +31 -0
- package/node_modules/@attocash/commons-transport/LICENSE +28 -0
- package/node_modules/@attocash/commons-transport/README.md +5 -0
- package/node_modules/@attocash/commons-transport/commons-commons-transport.d.mts +64 -0
- package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs +249 -0
- package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs +263 -0
- package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/kotlinx-browser.mjs +8 -0
- package/node_modules/@attocash/commons-transport/kotlinx-browser.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs +11604 -0
- package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs +499 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs +6456 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs +83 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs +1714 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs +3197 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs +2290 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs +46 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs +482 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs +165 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-sse.mjs +4 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-sse.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs +3222 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-websocket-serialization.mjs +4 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-websocket-serialization.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs +1485 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/package.json +29 -0
- package/node_modules/@attocash/commons-worker/LICENSE +28 -0
- package/node_modules/@attocash/commons-worker/README.md +48 -0
- package/node_modules/@attocash/commons-worker/commons-commons-worker.d.mts +73 -0
- package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs +702 -0
- package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker/kotlin-logging.mjs +432 -0
- package/node_modules/@attocash/commons-worker/kotlin-logging.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker/package.json +29 -0
- package/node_modules/@attocash/commons-worker-remote/LICENSE +28 -0
- package/node_modules/@attocash/commons-worker-remote/README.md +60 -0
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.d.mts +93 -0
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs +289 -0
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs +432 -0
- package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-browser.mjs +8 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-browser.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
- package/node_modules/@attocash/commons-worker-remote/package.json +31 -0
- package/node_modules/@js-joda/core/CHANGELOG.md +363 -0
- package/node_modules/@js-joda/core/CheatSheet.md +947 -0
- package/node_modules/@js-joda/core/LICENSE +34 -0
- package/node_modules/@js-joda/core/README.md +155 -0
- package/node_modules/@js-joda/core/bower.json +21 -0
- package/node_modules/@js-joda/core/dist/js-joda.d.ts +2452 -0
- package/node_modules/@js-joda/core/dist/js-joda.esm.js +13564 -0
- package/node_modules/@js-joda/core/dist/js-joda.flow.js +949 -0
- package/node_modules/@js-joda/core/dist/js-joda.js +13630 -0
- package/node_modules/@js-joda/core/dist/js-joda.js.map +1 -0
- package/node_modules/@js-joda/core/dist/js-joda.min.js +5 -0
- package/node_modules/@js-joda/core/package.json +76 -0
- package/node_modules/@js-joda/core/src/Clock.js +330 -0
- package/node_modules/@js-joda/core/src/DayOfWeek.js +451 -0
- package/node_modules/@js-joda/core/src/Duration.js +1205 -0
- package/node_modules/@js-joda/core/src/Enum.js +30 -0
- package/node_modules/@js-joda/core/src/Instant.js +1012 -0
- package/node_modules/@js-joda/core/src/LocalDate.js +1703 -0
- package/node_modules/@js-joda/core/src/LocalDateTime.js +1686 -0
- package/node_modules/@js-joda/core/src/LocalTime.js +1415 -0
- package/node_modules/@js-joda/core/src/MathUtil.js +236 -0
- package/node_modules/@js-joda/core/src/Month.js +600 -0
- package/node_modules/@js-joda/core/src/MonthDay.js +730 -0
- package/node_modules/@js-joda/core/src/OffsetDateTime.js +757 -0
- package/node_modules/@js-joda/core/src/OffsetTime.js +621 -0
- package/node_modules/@js-joda/core/src/Period.js +933 -0
- package/node_modules/@js-joda/core/src/StringUtil.js +43 -0
- package/node_modules/@js-joda/core/src/Year.js +1015 -0
- package/node_modules/@js-joda/core/src/YearConstants.js +21 -0
- package/node_modules/@js-joda/core/src/YearMonth.js +1096 -0
- package/node_modules/@js-joda/core/src/ZoneId.js +236 -0
- package/node_modules/@js-joda/core/src/ZoneIdFactory.js +201 -0
- package/node_modules/@js-joda/core/src/ZoneOffset.js +486 -0
- package/node_modules/@js-joda/core/src/ZoneRegion.js +72 -0
- package/node_modules/@js-joda/core/src/ZonedDateTime.js +2007 -0
- package/node_modules/@js-joda/core/src/_init.js +68 -0
- package/node_modules/@js-joda/core/src/assert.js +33 -0
- package/node_modules/@js-joda/core/src/chrono/ChronoLocalDate.js +230 -0
- package/node_modules/@js-joda/core/src/chrono/ChronoLocalDateTime.js +130 -0
- package/node_modules/@js-joda/core/src/chrono/ChronoZonedDateTime.js +194 -0
- package/node_modules/@js-joda/core/src/chrono/IsoChronology.js +235 -0
- package/node_modules/@js-joda/core/src/convert.js +83 -0
- package/node_modules/@js-joda/core/src/errors.js +54 -0
- package/node_modules/@js-joda/core/src/format/DateTimeBuilder.js +535 -0
- package/node_modules/@js-joda/core/src/format/DateTimeFormatter.js +728 -0
- package/node_modules/@js-joda/core/src/format/DateTimeFormatterBuilder.js +1545 -0
- package/node_modules/@js-joda/core/src/format/DateTimeParseContext.js +297 -0
- package/node_modules/@js-joda/core/src/format/DateTimePrintContext.js +138 -0
- package/node_modules/@js-joda/core/src/format/DecimalStyle.js +113 -0
- package/node_modules/@js-joda/core/src/format/EnumMap.js +70 -0
- package/node_modules/@js-joda/core/src/format/ParsePosition.js +31 -0
- package/node_modules/@js-joda/core/src/format/ResolverStyle.js +93 -0
- package/node_modules/@js-joda/core/src/format/SignStyle.js +38 -0
- package/node_modules/@js-joda/core/src/format/StringBuilder.js +47 -0
- package/node_modules/@js-joda/core/src/format/TextStyle.js +114 -0
- package/node_modules/@js-joda/core/src/format/parser/CharLiteralPrinterParser.js +46 -0
- package/node_modules/@js-joda/core/src/format/parser/CompositePrinterParser.js +89 -0
- package/node_modules/@js-joda/core/src/format/parser/FractionPrinterParser.js +162 -0
- package/node_modules/@js-joda/core/src/format/parser/NumberPrinterParser.js +367 -0
- package/node_modules/@js-joda/core/src/format/parser/OffsetIdPrinterParser.js +177 -0
- package/node_modules/@js-joda/core/src/format/parser/PadPrinterParserDecorator.js +81 -0
- package/node_modules/@js-joda/core/src/format/parser/SettingsParser.js +44 -0
- package/node_modules/@js-joda/core/src/format/parser/StringLiteralPrinterParser.js +39 -0
- package/node_modules/@js-joda/core/src/format/parser/ZoneIdPrinterParser.js +218 -0
- package/node_modules/@js-joda/core/src/js-joda.js +210 -0
- package/node_modules/@js-joda/core/src/license-preamble.js +3 -0
- package/node_modules/@js-joda/core/src/temporal/ChronoField.js +470 -0
- package/node_modules/@js-joda/core/src/temporal/ChronoUnit.js +310 -0
- package/node_modules/@js-joda/core/src/temporal/DefaultInterfaceTemporal.js +118 -0
- package/node_modules/@js-joda/core/src/temporal/IsoFields.js +859 -0
- package/node_modules/@js-joda/core/src/temporal/NativeJsTemporal.js +105 -0
- package/node_modules/@js-joda/core/src/temporal/Temporal.js +346 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalAccessor.js +125 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalAdjuster.js +92 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalAdjusters.js +464 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalAmount.js +166 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalField.js +248 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalQueries.js +223 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalQueriesFactory.js +77 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalQuery.js +107 -0
- package/node_modules/@js-joda/core/src/temporal/TemporalUnit.js +179 -0
- package/node_modules/@js-joda/core/src/temporal/ValueRange.js +257 -0
- package/node_modules/@js-joda/core/src/use.js +20 -0
- package/node_modules/@js-joda/core/src/zone/SystemDefaultZoneId.js +31 -0
- package/node_modules/@js-joda/core/src/zone/SystemDefaultZoneRules.js +162 -0
- package/node_modules/@js-joda/core/src/zone/ZoneOffsetTransition.js +289 -0
- package/node_modules/@js-joda/core/src/zone/ZoneRules.js +464 -0
- package/node_modules/@js-joda/core/src/zone/ZoneRulesProvider.js +36 -0
- package/node_modules/@noble/hashes/LICENSE +21 -0
- package/node_modules/@noble/hashes/README.md +563 -0
- package/node_modules/@noble/hashes/_blake.d.ts +21 -0
- package/node_modules/@noble/hashes/_blake.d.ts.map +1 -0
- package/node_modules/@noble/hashes/_blake.js +52 -0
- package/node_modules/@noble/hashes/_blake.js.map +1 -0
- package/node_modules/@noble/hashes/_md.d.ts +99 -0
- package/node_modules/@noble/hashes/_md.d.ts.map +1 -0
- package/node_modules/@noble/hashes/_md.js +202 -0
- package/node_modules/@noble/hashes/_md.js.map +1 -0
- package/node_modules/@noble/hashes/_u64.d.ts +63 -0
- package/node_modules/@noble/hashes/_u64.d.ts.map +1 -0
- package/node_modules/@noble/hashes/_u64.js +84 -0
- package/node_modules/@noble/hashes/_u64.js.map +1 -0
- package/node_modules/@noble/hashes/argon2.d.ts +112 -0
- package/node_modules/@noble/hashes/argon2.d.ts.map +1 -0
- package/node_modules/@noble/hashes/argon2.js +517 -0
- package/node_modules/@noble/hashes/argon2.js.map +1 -0
- package/node_modules/@noble/hashes/blake1.d.ts +156 -0
- package/node_modules/@noble/hashes/blake1.d.ts.map +1 -0
- package/node_modules/@noble/hashes/blake1.js +560 -0
- package/node_modules/@noble/hashes/blake1.js.map +1 -0
- package/node_modules/@noble/hashes/blake2.d.ts +184 -0
- package/node_modules/@noble/hashes/blake2.d.ts.map +1 -0
- package/node_modules/@noble/hashes/blake2.js +501 -0
- package/node_modules/@noble/hashes/blake2.js.map +1 -0
- package/node_modules/@noble/hashes/blake3.d.ts +68 -0
- package/node_modules/@noble/hashes/blake3.d.ts.map +1 -0
- package/node_modules/@noble/hashes/blake3.js +284 -0
- package/node_modules/@noble/hashes/blake3.js.map +1 -0
- package/node_modules/@noble/hashes/eskdf.d.ts +92 -0
- package/node_modules/@noble/hashes/eskdf.d.ts.map +1 -0
- package/node_modules/@noble/hashes/eskdf.js +218 -0
- package/node_modules/@noble/hashes/eskdf.js.map +1 -0
- package/node_modules/@noble/hashes/hkdf.d.ts +64 -0
- package/node_modules/@noble/hashes/hkdf.d.ts.map +1 -0
- package/node_modules/@noble/hashes/hkdf.js +120 -0
- package/node_modules/@noble/hashes/hkdf.js.map +1 -0
- package/node_modules/@noble/hashes/hmac.d.ts +47 -0
- package/node_modules/@noble/hashes/hmac.d.ts.map +1 -0
- package/node_modules/@noble/hashes/hmac.js +93 -0
- package/node_modules/@noble/hashes/hmac.js.map +1 -0
- package/node_modules/@noble/hashes/index.d.ts +2 -0
- package/node_modules/@noble/hashes/index.d.ts.map +1 -0
- package/node_modules/@noble/hashes/index.js +35 -0
- package/node_modules/@noble/hashes/index.js.map +1 -0
- package/node_modules/@noble/hashes/legacy.d.ts +102 -0
- package/node_modules/@noble/hashes/legacy.d.ts.map +1 -0
- package/node_modules/@noble/hashes/legacy.js +327 -0
- package/node_modules/@noble/hashes/legacy.js.map +1 -0
- package/node_modules/@noble/hashes/package.json +97 -0
- package/node_modules/@noble/hashes/pbkdf2.d.ts +56 -0
- package/node_modules/@noble/hashes/pbkdf2.d.ts.map +1 -0
- package/node_modules/@noble/hashes/pbkdf2.js +135 -0
- package/node_modules/@noble/hashes/pbkdf2.js.map +1 -0
- package/node_modules/@noble/hashes/scrypt.d.ts +65 -0
- package/node_modules/@noble/hashes/scrypt.d.ts.map +1 -0
- package/node_modules/@noble/hashes/scrypt.js +257 -0
- package/node_modules/@noble/hashes/scrypt.js.map +1 -0
- package/node_modules/@noble/hashes/sha2.d.ts +249 -0
- package/node_modules/@noble/hashes/sha2.d.ts.map +1 -0
- package/node_modules/@noble/hashes/sha2.js +458 -0
- package/node_modules/@noble/hashes/sha2.js.map +1 -0
- package/node_modules/@noble/hashes/sha3-addons.d.ts +461 -0
- package/node_modules/@noble/hashes/sha3-addons.d.ts.map +1 -0
- package/node_modules/@noble/hashes/sha3-addons.js +783 -0
- package/node_modules/@noble/hashes/sha3-addons.js.map +1 -0
- package/node_modules/@noble/hashes/sha3.d.ts +199 -0
- package/node_modules/@noble/hashes/sha3.d.ts.map +1 -0
- package/node_modules/@noble/hashes/sha3.js +431 -0
- package/node_modules/@noble/hashes/sha3.js.map +1 -0
- package/node_modules/@noble/hashes/src/_blake.ts +57 -0
- package/node_modules/@noble/hashes/src/_md.ts +222 -0
- package/node_modules/@noble/hashes/src/_u64.ts +117 -0
- package/node_modules/@noble/hashes/src/argon2.ts +667 -0
- package/node_modules/@noble/hashes/src/blake1.ts +614 -0
- package/node_modules/@noble/hashes/src/blake2.ts +582 -0
- package/node_modules/@noble/hashes/src/blake3.ts +317 -0
- package/node_modules/@noble/hashes/src/eskdf.ts +259 -0
- package/node_modules/@noble/hashes/src/hkdf.ts +133 -0
- package/node_modules/@noble/hashes/src/hmac.ts +126 -0
- package/node_modules/@noble/hashes/src/index.ts +33 -0
- package/node_modules/@noble/hashes/src/legacy.ts +339 -0
- package/node_modules/@noble/hashes/src/pbkdf2.ts +175 -0
- package/node_modules/@noble/hashes/src/scrypt.ts +315 -0
- package/node_modules/@noble/hashes/src/sha2.ts +530 -0
- package/node_modules/@noble/hashes/src/sha3-addons.ts +983 -0
- package/node_modules/@noble/hashes/src/sha3.ts +485 -0
- package/node_modules/@noble/hashes/src/utils.ts +848 -0
- package/node_modules/@noble/hashes/src/webcrypto.ts +239 -0
- package/node_modules/@noble/hashes/utils.d.ts +519 -0
- package/node_modules/@noble/hashes/utils.d.ts.map +1 -0
- package/node_modules/@noble/hashes/utils.js +578 -0
- package/node_modules/@noble/hashes/utils.js.map +1 -0
- package/node_modules/@noble/hashes/webcrypto.d.ts +120 -0
- package/node_modules/@noble/hashes/webcrypto.d.ts.map +1 -0
- package/node_modules/@noble/hashes/webcrypto.js +165 -0
- package/node_modules/@noble/hashes/webcrypto.js.map +1 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +743 -0
- package/node_modules/ws/lib/sender.js +607 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1407 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +53 -0
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA3 (keccak) addons.
|
|
3
|
+
*
|
|
4
|
+
* * cSHAKE, KMAC, TupleHash, ParallelHash + XOF variants from
|
|
5
|
+
* {@link https://csrc.nist.gov/pubs/sp/800/185/final | NIST SP 800-185}
|
|
6
|
+
* * KangarooTwelve 🦘 and TurboSHAKE - reduced-round keccak from
|
|
7
|
+
* {@link https://datatracker.ietf.org/doc/rfc9861/ | RFC 9861}
|
|
8
|
+
* * KeccakPRG: Pseudo-random generator based on Keccak
|
|
9
|
+
* ({@link https://keccak.team/files/CSF-0.1.pdf | pdf})
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { Keccak, type ShakeOpts } from './sha3.ts';
|
|
13
|
+
import {
|
|
14
|
+
abytes,
|
|
15
|
+
aexists,
|
|
16
|
+
anumber,
|
|
17
|
+
type CHash,
|
|
18
|
+
type CHashXOF,
|
|
19
|
+
clean,
|
|
20
|
+
copyBytes,
|
|
21
|
+
createHasher,
|
|
22
|
+
type Hash,
|
|
23
|
+
type HashXOF,
|
|
24
|
+
type KDFInput,
|
|
25
|
+
kdfInputToBytes,
|
|
26
|
+
type PRG,
|
|
27
|
+
type TArg,
|
|
28
|
+
type TRet,
|
|
29
|
+
u32,
|
|
30
|
+
} from './utils.ts';
|
|
31
|
+
|
|
32
|
+
// cSHAKE && KMAC (NIST SP800-185)
|
|
33
|
+
const _8n = /* @__PURE__ */ BigInt(8);
|
|
34
|
+
const _ffn = /* @__PURE__ */ BigInt(0xff);
|
|
35
|
+
|
|
36
|
+
// It is safe to use bigints here, since they used only for length encoding (not actual data).
|
|
37
|
+
// We use bigints in sha256 for lengths too.
|
|
38
|
+
// Callers are still expected to supply SP 800-185-valid lengths
|
|
39
|
+
// (`0 <= x < 2^2040`); this helper does not enforce that bound.
|
|
40
|
+
function leftEncode(n: number | bigint): TRet<Uint8Array> {
|
|
41
|
+
n = BigInt(n);
|
|
42
|
+
const res = [Number(n & _ffn)];
|
|
43
|
+
n >>= _8n;
|
|
44
|
+
for (; n > 0; n >>= _8n) res.unshift(Number(n & _ffn));
|
|
45
|
+
res.unshift(res.length);
|
|
46
|
+
return new Uint8Array(res) as TRet<Uint8Array>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Same caller contract as `leftEncode(...)`: lengths must already satisfy SP 800-185 §2.3.1.
|
|
50
|
+
function rightEncode(n: number | bigint): TRet<Uint8Array> {
|
|
51
|
+
n = BigInt(n);
|
|
52
|
+
const res = [Number(n & _ffn)];
|
|
53
|
+
n >>= _8n;
|
|
54
|
+
for (; n > 0; n >>= _8n) res.unshift(Number(n & _ffn));
|
|
55
|
+
res.push(res.length);
|
|
56
|
+
return new Uint8Array(res) as TRet<Uint8Array>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// `dkLen` validation is deferred to the downstream Keccak constructor.
|
|
60
|
+
function chooseLen(opts: ShakeOpts, outputLen: number): number {
|
|
61
|
+
return opts.dkLen === undefined ? outputLen : opts.dkLen;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const abytesOrZero = (buf?: TArg<Uint8Array>, title = '') => {
|
|
65
|
+
if (buf === undefined) return EMPTY_BUFFER;
|
|
66
|
+
abytes(buf, undefined, title);
|
|
67
|
+
return buf;
|
|
68
|
+
};
|
|
69
|
+
// NOTE: second modulo is necessary since we don't need to add padding if the
|
|
70
|
+
// current element takes a whole block.
|
|
71
|
+
// Callers only pass the fixed positive Keccak rates here (`168` or `136`);
|
|
72
|
+
// `block <= 0` is not validated locally.
|
|
73
|
+
const getPadding = (len: number, block: number) => new Uint8Array((block - (len % block)) % block);
|
|
74
|
+
/** Options for cSHAKE and related SP 800-185 functions. */
|
|
75
|
+
export type cShakeOpts = ShakeOpts & {
|
|
76
|
+
/** Optional personalization string mixed into domain separation. */
|
|
77
|
+
personalization?: Uint8Array;
|
|
78
|
+
/**
|
|
79
|
+
* Optional NIST function-name string used for domain separation.
|
|
80
|
+
* SP 800-185 reserves this for standardized function names; applications
|
|
81
|
+
* should generally stick to `personalization`.
|
|
82
|
+
*/
|
|
83
|
+
NISTfn?: KDFInput;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Personalization
|
|
87
|
+
function cshakePers(hash: TArg<Keccak>, opts: TArg<cShakeOpts> = {}): TRet<Keccak> {
|
|
88
|
+
const h = hash as unknown as Keccak;
|
|
89
|
+
if (!opts || (opts.personalization === undefined && opts.NISTfn === undefined))
|
|
90
|
+
return h as TRet<Keccak>;
|
|
91
|
+
// Encode and pad inplace to avoid unneccesary memory copies/slices so we
|
|
92
|
+
// don't need to zero them later.
|
|
93
|
+
// bytepad(encode_string(N) || encode_string(S), rate), where `rate` is the
|
|
94
|
+
// current cSHAKE/KMAC/TupleHash/ParallelHash block length.
|
|
95
|
+
const blockLenBytes = leftEncode(h.blockLen);
|
|
96
|
+
const fn = opts.NISTfn === undefined ? EMPTY_BUFFER : kdfInputToBytes(opts.NISTfn);
|
|
97
|
+
const fnLen = leftEncode(_8n * BigInt(fn.length)); // length in bits
|
|
98
|
+
const pers = abytesOrZero(opts.personalization, 'personalization');
|
|
99
|
+
const persLen = leftEncode(_8n * BigInt(pers.length)); // length in bits
|
|
100
|
+
if (!fn.length && !pers.length) return h as TRet<Keccak>;
|
|
101
|
+
// SP 800-185 cSHAKE appends `00` instead of SHAKE's `1111`; in this Keccak implementation
|
|
102
|
+
// that changes the delimited suffix byte from `0x1f` to `0x04` once N or S is non-empty.
|
|
103
|
+
h.suffix = 0x04;
|
|
104
|
+
h.update(blockLenBytes).update(fnLen).update(fn).update(persLen).update(pers);
|
|
105
|
+
let totalLen = blockLenBytes.length + fnLen.length + fn.length + persLen.length + pers.length;
|
|
106
|
+
h.update(getPadding(totalLen, h.blockLen));
|
|
107
|
+
return h as TRet<Keccak>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const gencShake = (
|
|
111
|
+
suffix: number,
|
|
112
|
+
blockLen: number,
|
|
113
|
+
outputLen: number
|
|
114
|
+
): TRet<CHashXOF<Keccak, cShakeOpts>> =>
|
|
115
|
+
createHasher<Keccak, cShakeOpts>(
|
|
116
|
+
(opts: TArg<cShakeOpts> = {}) =>
|
|
117
|
+
cshakePers(
|
|
118
|
+
new Keccak(blockLen, suffix, chooseLen(opts, outputLen), true) as unknown as TArg<Keccak>,
|
|
119
|
+
opts
|
|
120
|
+
) as Keccak
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
/** TupleHash callable interface. */
|
|
124
|
+
export type ITupleHash = {
|
|
125
|
+
/**
|
|
126
|
+
* Hashes an ordered tuple of byte arrays.
|
|
127
|
+
* @param messages - Ordered byte-array tuple to hash.
|
|
128
|
+
* @param opts - TupleHash output and personalization options. See {@link cShakeOpts}.
|
|
129
|
+
* @returns Digest bytes.
|
|
130
|
+
*/
|
|
131
|
+
(messages: TArg<Uint8Array[]>, opts?: TArg<cShakeOpts>): TRet<Uint8Array>;
|
|
132
|
+
/**
|
|
133
|
+
* Creates an incremental TupleHash state.
|
|
134
|
+
* @param opts - TupleHash output and personalization options. See {@link cShakeOpts}.
|
|
135
|
+
* @returns Stateful TupleHash instance.
|
|
136
|
+
*/
|
|
137
|
+
create(opts?: cShakeOpts): _TupleHash;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* 128-bit NIST cSHAKE XOF.
|
|
141
|
+
* @param msg - message bytes to hash
|
|
142
|
+
* @param opts - Optional output, personalization, and NIST function-name
|
|
143
|
+
* settings. When both `NISTfn` and `personalization` are empty,
|
|
144
|
+
* SP 800-185 defines this as plain SHAKE128. Defaults to 16 output bytes
|
|
145
|
+
* when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
146
|
+
* @returns Digest bytes.
|
|
147
|
+
* @example
|
|
148
|
+
* Hash a message with cSHAKE128.
|
|
149
|
+
* ```ts
|
|
150
|
+
* cshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export const cshake128: TRet<CHashXOF<Keccak, cShakeOpts>> = /* @__PURE__ */ gencShake(
|
|
154
|
+
0x1f,
|
|
155
|
+
168,
|
|
156
|
+
16
|
|
157
|
+
);
|
|
158
|
+
/**
|
|
159
|
+
* 256-bit NIST cSHAKE XOF.
|
|
160
|
+
* @param msg - message bytes to hash
|
|
161
|
+
* @param opts - Optional output, personalization, and NIST function-name
|
|
162
|
+
* settings. When both `NISTfn` and `personalization` are empty,
|
|
163
|
+
* SP 800-185 defines this as plain SHAKE256. Defaults to 32 output bytes
|
|
164
|
+
* when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
165
|
+
* @returns Digest bytes.
|
|
166
|
+
* @example
|
|
167
|
+
* Hash a message with cSHAKE256.
|
|
168
|
+
* ```ts
|
|
169
|
+
* cshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export const cshake256: TRet<CHashXOF<Keccak, cShakeOpts>> = /* @__PURE__ */ gencShake(
|
|
173
|
+
0x1f,
|
|
174
|
+
136,
|
|
175
|
+
32
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Internal KMAC class.
|
|
180
|
+
* SP 800-185 §8.4.1 still recommends keys at least as long as the target
|
|
181
|
+
* security strength.
|
|
182
|
+
*/
|
|
183
|
+
export class _KMAC extends Keccak implements HashXOF<_KMAC> {
|
|
184
|
+
constructor(
|
|
185
|
+
blockLen: number,
|
|
186
|
+
outputLen: number,
|
|
187
|
+
enableXOF: boolean,
|
|
188
|
+
key: TArg<Uint8Array>,
|
|
189
|
+
opts: TArg<cShakeOpts> = {}
|
|
190
|
+
) {
|
|
191
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
192
|
+
// Preload T = bytepad(encode_string("KMAC") || encode_string(S), rate); later updates append
|
|
193
|
+
// newX = bytepad(encode_string(K), rate) || X and `finish()` appends right_encode(L or 0).
|
|
194
|
+
cshakePers(this as unknown as TArg<Keccak>, {
|
|
195
|
+
NISTfn: 'KMAC',
|
|
196
|
+
personalization: opts.personalization,
|
|
197
|
+
});
|
|
198
|
+
abytes(key, undefined, 'key');
|
|
199
|
+
// 1. newX = bytepad(encode_string(K), rate) || X || right_encode(L),
|
|
200
|
+
// with `rate = this.blockLen`.
|
|
201
|
+
const blockLenBytes = leftEncode(this.blockLen);
|
|
202
|
+
const keyLen = leftEncode(_8n * BigInt(key.length));
|
|
203
|
+
this.update(blockLenBytes).update(keyLen).update(key);
|
|
204
|
+
const totalLen = blockLenBytes.length + keyLen.length + key.length;
|
|
205
|
+
this.update(getPadding(totalLen, this.blockLen));
|
|
206
|
+
}
|
|
207
|
+
protected finish(): void {
|
|
208
|
+
// SP 800-185 uses right_encode(L) for fixed-length KMAC and right_encode(0) for KMACXOF.
|
|
209
|
+
// outputLen in bits
|
|
210
|
+
if (!this.finished) this.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
211
|
+
super.finish();
|
|
212
|
+
}
|
|
213
|
+
_cloneInto(to?: _KMAC): _KMAC {
|
|
214
|
+
// Create new instance without calling constructor since the key
|
|
215
|
+
// is already in state and we don't know it.
|
|
216
|
+
// Force "to" to be instance of KMAC instead of Sha3.
|
|
217
|
+
if (!to) {
|
|
218
|
+
to = Object.create(Object.getPrototypeOf(this), {}) as _KMAC;
|
|
219
|
+
to.state = this.state.slice();
|
|
220
|
+
to.blockLen = this.blockLen;
|
|
221
|
+
to.state32 = u32(to.state);
|
|
222
|
+
}
|
|
223
|
+
return super._cloneInto(to) as _KMAC;
|
|
224
|
+
}
|
|
225
|
+
clone(): _KMAC {
|
|
226
|
+
return this._cloneInto();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function genKmac(blockLen: number, outputLen: number, xof = false): TRet<IKMAC> {
|
|
231
|
+
// One-shot XOF wrappers still finalize via `.digest()` because `_KMAC`
|
|
232
|
+
// already bakes the requested output length into the state.
|
|
233
|
+
const kmac = (
|
|
234
|
+
key: TArg<Uint8Array>,
|
|
235
|
+
message: TArg<Uint8Array>,
|
|
236
|
+
opts?: TArg<cShakeOpts>
|
|
237
|
+
): TRet<Uint8Array> => kmac.create(key, opts).update(message).digest();
|
|
238
|
+
kmac.create = (key: TArg<Uint8Array>, opts: TArg<cShakeOpts> = {}) =>
|
|
239
|
+
new _KMAC(blockLen, chooseLen(opts, outputLen), xof, key, opts);
|
|
240
|
+
return kmac as TRet<IKMAC>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** KMAC callable interface. */
|
|
244
|
+
export type IKMAC = {
|
|
245
|
+
/**
|
|
246
|
+
* Computes a keyed KMAC digest for one message.
|
|
247
|
+
* @param key - Secret key bytes.
|
|
248
|
+
* @param message - Message bytes to authenticate.
|
|
249
|
+
* @param opts - KMAC output and personalization options. See {@link KangarooOpts}.
|
|
250
|
+
* @returns Authentication tag bytes.
|
|
251
|
+
*/
|
|
252
|
+
(key: TArg<Uint8Array>, message: TArg<Uint8Array>, opts?: TArg<KangarooOpts>): TRet<Uint8Array>;
|
|
253
|
+
/**
|
|
254
|
+
* Creates an incremental KMAC state.
|
|
255
|
+
* @param key - Secret key bytes.
|
|
256
|
+
* @param opts - KMAC output and personalization options. See {@link cShakeOpts}.
|
|
257
|
+
* @returns Stateful KMAC instance.
|
|
258
|
+
*/
|
|
259
|
+
create(key: TArg<Uint8Array>, opts?: TArg<cShakeOpts>): _KMAC;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* 128-bit Keccak MAC.
|
|
263
|
+
* @param key - MAC key bytes
|
|
264
|
+
* @param message - message bytes to authenticate
|
|
265
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
266
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
267
|
+
* @returns Authentication tag bytes.
|
|
268
|
+
* @example
|
|
269
|
+
* Authenticate a message with KMAC128.
|
|
270
|
+
* ```ts
|
|
271
|
+
* kmac128(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export const kmac128: TRet<IKMAC> = /* @__PURE__ */ genKmac(168, 16);
|
|
275
|
+
/**
|
|
276
|
+
* 256-bit Keccak MAC.
|
|
277
|
+
* @param key - MAC key bytes
|
|
278
|
+
* @param message - message bytes to authenticate
|
|
279
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
280
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
281
|
+
* @returns Authentication tag bytes.
|
|
282
|
+
* @example
|
|
283
|
+
* Authenticate a message with KMAC256.
|
|
284
|
+
* ```ts
|
|
285
|
+
* kmac256(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
export const kmac256: TRet<IKMAC> = /* @__PURE__ */ genKmac(136, 32);
|
|
289
|
+
/**
|
|
290
|
+
* 128-bit Keccak-MAC XOF.
|
|
291
|
+
* @param key - MAC key bytes
|
|
292
|
+
* @param message - message bytes to authenticate
|
|
293
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
294
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
295
|
+
* @returns Authentication tag bytes.
|
|
296
|
+
* @example
|
|
297
|
+
* Authenticate a message with KMAC128 XOF output.
|
|
298
|
+
* ```ts
|
|
299
|
+
* kmac128xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 32 });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
export const kmac128xof: TRet<IKMAC> = /* @__PURE__ */ genKmac(168, 16, true);
|
|
303
|
+
/**
|
|
304
|
+
* 256-bit Keccak-MAC XOF.
|
|
305
|
+
* @param key - MAC key bytes
|
|
306
|
+
* @param message - message bytes to authenticate
|
|
307
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
308
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
309
|
+
* @returns Authentication tag bytes.
|
|
310
|
+
* @example
|
|
311
|
+
* Authenticate a message with KMAC256 XOF output.
|
|
312
|
+
* ```ts
|
|
313
|
+
* kmac256xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 64 });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
export const kmac256xof: TRet<IKMAC> = /* @__PURE__ */ genKmac(136, 32, true);
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Internal TupleHash class for byte-array tuple elements.
|
|
320
|
+
* This implementation relies on SP 800-185's byte-oriented encoding form
|
|
321
|
+
* rather than arbitrary bit strings.
|
|
322
|
+
*/
|
|
323
|
+
export class _TupleHash extends Keccak implements HashXOF<_TupleHash> {
|
|
324
|
+
constructor(
|
|
325
|
+
blockLen: number,
|
|
326
|
+
outputLen: number,
|
|
327
|
+
enableXOF: boolean,
|
|
328
|
+
opts: TArg<cShakeOpts> = {}
|
|
329
|
+
) {
|
|
330
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
331
|
+
cshakePers(this as unknown as TArg<Keccak>, {
|
|
332
|
+
NISTfn: 'TupleHash',
|
|
333
|
+
personalization: opts.personalization,
|
|
334
|
+
});
|
|
335
|
+
// Change update after cshake processed
|
|
336
|
+
this.update = (data: TArg<Uint8Array>) => {
|
|
337
|
+
abytes(data);
|
|
338
|
+
// SP 800-185 encodes each tuple element as
|
|
339
|
+
// encode_string(X[i]) = left_encode(len(X[i])) || X[i].
|
|
340
|
+
super.update(leftEncode(_8n * BigInt(data.length)));
|
|
341
|
+
super.update(data);
|
|
342
|
+
return this;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
protected finish(): void {
|
|
346
|
+
// SP 800-185 uses right_encode(L) for fixed-length TupleHash
|
|
347
|
+
// and right_encode(0) for TupleHashXOF.
|
|
348
|
+
if (!this.finished)
|
|
349
|
+
// outputLen in bits
|
|
350
|
+
super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
351
|
+
super.finish();
|
|
352
|
+
}
|
|
353
|
+
_cloneInto(to?: _TupleHash): _TupleHash {
|
|
354
|
+
to ||= new _TupleHash(this.blockLen, this.outputLen, this.enableXOF);
|
|
355
|
+
return super._cloneInto(to) as _TupleHash;
|
|
356
|
+
}
|
|
357
|
+
clone(): _TupleHash {
|
|
358
|
+
return this._cloneInto();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function genTuple(blockLen: number, outputLen: number, xof = false): TRet<ITupleHash> {
|
|
363
|
+
// One-shot XOF wrappers still use `.digest()` because `_TupleHash` stores
|
|
364
|
+
// the requested output length in the state itself.
|
|
365
|
+
const tuple = (messages: TArg<Uint8Array[]>, opts?: TArg<cShakeOpts>): TRet<Uint8Array> => {
|
|
366
|
+
const h = tuple.create(opts);
|
|
367
|
+
if (!Array.isArray(messages)) throw new Error('expected array of messages');
|
|
368
|
+
for (const msg of messages) h.update(msg);
|
|
369
|
+
return h.digest();
|
|
370
|
+
};
|
|
371
|
+
tuple.create = (opts: TArg<cShakeOpts> = {}) =>
|
|
372
|
+
new _TupleHash(blockLen, chooseLen(opts, outputLen), xof, opts);
|
|
373
|
+
return tuple as TRet<ITupleHash>;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 128-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
|
|
378
|
+
* @param messages - ordered byte-array tuple
|
|
379
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
380
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
381
|
+
* @returns Digest bytes.
|
|
382
|
+
* @example
|
|
383
|
+
* Hash a tuple of byte arrays with TupleHash128.
|
|
384
|
+
* ```ts
|
|
385
|
+
* tuplehash128([new Uint8Array([1]), new Uint8Array([2])]);
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export const tuplehash128: TRet<ITupleHash> = /* @__PURE__ */ genTuple(168, 16);
|
|
389
|
+
/**
|
|
390
|
+
* 256-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
|
|
391
|
+
* @param messages - ordered byte-array tuple
|
|
392
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
393
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
394
|
+
* @returns Digest bytes.
|
|
395
|
+
* @example
|
|
396
|
+
* Hash a tuple of byte arrays with TupleHash256.
|
|
397
|
+
* ```ts
|
|
398
|
+
* tuplehash256([new Uint8Array([1]), new Uint8Array([2])]);
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
export const tuplehash256: TRet<ITupleHash> = /* @__PURE__ */ genTuple(136, 32);
|
|
402
|
+
/**
|
|
403
|
+
* 128-bit TupleHASH XOF.
|
|
404
|
+
* @param messages - ordered byte-array tuple
|
|
405
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
406
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
407
|
+
* @returns Digest bytes.
|
|
408
|
+
* @example
|
|
409
|
+
* Hash a tuple of byte arrays with TupleHash128 XOF output.
|
|
410
|
+
* ```ts
|
|
411
|
+
* tuplehash128xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 32 });
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
export const tuplehash128xof: TRet<ITupleHash> = /* @__PURE__ */ genTuple(168, 16, true);
|
|
415
|
+
/**
|
|
416
|
+
* 256-bit TupleHASH XOF.
|
|
417
|
+
* @param messages - ordered byte-array tuple
|
|
418
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
419
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
420
|
+
* @returns Digest bytes.
|
|
421
|
+
* @example
|
|
422
|
+
* Hash a tuple of byte arrays with TupleHash256 XOF output.
|
|
423
|
+
* ```ts
|
|
424
|
+
* tuplehash256xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 64 });
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
export const tuplehash256xof: TRet<ITupleHash> = /* @__PURE__ */ genTuple(136, 32, true);
|
|
428
|
+
|
|
429
|
+
// Same as K12/M14, but without speedup for inputs less 8kb,
|
|
430
|
+
// reduced number of rounds and simpler.
|
|
431
|
+
type ParallelOpts = KangarooOpts & { blockLen?: number };
|
|
432
|
+
|
|
433
|
+
/** Internal Parallel Keccak Hash class. */
|
|
434
|
+
export class _ParallelHash extends Keccak implements HashXOF<_ParallelHash> {
|
|
435
|
+
private leafHash?: Hash<Keccak>;
|
|
436
|
+
protected leafCons: () => Hash<Keccak>;
|
|
437
|
+
private chunkPos = 0; // Position of current block in chunk
|
|
438
|
+
private chunksDone = 0; // How many chunks we already have
|
|
439
|
+
private chunkLen: number;
|
|
440
|
+
constructor(
|
|
441
|
+
blockLen: number,
|
|
442
|
+
outputLen: number,
|
|
443
|
+
leafCons: () => Hash<Keccak>,
|
|
444
|
+
enableXOF: boolean,
|
|
445
|
+
opts: TArg<ParallelOpts> = {}
|
|
446
|
+
) {
|
|
447
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
448
|
+
cshakePers(this as unknown as TArg<Keccak>, {
|
|
449
|
+
NISTfn: 'ParallelHash',
|
|
450
|
+
personalization: opts.personalization,
|
|
451
|
+
});
|
|
452
|
+
this.leafCons = leafCons;
|
|
453
|
+
let { blockLen: B = 8 } = opts;
|
|
454
|
+
anumber(B);
|
|
455
|
+
// blockLen=0 makes take=0 in update(), so pos never advances and the hash hangs.
|
|
456
|
+
if (B < 1) throw new Error('"blockLen" must be >= 1, got ' + B);
|
|
457
|
+
this.chunkLen = B;
|
|
458
|
+
// SP 800-185 initializes z = left_encode(B); each completed chunk appends
|
|
459
|
+
// one fixed-size cSHAKE leaf digest before finish() adds right_encode(n)
|
|
460
|
+
// and right_encode(L or 0).
|
|
461
|
+
super.update(leftEncode(B));
|
|
462
|
+
// Change update after cshake processed
|
|
463
|
+
this.update = (data: TArg<Uint8Array>) => {
|
|
464
|
+
abytes(data);
|
|
465
|
+
const { chunkLen, leafCons } = this;
|
|
466
|
+
for (let pos = 0, len = data.length; pos < len; ) {
|
|
467
|
+
if (this.chunkPos == chunkLen || !this.leafHash) {
|
|
468
|
+
if (this.leafHash) {
|
|
469
|
+
super.update(this.leafHash.digest());
|
|
470
|
+
this.chunksDone++;
|
|
471
|
+
}
|
|
472
|
+
this.leafHash = leafCons();
|
|
473
|
+
this.chunkPos = 0;
|
|
474
|
+
}
|
|
475
|
+
const take = Math.min(chunkLen - this.chunkPos, len - pos);
|
|
476
|
+
this.leafHash.update(data.subarray(pos, pos + take));
|
|
477
|
+
this.chunkPos += take;
|
|
478
|
+
pos += take;
|
|
479
|
+
}
|
|
480
|
+
return this;
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
protected finish(): void {
|
|
484
|
+
if (this.finished) return;
|
|
485
|
+
if (this.leafHash) {
|
|
486
|
+
super.update(this.leafHash.digest());
|
|
487
|
+
this.chunksDone++;
|
|
488
|
+
}
|
|
489
|
+
// SP 800-185 finishes ParallelHash as
|
|
490
|
+
// z || right_encode(n) || right_encode(L); XOF mode replaces
|
|
491
|
+
// right_encode(L) with right_encode(0).
|
|
492
|
+
super.update(rightEncode(this.chunksDone));
|
|
493
|
+
// outputLen in bits
|
|
494
|
+
super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
495
|
+
super.finish();
|
|
496
|
+
}
|
|
497
|
+
_cloneInto(to?: _ParallelHash): _ParallelHash {
|
|
498
|
+
to ||= new _ParallelHash(this.blockLen, this.outputLen, this.leafCons, this.enableXOF);
|
|
499
|
+
to.leafCons = this.leafCons;
|
|
500
|
+
// Reused destinations can carry a stale partial leaf
|
|
501
|
+
// when the source is still on the root sponge.
|
|
502
|
+
if (this.leafHash) to.leafHash = this.leafHash._cloneInto(to.leafHash as Keccak);
|
|
503
|
+
else if (to.leafHash) {
|
|
504
|
+
to.leafHash.destroy();
|
|
505
|
+
to.leafHash = undefined;
|
|
506
|
+
}
|
|
507
|
+
to.chunkPos = this.chunkPos;
|
|
508
|
+
to.chunkLen = this.chunkLen;
|
|
509
|
+
to.chunksDone = this.chunksDone;
|
|
510
|
+
return super._cloneInto(to) as _ParallelHash;
|
|
511
|
+
}
|
|
512
|
+
destroy(): void {
|
|
513
|
+
super.destroy.call(this);
|
|
514
|
+
if (this.leafHash) this.leafHash.destroy();
|
|
515
|
+
}
|
|
516
|
+
clone(): _ParallelHash {
|
|
517
|
+
return this._cloneInto();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function genPrl(
|
|
522
|
+
blockLen: number,
|
|
523
|
+
outputLen: number,
|
|
524
|
+
leaf: ReturnType<typeof gencShake>,
|
|
525
|
+
xof = false
|
|
526
|
+
): TRet<CHashXOF<Keccak, ParallelOpts>> {
|
|
527
|
+
const parallel = (message: TArg<Uint8Array>, opts?: TArg<ParallelOpts>): TRet<Uint8Array> =>
|
|
528
|
+
parallel.create(opts).update(message).digest();
|
|
529
|
+
parallel.create = (opts: TArg<ParallelOpts> = {}) =>
|
|
530
|
+
new _ParallelHash(
|
|
531
|
+
blockLen,
|
|
532
|
+
chooseLen(opts, outputLen),
|
|
533
|
+
// SP 800-185 fixes leaf digests at 256 bits for ParallelHash128 and
|
|
534
|
+
// 512 bits for ParallelHash256; only the final cSHAKE output uses the
|
|
535
|
+
// caller-selected dkLen.
|
|
536
|
+
() => leaf.create({ dkLen: 2 * outputLen }),
|
|
537
|
+
xof,
|
|
538
|
+
opts
|
|
539
|
+
);
|
|
540
|
+
parallel.outputLen = outputLen;
|
|
541
|
+
parallel.blockLen = blockLen;
|
|
542
|
+
parallel.canXOF = xof;
|
|
543
|
+
return parallel as TRet<CHashXOF<Keccak, ParallelOpts>>;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* 128-bit ParallelHash. In JS, it is not parallel.
|
|
548
|
+
* @param msg - message bytes to hash
|
|
549
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
550
|
+
* Defaults to 16 output bytes when `dkLen` is omitted.
|
|
551
|
+
* See {@link ParallelOpts}.
|
|
552
|
+
* @returns Digest bytes.
|
|
553
|
+
* @example
|
|
554
|
+
* Hash a message with ParallelHash128.
|
|
555
|
+
* ```ts
|
|
556
|
+
* parallelhash128(new Uint8Array([1, 2, 3]));
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
export const parallelhash128: TRet<CHash<Keccak, ParallelOpts>> = /* @__PURE__ */ genPrl(
|
|
560
|
+
168,
|
|
561
|
+
16,
|
|
562
|
+
cshake128
|
|
563
|
+
);
|
|
564
|
+
/**
|
|
565
|
+
* 256-bit ParallelHash. In JS, it is not parallel.
|
|
566
|
+
* @param msg - message bytes to hash
|
|
567
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
568
|
+
* Defaults to 32 output bytes when `dkLen` is omitted.
|
|
569
|
+
* See {@link ParallelOpts}.
|
|
570
|
+
* @returns Digest bytes.
|
|
571
|
+
* @example
|
|
572
|
+
* Hash a message with ParallelHash256.
|
|
573
|
+
* ```ts
|
|
574
|
+
* parallelhash256(new Uint8Array([1, 2, 3]));
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
export const parallelhash256: TRet<CHash<Keccak, ParallelOpts>> = /* @__PURE__ */ genPrl(
|
|
578
|
+
136,
|
|
579
|
+
32,
|
|
580
|
+
cshake256
|
|
581
|
+
);
|
|
582
|
+
/**
|
|
583
|
+
* 128-bit ParallelHash XOF. In JS, it is not parallel.
|
|
584
|
+
* @param msg - message bytes to hash
|
|
585
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
586
|
+
* Defaults to 16 output bytes when `dkLen` is omitted.
|
|
587
|
+
* See {@link ParallelOpts}.
|
|
588
|
+
* @returns Digest bytes.
|
|
589
|
+
* @example
|
|
590
|
+
* Hash a message with ParallelHash128 XOF output.
|
|
591
|
+
* ```ts
|
|
592
|
+
* parallelhash128xof(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
export const parallelhash128xof: TRet<CHashXOF<Keccak, ParallelOpts>> = /* @__PURE__ */ genPrl(
|
|
596
|
+
168,
|
|
597
|
+
16,
|
|
598
|
+
cshake128,
|
|
599
|
+
true
|
|
600
|
+
);
|
|
601
|
+
/**
|
|
602
|
+
* 256-bit ParallelHash XOF. In JS, it is not parallel.
|
|
603
|
+
* @param msg - message bytes to hash
|
|
604
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
605
|
+
* Defaults to 32 output bytes when `dkLen` is omitted.
|
|
606
|
+
* See {@link ParallelOpts}.
|
|
607
|
+
* @returns Digest bytes.
|
|
608
|
+
* @example
|
|
609
|
+
* Hash a message with ParallelHash256 XOF output.
|
|
610
|
+
* ```ts
|
|
611
|
+
* parallelhash256xof(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
export const parallelhash256xof: TRet<CHashXOF<Keccak, ParallelOpts>> = /* @__PURE__ */ genPrl(
|
|
615
|
+
136,
|
|
616
|
+
32,
|
|
617
|
+
cshake256,
|
|
618
|
+
true
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* TurboSHAKE options.
|
|
623
|
+
* `D` is the domain separation byte; RFC 9861 defines output length `L`
|
|
624
|
+
* as a positive integer.
|
|
625
|
+
*/
|
|
626
|
+
export type TurboshakeOpts = ShakeOpts & {
|
|
627
|
+
/** Optional domain separation byte in the `0x01..0x7f` range. */
|
|
628
|
+
D?: number;
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
const genTurbo = (blockLen: number, outputLen: number) =>
|
|
632
|
+
createHasher<Keccak, TurboshakeOpts>((opts: TArg<TurboshakeOpts> = {}) => {
|
|
633
|
+
const D = opts.D === undefined ? 0x1f : opts.D;
|
|
634
|
+
// RFC 9861 §2.1 fixes the default `D = 0x1f`; §2.2 defines the 12-round
|
|
635
|
+
// TurboSHAKE family selected here.
|
|
636
|
+
if (!Number.isSafeInteger(D) || D < 0x01 || D > 0x7f)
|
|
637
|
+
throw new Error('"D" (domain separation byte) must be 0x01..0x7f, got: ' + D);
|
|
638
|
+
const dkLen = opts.dkLen === undefined ? outputLen : opts.dkLen;
|
|
639
|
+
// RFC 9861 §§2.1-2.2 define output length L as a positive integer.
|
|
640
|
+
if (dkLen < 1) throw new Error('"dkLen" must be >= 1');
|
|
641
|
+
return new Keccak(blockLen, D, dkLen, true, 12);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* TurboSHAKE 128-bit: reduced 12-round keccak.
|
|
646
|
+
* Should've been a simple "shake with 12 rounds", but we got a whole new
|
|
647
|
+
* spec about Turbo SHAKE Pro MAX.
|
|
648
|
+
* @param msg - message bytes to hash
|
|
649
|
+
* @param opts - Optional output-length and domain-separation settings.
|
|
650
|
+
* RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 32 output bytes when
|
|
651
|
+
* `dkLen` is omitted. See {@link TurboshakeOpts}.
|
|
652
|
+
* @returns Digest bytes.
|
|
653
|
+
* @example
|
|
654
|
+
* Hash a message with TurboSHAKE128.
|
|
655
|
+
* ```ts
|
|
656
|
+
* turboshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
657
|
+
* ```
|
|
658
|
+
*/
|
|
659
|
+
export const turboshake128: TRet<CHashXOF<Keccak, TurboshakeOpts>> = /* @__PURE__ */ genTurbo(
|
|
660
|
+
168,
|
|
661
|
+
32
|
|
662
|
+
);
|
|
663
|
+
/**
|
|
664
|
+
* TurboSHAKE 256-bit: reduced 12-round keccak.
|
|
665
|
+
* @param msg - message bytes to hash
|
|
666
|
+
* @param opts - Optional output-length and domain-separation settings.
|
|
667
|
+
* RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 64 output bytes when
|
|
668
|
+
* `dkLen` is omitted. See {@link TurboshakeOpts}.
|
|
669
|
+
* @returns Digest bytes.
|
|
670
|
+
* @example
|
|
671
|
+
* Hash a message with TurboSHAKE256.
|
|
672
|
+
* ```ts
|
|
673
|
+
* turboshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
export const turboshake256: TRet<CHashXOF<Keccak, TurboshakeOpts>> = /* @__PURE__ */ genTurbo(
|
|
677
|
+
136,
|
|
678
|
+
64
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
// Same as NIST rightEncode, but returns `[0]` for the zero string.
|
|
682
|
+
// Callers still need to keep `x < 256^255` per RFC 9861 §3.3.
|
|
683
|
+
function rightEncodeK12(n: number | bigint): TRet<Uint8Array> {
|
|
684
|
+
n = BigInt(n);
|
|
685
|
+
const res: number[] = [];
|
|
686
|
+
for (; n > 0; n >>= _8n) res.unshift(Number(n & _ffn));
|
|
687
|
+
res.push(res.length);
|
|
688
|
+
return Uint8Array.from(res);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** K12 options. */
|
|
692
|
+
export type KangarooOpts = {
|
|
693
|
+
/**
|
|
694
|
+
* Desired digest length in bytes.
|
|
695
|
+
* RFC 9861 §3 defines output length `L` as a positive integer.
|
|
696
|
+
*/
|
|
697
|
+
dkLen?: number;
|
|
698
|
+
/**
|
|
699
|
+
* Optional personalization string mixed into the sponge state.
|
|
700
|
+
* Stateful K12 instances keep an internal copy so caller buffers can be
|
|
701
|
+
* wiped independently.
|
|
702
|
+
*/
|
|
703
|
+
personalization?: Uint8Array;
|
|
704
|
+
};
|
|
705
|
+
const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
706
|
+
|
|
707
|
+
/** Internal K12 hash class. */
|
|
708
|
+
export class _KangarooTwelve extends Keccak implements HashXOF<_KangarooTwelve> {
|
|
709
|
+
readonly chunkLen = 8192;
|
|
710
|
+
private leafHash?: Keccak;
|
|
711
|
+
protected leafLen: number;
|
|
712
|
+
private personalization: Uint8Array;
|
|
713
|
+
private chunkPos = 0; // Position of current block in chunk
|
|
714
|
+
private chunksDone = 0; // How many chunks we already have
|
|
715
|
+
constructor(
|
|
716
|
+
blockLen: number,
|
|
717
|
+
leafLen: number,
|
|
718
|
+
outputLen: number,
|
|
719
|
+
rounds: number,
|
|
720
|
+
opts: TArg<KangarooOpts>
|
|
721
|
+
) {
|
|
722
|
+
super(blockLen, 0x07, outputLen, true, rounds);
|
|
723
|
+
// RFC 9861 §3 defines output length L as a positive integer.
|
|
724
|
+
if (outputLen < 1) throw new Error('"dkLen" must be >= 1');
|
|
725
|
+
this.leafLen = leafLen;
|
|
726
|
+
this.personalization =
|
|
727
|
+
opts.personalization === undefined
|
|
728
|
+
? EMPTY_BUFFER
|
|
729
|
+
: copyBytes(abytes(opts.personalization, undefined, 'personalization'));
|
|
730
|
+
}
|
|
731
|
+
update(data: TArg<Uint8Array>): this {
|
|
732
|
+
abytes(data);
|
|
733
|
+
const { chunkLen, blockLen, leafLen, rounds } = this;
|
|
734
|
+
for (let pos = 0, len = data.length; pos < len; ) {
|
|
735
|
+
if (this.chunkPos == chunkLen) {
|
|
736
|
+
if (this.leafHash) super.update(this.leafHash.digest());
|
|
737
|
+
else {
|
|
738
|
+
// RFC 9861 §3.2 switches from SingleNode (`07`) to FinalNode (`06`)
|
|
739
|
+
// once S exceeds 8192 bytes and prefixes S_0 with
|
|
740
|
+
// `03 00 00 00 00 00 00 00`.
|
|
741
|
+
this.suffix = 0x06; // Its safe to change suffix here since its used only in digest()
|
|
742
|
+
super.update(Uint8Array.from([3, 0, 0, 0, 0, 0, 0, 0]));
|
|
743
|
+
}
|
|
744
|
+
// Secondary chunks S_1..S_(n-1) become fixed-length
|
|
745
|
+
// CV_i = TurboSHAKE*(S_i, `0B`, 32|64) chaining values.
|
|
746
|
+
this.leafHash = new Keccak(blockLen, 0x0b, leafLen, false, rounds);
|
|
747
|
+
this.chunksDone++;
|
|
748
|
+
this.chunkPos = 0;
|
|
749
|
+
}
|
|
750
|
+
const take = Math.min(chunkLen - this.chunkPos, len - pos);
|
|
751
|
+
const chunk = data.subarray(pos, pos + take);
|
|
752
|
+
if (this.leafHash) this.leafHash.update(chunk);
|
|
753
|
+
else super.update(chunk);
|
|
754
|
+
this.chunkPos += take;
|
|
755
|
+
pos += take;
|
|
756
|
+
}
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
protected finish(): void {
|
|
760
|
+
if (this.finished) return;
|
|
761
|
+
const { personalization } = this;
|
|
762
|
+
// RFC 9861 §3.2 forms S = M || C || length_encode(|C|) before any tree hashing logic.
|
|
763
|
+
this.update(personalization).update(rightEncodeK12(personalization.length));
|
|
764
|
+
// Leaf hash
|
|
765
|
+
if (this.leafHash) {
|
|
766
|
+
// Multi-chunk K12 appends
|
|
767
|
+
// CV_1..CV_(n-1) || length_encode(n-1) || `FF FF`
|
|
768
|
+
// before the final TurboSHAKE call.
|
|
769
|
+
super.update(this.leafHash.digest());
|
|
770
|
+
super.update(rightEncodeK12(this.chunksDone));
|
|
771
|
+
super.update(Uint8Array.from([0xff, 0xff]));
|
|
772
|
+
}
|
|
773
|
+
super.finish.call(this);
|
|
774
|
+
}
|
|
775
|
+
destroy(): void {
|
|
776
|
+
super.destroy.call(this);
|
|
777
|
+
if (this.leafHash) this.leafHash.destroy();
|
|
778
|
+
// Personalization is copied on create/clone, so destroy can wipe it
|
|
779
|
+
// without touching caller input.
|
|
780
|
+
if (this.personalization !== EMPTY_BUFFER) clean(this.personalization);
|
|
781
|
+
this.personalization = EMPTY_BUFFER;
|
|
782
|
+
}
|
|
783
|
+
_cloneInto(to?: _KangarooTwelve): _KangarooTwelve {
|
|
784
|
+
const { blockLen, leafLen, leafHash, outputLen, rounds } = this;
|
|
785
|
+
const personalization =
|
|
786
|
+
this.personalization === EMPTY_BUFFER ? EMPTY_BUFFER : copyBytes(this.personalization);
|
|
787
|
+
// Personalization is absorbed only during finish(), so clones need the same pending value.
|
|
788
|
+
to ||= new _KangarooTwelve(blockLen, leafLen, outputLen, rounds, {
|
|
789
|
+
personalization,
|
|
790
|
+
});
|
|
791
|
+
super._cloneInto(to);
|
|
792
|
+
// Reused destinations can carry a stale leaf from an older multi-chunk state.
|
|
793
|
+
if (leafHash) to.leafHash = leafHash._cloneInto(to.leafHash);
|
|
794
|
+
else if (to.leafHash) {
|
|
795
|
+
to.leafHash.destroy();
|
|
796
|
+
to.leafHash = undefined;
|
|
797
|
+
}
|
|
798
|
+
// Snapshot the pending personalization so clone state does not alias caller-owned input.
|
|
799
|
+
to.personalization = personalization;
|
|
800
|
+
to.leafLen = this.leafLen;
|
|
801
|
+
to.chunkPos = this.chunkPos;
|
|
802
|
+
to.chunksDone = this.chunksDone;
|
|
803
|
+
return to;
|
|
804
|
+
}
|
|
805
|
+
clone(): _KangarooTwelve {
|
|
806
|
+
return this._cloneInto();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* 128-bit KangarooTwelve (k12): reduced 12-round keccak.
|
|
812
|
+
* @param msg - message bytes to hash
|
|
813
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
814
|
+
* 32 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
|
|
815
|
+
* @returns Digest bytes.
|
|
816
|
+
* @example
|
|
817
|
+
* Hash a message with KangarooTwelve-128.
|
|
818
|
+
* ```ts
|
|
819
|
+
* kt128(new Uint8Array([1, 2, 3]));
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
export const kt128: TRet<CHash<_KangarooTwelve, KangarooOpts>> = /* @__PURE__ */ createHasher(
|
|
823
|
+
(opts: TArg<KangarooOpts> = {}) => new _KangarooTwelve(168, 32, chooseLen(opts, 32), 12, opts)
|
|
824
|
+
);
|
|
825
|
+
/**
|
|
826
|
+
* 256-bit KangarooTwelve (k12): reduced 12-round keccak.
|
|
827
|
+
* @param msg - message bytes to hash
|
|
828
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
829
|
+
* 64 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
|
|
830
|
+
* @returns Digest bytes.
|
|
831
|
+
* @example
|
|
832
|
+
* Hash a message with KangarooTwelve-256.
|
|
833
|
+
* ```ts
|
|
834
|
+
* kt256(new Uint8Array([1, 2, 3]));
|
|
835
|
+
* ```
|
|
836
|
+
*/
|
|
837
|
+
export const kt256: TRet<CHash<_KangarooTwelve, KangarooOpts>> = /* @__PURE__ */ createHasher(
|
|
838
|
+
(opts: TArg<KangarooOpts> = {}) => new _KangarooTwelve(136, 64, chooseLen(opts, 64), 12, opts)
|
|
839
|
+
);
|
|
840
|
+
|
|
841
|
+
// MarsupilamiFourteen (14-rounds) can be defined as:
|
|
842
|
+
// `new KangarooTwelve(136, 64, chooseLen(opts, 64), 14, opts)`
|
|
843
|
+
|
|
844
|
+
/** KangarooTwelve-based MAC function type. */
|
|
845
|
+
export type HopMAC = (
|
|
846
|
+
key: TArg<Uint8Array>,
|
|
847
|
+
message: TArg<Uint8Array>,
|
|
848
|
+
personalization: TArg<Uint8Array>,
|
|
849
|
+
dkLen?: number
|
|
850
|
+
) => TRet<Uint8Array>;
|
|
851
|
+
const genHopMAC =
|
|
852
|
+
(hash: TArg<CHash<_KangarooTwelve, KangarooOpts>>): TRet<HopMAC> =>
|
|
853
|
+
(
|
|
854
|
+
key: TArg<Uint8Array>,
|
|
855
|
+
message: TArg<Uint8Array>,
|
|
856
|
+
personalization: TArg<Uint8Array>,
|
|
857
|
+
dkLen?: number
|
|
858
|
+
) => {
|
|
859
|
+
const h = hash as unknown as CHash<_KangarooTwelve, KangarooOpts>;
|
|
860
|
+
return h(key, { personalization: h(message, { personalization }), dkLen }) as TRet<Uint8Array>;
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* 128-bit KangarooTwelve-based MAC.
|
|
865
|
+
*
|
|
866
|
+
* These untested (there is no test vectors or implementation available). Use at your own risk.
|
|
867
|
+
* HopMAC128(Key, M, C, L) = KT128(Key, KT128(M, C, 32), L)
|
|
868
|
+
* HopMAC256(Key, M, C, L) = KT256(Key, KT256(M, C, 64), L)
|
|
869
|
+
* The inner KangarooTwelve call always uses a fixed 32-byte digest here,
|
|
870
|
+
* regardless of the outer `dkLen`.
|
|
871
|
+
* @param key - MAC key bytes
|
|
872
|
+
* @param message - message bytes to authenticate
|
|
873
|
+
* @param personalization - personalization bytes mixed into the inner hash
|
|
874
|
+
* @param dkLen - optional output length in bytes
|
|
875
|
+
* @returns Authentication tag bytes.
|
|
876
|
+
* @example
|
|
877
|
+
* Authenticate a message with HopMAC128.
|
|
878
|
+
* ```ts
|
|
879
|
+
* HopMAC128(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 32);
|
|
880
|
+
* ```
|
|
881
|
+
*/
|
|
882
|
+
export const HopMAC128: TRet<HopMAC> = /* @__PURE__ */ genHopMAC(kt128);
|
|
883
|
+
/**
|
|
884
|
+
* 256-bit KangarooTwelve-based MAC.
|
|
885
|
+
* Like `HopMAC128`, there are no test vectors or known independent
|
|
886
|
+
* implementations available for cross-checking.
|
|
887
|
+
* @param key - MAC key bytes
|
|
888
|
+
* @param message - message bytes to authenticate
|
|
889
|
+
* @param personalization - personalization bytes mixed into the inner hash
|
|
890
|
+
* @param dkLen - optional output length in bytes. The inner KangarooTwelve
|
|
891
|
+
* call still uses a fixed 64-byte digest here, regardless of the outer
|
|
892
|
+
* `dkLen`.
|
|
893
|
+
* @returns Authentication tag bytes.
|
|
894
|
+
* @example
|
|
895
|
+
* Authenticate a message with HopMAC256.
|
|
896
|
+
* ```ts
|
|
897
|
+
* HopMAC256(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 64);
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
export const HopMAC256: TRet<HopMAC> = /* @__PURE__ */ genHopMAC(kt256);
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* More at
|
|
904
|
+
* {@link https://github.com/XKCP/XKCP/tree/master/lib/high/Keccak/PRG}.
|
|
905
|
+
* Accepted capacities must keep `rho = 1598 - capacity` byte-aligned, and
|
|
906
|
+
* `.clean()` later also requires `rate > 801`.
|
|
907
|
+
*/
|
|
908
|
+
export class _KeccakPRG extends Keccak implements PRG {
|
|
909
|
+
protected rate: number;
|
|
910
|
+
constructor(capacity: number) {
|
|
911
|
+
anumber(capacity);
|
|
912
|
+
const rate = 1600 - capacity;
|
|
913
|
+
const rho = rate - 2;
|
|
914
|
+
// Rho must be full bytes
|
|
915
|
+
if (capacity < 0 || capacity > 1600 - 10 || rho % 8) throw new Error('invalid capacity');
|
|
916
|
+
// blockLen = rho in bytes
|
|
917
|
+
super(rho / 8, 0, 0, true);
|
|
918
|
+
this.rate = rate;
|
|
919
|
+
this.posOut = Math.floor((rate + 7) / 8);
|
|
920
|
+
}
|
|
921
|
+
protected keccak(): void {
|
|
922
|
+
// Duplex padding
|
|
923
|
+
this.state[this.pos] ^= 0x01;
|
|
924
|
+
this.state[this.blockLen] ^= 0x02; // Rho is full bytes
|
|
925
|
+
super.keccak();
|
|
926
|
+
this.pos = 0;
|
|
927
|
+
this.posOut = 0;
|
|
928
|
+
}
|
|
929
|
+
update(data: TArg<Uint8Array>): this {
|
|
930
|
+
super.update(data);
|
|
931
|
+
this.posOut = this.blockLen;
|
|
932
|
+
return this;
|
|
933
|
+
}
|
|
934
|
+
protected finish(): void {}
|
|
935
|
+
digestInto(_out: TArg<Uint8Array>): void {
|
|
936
|
+
throw new Error('digest is not allowed, use .randomBytes() instead');
|
|
937
|
+
}
|
|
938
|
+
addEntropy(seed: TArg<Uint8Array>): void {
|
|
939
|
+
this.update(seed);
|
|
940
|
+
}
|
|
941
|
+
randomBytes(length: number): TRet<Uint8Array> {
|
|
942
|
+
return this.xof(length);
|
|
943
|
+
}
|
|
944
|
+
clean(): void {
|
|
945
|
+
// clean() mutates live sponge state just like randomBytes(),
|
|
946
|
+
// so destroyed instances must reject it.
|
|
947
|
+
aexists(this, false);
|
|
948
|
+
if (this.rate < 1600 / 2 + 1) throw new Error('rate is too low to use .forget()');
|
|
949
|
+
this.keccak();
|
|
950
|
+
for (let i = 0; i < this.blockLen; i++) this.state[i] = 0;
|
|
951
|
+
this.pos = this.blockLen;
|
|
952
|
+
this.keccak();
|
|
953
|
+
this.posOut = this.blockLen;
|
|
954
|
+
}
|
|
955
|
+
_cloneInto(to?: _KeccakPRG): _KeccakPRG {
|
|
956
|
+
const { rate } = this;
|
|
957
|
+
to ||= new _KeccakPRG(1600 - rate);
|
|
958
|
+
super._cloneInto(to);
|
|
959
|
+
to.rate = rate;
|
|
960
|
+
return to;
|
|
961
|
+
}
|
|
962
|
+
clone(): _KeccakPRG {
|
|
963
|
+
return this._cloneInto();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* KeccakPRG: pseudo-random generator based on Keccak.
|
|
969
|
+
* See {@link https://keccak.team/files/CSF-0.1.pdf}.
|
|
970
|
+
* @param capacity - sponge capacity in bits. Accepted values are those that
|
|
971
|
+
* keep `rho = 1598 - capacity` byte-aligned; the default `254` is chosen
|
|
972
|
+
* because it satisfies that duplex layout while leaving a wide byte-aligned
|
|
973
|
+
* rate.
|
|
974
|
+
* @returns PRG instance backed by a Keccak sponge.
|
|
975
|
+
* @example
|
|
976
|
+
* Create a Keccak-based pseudorandom generator and read bytes from it.
|
|
977
|
+
* ```ts
|
|
978
|
+
* const prg = keccakprg(254);
|
|
979
|
+
* prg.randomBytes(8);
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
982
|
+
export const keccakprg = (capacity = 254): TRet<_KeccakPRG> =>
|
|
983
|
+
new _KeccakPRG(capacity) as TRet<_KeccakPRG>;
|