@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,783 @@
|
|
|
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 } from "./sha3.js";
|
|
13
|
+
import { abytes, aexists, anumber, clean, copyBytes, createHasher, kdfInputToBytes, u32, } from "./utils.js";
|
|
14
|
+
// cSHAKE && KMAC (NIST SP800-185)
|
|
15
|
+
const _8n = /* @__PURE__ */ BigInt(8);
|
|
16
|
+
const _ffn = /* @__PURE__ */ BigInt(0xff);
|
|
17
|
+
// It is safe to use bigints here, since they used only for length encoding (not actual data).
|
|
18
|
+
// We use bigints in sha256 for lengths too.
|
|
19
|
+
// Callers are still expected to supply SP 800-185-valid lengths
|
|
20
|
+
// (`0 <= x < 2^2040`); this helper does not enforce that bound.
|
|
21
|
+
function leftEncode(n) {
|
|
22
|
+
n = BigInt(n);
|
|
23
|
+
const res = [Number(n & _ffn)];
|
|
24
|
+
n >>= _8n;
|
|
25
|
+
for (; n > 0; n >>= _8n)
|
|
26
|
+
res.unshift(Number(n & _ffn));
|
|
27
|
+
res.unshift(res.length);
|
|
28
|
+
return new Uint8Array(res);
|
|
29
|
+
}
|
|
30
|
+
// Same caller contract as `leftEncode(...)`: lengths must already satisfy SP 800-185 §2.3.1.
|
|
31
|
+
function rightEncode(n) {
|
|
32
|
+
n = BigInt(n);
|
|
33
|
+
const res = [Number(n & _ffn)];
|
|
34
|
+
n >>= _8n;
|
|
35
|
+
for (; n > 0; n >>= _8n)
|
|
36
|
+
res.unshift(Number(n & _ffn));
|
|
37
|
+
res.push(res.length);
|
|
38
|
+
return new Uint8Array(res);
|
|
39
|
+
}
|
|
40
|
+
// `dkLen` validation is deferred to the downstream Keccak constructor.
|
|
41
|
+
function chooseLen(opts, outputLen) {
|
|
42
|
+
return opts.dkLen === undefined ? outputLen : opts.dkLen;
|
|
43
|
+
}
|
|
44
|
+
const abytesOrZero = (buf, title = '') => {
|
|
45
|
+
if (buf === undefined)
|
|
46
|
+
return EMPTY_BUFFER;
|
|
47
|
+
abytes(buf, undefined, title);
|
|
48
|
+
return buf;
|
|
49
|
+
};
|
|
50
|
+
// NOTE: second modulo is necessary since we don't need to add padding if the
|
|
51
|
+
// current element takes a whole block.
|
|
52
|
+
// Callers only pass the fixed positive Keccak rates here (`168` or `136`);
|
|
53
|
+
// `block <= 0` is not validated locally.
|
|
54
|
+
const getPadding = (len, block) => new Uint8Array((block - (len % block)) % block);
|
|
55
|
+
// Personalization
|
|
56
|
+
function cshakePers(hash, opts = {}) {
|
|
57
|
+
const h = hash;
|
|
58
|
+
if (!opts || (opts.personalization === undefined && opts.NISTfn === undefined))
|
|
59
|
+
return h;
|
|
60
|
+
// Encode and pad inplace to avoid unneccesary memory copies/slices so we
|
|
61
|
+
// don't need to zero them later.
|
|
62
|
+
// bytepad(encode_string(N) || encode_string(S), rate), where `rate` is the
|
|
63
|
+
// current cSHAKE/KMAC/TupleHash/ParallelHash block length.
|
|
64
|
+
const blockLenBytes = leftEncode(h.blockLen);
|
|
65
|
+
const fn = opts.NISTfn === undefined ? EMPTY_BUFFER : kdfInputToBytes(opts.NISTfn);
|
|
66
|
+
const fnLen = leftEncode(_8n * BigInt(fn.length)); // length in bits
|
|
67
|
+
const pers = abytesOrZero(opts.personalization, 'personalization');
|
|
68
|
+
const persLen = leftEncode(_8n * BigInt(pers.length)); // length in bits
|
|
69
|
+
if (!fn.length && !pers.length)
|
|
70
|
+
return h;
|
|
71
|
+
// SP 800-185 cSHAKE appends `00` instead of SHAKE's `1111`; in this Keccak implementation
|
|
72
|
+
// that changes the delimited suffix byte from `0x1f` to `0x04` once N or S is non-empty.
|
|
73
|
+
h.suffix = 0x04;
|
|
74
|
+
h.update(blockLenBytes).update(fnLen).update(fn).update(persLen).update(pers);
|
|
75
|
+
let totalLen = blockLenBytes.length + fnLen.length + fn.length + persLen.length + pers.length;
|
|
76
|
+
h.update(getPadding(totalLen, h.blockLen));
|
|
77
|
+
return h;
|
|
78
|
+
}
|
|
79
|
+
const gencShake = (suffix, blockLen, outputLen) => createHasher((opts = {}) => cshakePers(new Keccak(blockLen, suffix, chooseLen(opts, outputLen), true), opts));
|
|
80
|
+
/**
|
|
81
|
+
* 128-bit NIST cSHAKE XOF.
|
|
82
|
+
* @param msg - message bytes to hash
|
|
83
|
+
* @param opts - Optional output, personalization, and NIST function-name
|
|
84
|
+
* settings. When both `NISTfn` and `personalization` are empty,
|
|
85
|
+
* SP 800-185 defines this as plain SHAKE128. Defaults to 16 output bytes
|
|
86
|
+
* when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
87
|
+
* @returns Digest bytes.
|
|
88
|
+
* @example
|
|
89
|
+
* Hash a message with cSHAKE128.
|
|
90
|
+
* ```ts
|
|
91
|
+
* cshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export const cshake128 = /* @__PURE__ */ gencShake(0x1f, 168, 16);
|
|
95
|
+
/**
|
|
96
|
+
* 256-bit NIST cSHAKE XOF.
|
|
97
|
+
* @param msg - message bytes to hash
|
|
98
|
+
* @param opts - Optional output, personalization, and NIST function-name
|
|
99
|
+
* settings. When both `NISTfn` and `personalization` are empty,
|
|
100
|
+
* SP 800-185 defines this as plain SHAKE256. Defaults to 32 output bytes
|
|
101
|
+
* when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
102
|
+
* @returns Digest bytes.
|
|
103
|
+
* @example
|
|
104
|
+
* Hash a message with cSHAKE256.
|
|
105
|
+
* ```ts
|
|
106
|
+
* cshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const cshake256 = /* @__PURE__ */ gencShake(0x1f, 136, 32);
|
|
110
|
+
/**
|
|
111
|
+
* Internal KMAC class.
|
|
112
|
+
* SP 800-185 §8.4.1 still recommends keys at least as long as the target
|
|
113
|
+
* security strength.
|
|
114
|
+
*/
|
|
115
|
+
export class _KMAC extends Keccak {
|
|
116
|
+
constructor(blockLen, outputLen, enableXOF, key, opts = {}) {
|
|
117
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
118
|
+
// Preload T = bytepad(encode_string("KMAC") || encode_string(S), rate); later updates append
|
|
119
|
+
// newX = bytepad(encode_string(K), rate) || X and `finish()` appends right_encode(L or 0).
|
|
120
|
+
cshakePers(this, {
|
|
121
|
+
NISTfn: 'KMAC',
|
|
122
|
+
personalization: opts.personalization,
|
|
123
|
+
});
|
|
124
|
+
abytes(key, undefined, 'key');
|
|
125
|
+
// 1. newX = bytepad(encode_string(K), rate) || X || right_encode(L),
|
|
126
|
+
// with `rate = this.blockLen`.
|
|
127
|
+
const blockLenBytes = leftEncode(this.blockLen);
|
|
128
|
+
const keyLen = leftEncode(_8n * BigInt(key.length));
|
|
129
|
+
this.update(blockLenBytes).update(keyLen).update(key);
|
|
130
|
+
const totalLen = blockLenBytes.length + keyLen.length + key.length;
|
|
131
|
+
this.update(getPadding(totalLen, this.blockLen));
|
|
132
|
+
}
|
|
133
|
+
finish() {
|
|
134
|
+
// SP 800-185 uses right_encode(L) for fixed-length KMAC and right_encode(0) for KMACXOF.
|
|
135
|
+
// outputLen in bits
|
|
136
|
+
if (!this.finished)
|
|
137
|
+
this.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
138
|
+
super.finish();
|
|
139
|
+
}
|
|
140
|
+
_cloneInto(to) {
|
|
141
|
+
// Create new instance without calling constructor since the key
|
|
142
|
+
// is already in state and we don't know it.
|
|
143
|
+
// Force "to" to be instance of KMAC instead of Sha3.
|
|
144
|
+
if (!to) {
|
|
145
|
+
to = Object.create(Object.getPrototypeOf(this), {});
|
|
146
|
+
to.state = this.state.slice();
|
|
147
|
+
to.blockLen = this.blockLen;
|
|
148
|
+
to.state32 = u32(to.state);
|
|
149
|
+
}
|
|
150
|
+
return super._cloneInto(to);
|
|
151
|
+
}
|
|
152
|
+
clone() {
|
|
153
|
+
return this._cloneInto();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function genKmac(blockLen, outputLen, xof = false) {
|
|
157
|
+
// One-shot XOF wrappers still finalize via `.digest()` because `_KMAC`
|
|
158
|
+
// already bakes the requested output length into the state.
|
|
159
|
+
const kmac = (key, message, opts) => kmac.create(key, opts).update(message).digest();
|
|
160
|
+
kmac.create = (key, opts = {}) => new _KMAC(blockLen, chooseLen(opts, outputLen), xof, key, opts);
|
|
161
|
+
return kmac;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 128-bit Keccak MAC.
|
|
165
|
+
* @param key - MAC key bytes
|
|
166
|
+
* @param message - message bytes to authenticate
|
|
167
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
168
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
169
|
+
* @returns Authentication tag bytes.
|
|
170
|
+
* @example
|
|
171
|
+
* Authenticate a message with KMAC128.
|
|
172
|
+
* ```ts
|
|
173
|
+
* kmac128(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export const kmac128 = /* @__PURE__ */ genKmac(168, 16);
|
|
177
|
+
/**
|
|
178
|
+
* 256-bit Keccak MAC.
|
|
179
|
+
* @param key - MAC key bytes
|
|
180
|
+
* @param message - message bytes to authenticate
|
|
181
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
182
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
183
|
+
* @returns Authentication tag bytes.
|
|
184
|
+
* @example
|
|
185
|
+
* Authenticate a message with KMAC256.
|
|
186
|
+
* ```ts
|
|
187
|
+
* kmac256(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export const kmac256 = /* @__PURE__ */ genKmac(136, 32);
|
|
191
|
+
/**
|
|
192
|
+
* 128-bit Keccak-MAC XOF.
|
|
193
|
+
* @param key - MAC key bytes
|
|
194
|
+
* @param message - message bytes to authenticate
|
|
195
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
196
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
197
|
+
* @returns Authentication tag bytes.
|
|
198
|
+
* @example
|
|
199
|
+
* Authenticate a message with KMAC128 XOF output.
|
|
200
|
+
* ```ts
|
|
201
|
+
* kmac128xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 32 });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export const kmac128xof = /* @__PURE__ */ genKmac(168, 16, true);
|
|
205
|
+
/**
|
|
206
|
+
* 256-bit Keccak-MAC XOF.
|
|
207
|
+
* @param key - MAC key bytes
|
|
208
|
+
* @param message - message bytes to authenticate
|
|
209
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
210
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
211
|
+
* @returns Authentication tag bytes.
|
|
212
|
+
* @example
|
|
213
|
+
* Authenticate a message with KMAC256 XOF output.
|
|
214
|
+
* ```ts
|
|
215
|
+
* kmac256xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 64 });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
export const kmac256xof = /* @__PURE__ */ genKmac(136, 32, true);
|
|
219
|
+
/**
|
|
220
|
+
* Internal TupleHash class for byte-array tuple elements.
|
|
221
|
+
* This implementation relies on SP 800-185's byte-oriented encoding form
|
|
222
|
+
* rather than arbitrary bit strings.
|
|
223
|
+
*/
|
|
224
|
+
export class _TupleHash extends Keccak {
|
|
225
|
+
constructor(blockLen, outputLen, enableXOF, opts = {}) {
|
|
226
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
227
|
+
cshakePers(this, {
|
|
228
|
+
NISTfn: 'TupleHash',
|
|
229
|
+
personalization: opts.personalization,
|
|
230
|
+
});
|
|
231
|
+
// Change update after cshake processed
|
|
232
|
+
this.update = (data) => {
|
|
233
|
+
abytes(data);
|
|
234
|
+
// SP 800-185 encodes each tuple element as
|
|
235
|
+
// encode_string(X[i]) = left_encode(len(X[i])) || X[i].
|
|
236
|
+
super.update(leftEncode(_8n * BigInt(data.length)));
|
|
237
|
+
super.update(data);
|
|
238
|
+
return this;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
finish() {
|
|
242
|
+
// SP 800-185 uses right_encode(L) for fixed-length TupleHash
|
|
243
|
+
// and right_encode(0) for TupleHashXOF.
|
|
244
|
+
if (!this.finished)
|
|
245
|
+
// outputLen in bits
|
|
246
|
+
super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
247
|
+
super.finish();
|
|
248
|
+
}
|
|
249
|
+
_cloneInto(to) {
|
|
250
|
+
to ||= new _TupleHash(this.blockLen, this.outputLen, this.enableXOF);
|
|
251
|
+
return super._cloneInto(to);
|
|
252
|
+
}
|
|
253
|
+
clone() {
|
|
254
|
+
return this._cloneInto();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function genTuple(blockLen, outputLen, xof = false) {
|
|
258
|
+
// One-shot XOF wrappers still use `.digest()` because `_TupleHash` stores
|
|
259
|
+
// the requested output length in the state itself.
|
|
260
|
+
const tuple = (messages, opts) => {
|
|
261
|
+
const h = tuple.create(opts);
|
|
262
|
+
if (!Array.isArray(messages))
|
|
263
|
+
throw new Error('expected array of messages');
|
|
264
|
+
for (const msg of messages)
|
|
265
|
+
h.update(msg);
|
|
266
|
+
return h.digest();
|
|
267
|
+
};
|
|
268
|
+
tuple.create = (opts = {}) => new _TupleHash(blockLen, chooseLen(opts, outputLen), xof, opts);
|
|
269
|
+
return tuple;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 128-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
|
|
273
|
+
* @param messages - ordered byte-array tuple
|
|
274
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
275
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
276
|
+
* @returns Digest bytes.
|
|
277
|
+
* @example
|
|
278
|
+
* Hash a tuple of byte arrays with TupleHash128.
|
|
279
|
+
* ```ts
|
|
280
|
+
* tuplehash128([new Uint8Array([1]), new Uint8Array([2])]);
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export const tuplehash128 = /* @__PURE__ */ genTuple(168, 16);
|
|
284
|
+
/**
|
|
285
|
+
* 256-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
|
|
286
|
+
* @param messages - ordered byte-array tuple
|
|
287
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
288
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
289
|
+
* @returns Digest bytes.
|
|
290
|
+
* @example
|
|
291
|
+
* Hash a tuple of byte arrays with TupleHash256.
|
|
292
|
+
* ```ts
|
|
293
|
+
* tuplehash256([new Uint8Array([1]), new Uint8Array([2])]);
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export const tuplehash256 = /* @__PURE__ */ genTuple(136, 32);
|
|
297
|
+
/**
|
|
298
|
+
* 128-bit TupleHASH XOF.
|
|
299
|
+
* @param messages - ordered byte-array tuple
|
|
300
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
301
|
+
* 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
302
|
+
* @returns Digest bytes.
|
|
303
|
+
* @example
|
|
304
|
+
* Hash a tuple of byte arrays with TupleHash128 XOF output.
|
|
305
|
+
* ```ts
|
|
306
|
+
* tuplehash128xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 32 });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export const tuplehash128xof = /* @__PURE__ */ genTuple(168, 16, true);
|
|
310
|
+
/**
|
|
311
|
+
* 256-bit TupleHASH XOF.
|
|
312
|
+
* @param messages - ordered byte-array tuple
|
|
313
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
314
|
+
* 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
|
|
315
|
+
* @returns Digest bytes.
|
|
316
|
+
* @example
|
|
317
|
+
* Hash a tuple of byte arrays with TupleHash256 XOF output.
|
|
318
|
+
* ```ts
|
|
319
|
+
* tuplehash256xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 64 });
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export const tuplehash256xof = /* @__PURE__ */ genTuple(136, 32, true);
|
|
323
|
+
/** Internal Parallel Keccak Hash class. */
|
|
324
|
+
export class _ParallelHash extends Keccak {
|
|
325
|
+
leafHash;
|
|
326
|
+
leafCons;
|
|
327
|
+
chunkPos = 0; // Position of current block in chunk
|
|
328
|
+
chunksDone = 0; // How many chunks we already have
|
|
329
|
+
chunkLen;
|
|
330
|
+
constructor(blockLen, outputLen, leafCons, enableXOF, opts = {}) {
|
|
331
|
+
super(blockLen, 0x1f, outputLen, enableXOF);
|
|
332
|
+
cshakePers(this, {
|
|
333
|
+
NISTfn: 'ParallelHash',
|
|
334
|
+
personalization: opts.personalization,
|
|
335
|
+
});
|
|
336
|
+
this.leafCons = leafCons;
|
|
337
|
+
let { blockLen: B = 8 } = opts;
|
|
338
|
+
anumber(B);
|
|
339
|
+
// blockLen=0 makes take=0 in update(), so pos never advances and the hash hangs.
|
|
340
|
+
if (B < 1)
|
|
341
|
+
throw new Error('"blockLen" must be >= 1, got ' + B);
|
|
342
|
+
this.chunkLen = B;
|
|
343
|
+
// SP 800-185 initializes z = left_encode(B); each completed chunk appends
|
|
344
|
+
// one fixed-size cSHAKE leaf digest before finish() adds right_encode(n)
|
|
345
|
+
// and right_encode(L or 0).
|
|
346
|
+
super.update(leftEncode(B));
|
|
347
|
+
// Change update after cshake processed
|
|
348
|
+
this.update = (data) => {
|
|
349
|
+
abytes(data);
|
|
350
|
+
const { chunkLen, leafCons } = this;
|
|
351
|
+
for (let pos = 0, len = data.length; pos < len;) {
|
|
352
|
+
if (this.chunkPos == chunkLen || !this.leafHash) {
|
|
353
|
+
if (this.leafHash) {
|
|
354
|
+
super.update(this.leafHash.digest());
|
|
355
|
+
this.chunksDone++;
|
|
356
|
+
}
|
|
357
|
+
this.leafHash = leafCons();
|
|
358
|
+
this.chunkPos = 0;
|
|
359
|
+
}
|
|
360
|
+
const take = Math.min(chunkLen - this.chunkPos, len - pos);
|
|
361
|
+
this.leafHash.update(data.subarray(pos, pos + take));
|
|
362
|
+
this.chunkPos += take;
|
|
363
|
+
pos += take;
|
|
364
|
+
}
|
|
365
|
+
return this;
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
finish() {
|
|
369
|
+
if (this.finished)
|
|
370
|
+
return;
|
|
371
|
+
if (this.leafHash) {
|
|
372
|
+
super.update(this.leafHash.digest());
|
|
373
|
+
this.chunksDone++;
|
|
374
|
+
}
|
|
375
|
+
// SP 800-185 finishes ParallelHash as
|
|
376
|
+
// z || right_encode(n) || right_encode(L); XOF mode replaces
|
|
377
|
+
// right_encode(L) with right_encode(0).
|
|
378
|
+
super.update(rightEncode(this.chunksDone));
|
|
379
|
+
// outputLen in bits
|
|
380
|
+
super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
|
|
381
|
+
super.finish();
|
|
382
|
+
}
|
|
383
|
+
_cloneInto(to) {
|
|
384
|
+
to ||= new _ParallelHash(this.blockLen, this.outputLen, this.leafCons, this.enableXOF);
|
|
385
|
+
to.leafCons = this.leafCons;
|
|
386
|
+
// Reused destinations can carry a stale partial leaf
|
|
387
|
+
// when the source is still on the root sponge.
|
|
388
|
+
if (this.leafHash)
|
|
389
|
+
to.leafHash = this.leafHash._cloneInto(to.leafHash);
|
|
390
|
+
else if (to.leafHash) {
|
|
391
|
+
to.leafHash.destroy();
|
|
392
|
+
to.leafHash = undefined;
|
|
393
|
+
}
|
|
394
|
+
to.chunkPos = this.chunkPos;
|
|
395
|
+
to.chunkLen = this.chunkLen;
|
|
396
|
+
to.chunksDone = this.chunksDone;
|
|
397
|
+
return super._cloneInto(to);
|
|
398
|
+
}
|
|
399
|
+
destroy() {
|
|
400
|
+
super.destroy.call(this);
|
|
401
|
+
if (this.leafHash)
|
|
402
|
+
this.leafHash.destroy();
|
|
403
|
+
}
|
|
404
|
+
clone() {
|
|
405
|
+
return this._cloneInto();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function genPrl(blockLen, outputLen, leaf, xof = false) {
|
|
409
|
+
const parallel = (message, opts) => parallel.create(opts).update(message).digest();
|
|
410
|
+
parallel.create = (opts = {}) => new _ParallelHash(blockLen, chooseLen(opts, outputLen),
|
|
411
|
+
// SP 800-185 fixes leaf digests at 256 bits for ParallelHash128 and
|
|
412
|
+
// 512 bits for ParallelHash256; only the final cSHAKE output uses the
|
|
413
|
+
// caller-selected dkLen.
|
|
414
|
+
() => leaf.create({ dkLen: 2 * outputLen }), xof, opts);
|
|
415
|
+
parallel.outputLen = outputLen;
|
|
416
|
+
parallel.blockLen = blockLen;
|
|
417
|
+
parallel.canXOF = xof;
|
|
418
|
+
return parallel;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* 128-bit ParallelHash. In JS, it is not parallel.
|
|
422
|
+
* @param msg - message bytes to hash
|
|
423
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
424
|
+
* Defaults to 16 output bytes when `dkLen` is omitted.
|
|
425
|
+
* See {@link ParallelOpts}.
|
|
426
|
+
* @returns Digest bytes.
|
|
427
|
+
* @example
|
|
428
|
+
* Hash a message with ParallelHash128.
|
|
429
|
+
* ```ts
|
|
430
|
+
* parallelhash128(new Uint8Array([1, 2, 3]));
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
export const parallelhash128 = /* @__PURE__ */ genPrl(168, 16, cshake128);
|
|
434
|
+
/**
|
|
435
|
+
* 256-bit ParallelHash. In JS, it is not parallel.
|
|
436
|
+
* @param msg - message bytes to hash
|
|
437
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
438
|
+
* Defaults to 32 output bytes when `dkLen` is omitted.
|
|
439
|
+
* See {@link ParallelOpts}.
|
|
440
|
+
* @returns Digest bytes.
|
|
441
|
+
* @example
|
|
442
|
+
* Hash a message with ParallelHash256.
|
|
443
|
+
* ```ts
|
|
444
|
+
* parallelhash256(new Uint8Array([1, 2, 3]));
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
export const parallelhash256 = /* @__PURE__ */ genPrl(136, 32, cshake256);
|
|
448
|
+
/**
|
|
449
|
+
* 128-bit ParallelHash XOF. In JS, it is not parallel.
|
|
450
|
+
* @param msg - message bytes to hash
|
|
451
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
452
|
+
* Defaults to 16 output bytes when `dkLen` is omitted.
|
|
453
|
+
* See {@link ParallelOpts}.
|
|
454
|
+
* @returns Digest bytes.
|
|
455
|
+
* @example
|
|
456
|
+
* Hash a message with ParallelHash128 XOF output.
|
|
457
|
+
* ```ts
|
|
458
|
+
* parallelhash128xof(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
export const parallelhash128xof = /* @__PURE__ */ genPrl(168, 16, cshake128, true);
|
|
462
|
+
/**
|
|
463
|
+
* 256-bit ParallelHash XOF. In JS, it is not parallel.
|
|
464
|
+
* @param msg - message bytes to hash
|
|
465
|
+
* @param opts - Optional output, personalization, and chunking settings.
|
|
466
|
+
* Defaults to 32 output bytes when `dkLen` is omitted.
|
|
467
|
+
* See {@link ParallelOpts}.
|
|
468
|
+
* @returns Digest bytes.
|
|
469
|
+
* @example
|
|
470
|
+
* Hash a message with ParallelHash256 XOF output.
|
|
471
|
+
* ```ts
|
|
472
|
+
* parallelhash256xof(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
export const parallelhash256xof = /* @__PURE__ */ genPrl(136, 32, cshake256, true);
|
|
476
|
+
const genTurbo = (blockLen, outputLen) => createHasher((opts = {}) => {
|
|
477
|
+
const D = opts.D === undefined ? 0x1f : opts.D;
|
|
478
|
+
// RFC 9861 §2.1 fixes the default `D = 0x1f`; §2.2 defines the 12-round
|
|
479
|
+
// TurboSHAKE family selected here.
|
|
480
|
+
if (!Number.isSafeInteger(D) || D < 0x01 || D > 0x7f)
|
|
481
|
+
throw new Error('"D" (domain separation byte) must be 0x01..0x7f, got: ' + D);
|
|
482
|
+
const dkLen = opts.dkLen === undefined ? outputLen : opts.dkLen;
|
|
483
|
+
// RFC 9861 §§2.1-2.2 define output length L as a positive integer.
|
|
484
|
+
if (dkLen < 1)
|
|
485
|
+
throw new Error('"dkLen" must be >= 1');
|
|
486
|
+
return new Keccak(blockLen, D, dkLen, true, 12);
|
|
487
|
+
});
|
|
488
|
+
/**
|
|
489
|
+
* TurboSHAKE 128-bit: reduced 12-round keccak.
|
|
490
|
+
* Should've been a simple "shake with 12 rounds", but we got a whole new
|
|
491
|
+
* spec about Turbo SHAKE Pro MAX.
|
|
492
|
+
* @param msg - message bytes to hash
|
|
493
|
+
* @param opts - Optional output-length and domain-separation settings.
|
|
494
|
+
* RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 32 output bytes when
|
|
495
|
+
* `dkLen` is omitted. See {@link TurboshakeOpts}.
|
|
496
|
+
* @returns Digest bytes.
|
|
497
|
+
* @example
|
|
498
|
+
* Hash a message with TurboSHAKE128.
|
|
499
|
+
* ```ts
|
|
500
|
+
* turboshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
export const turboshake128 = /* @__PURE__ */ genTurbo(168, 32);
|
|
504
|
+
/**
|
|
505
|
+
* TurboSHAKE 256-bit: reduced 12-round keccak.
|
|
506
|
+
* @param msg - message bytes to hash
|
|
507
|
+
* @param opts - Optional output-length and domain-separation settings.
|
|
508
|
+
* RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 64 output bytes when
|
|
509
|
+
* `dkLen` is omitted. See {@link TurboshakeOpts}.
|
|
510
|
+
* @returns Digest bytes.
|
|
511
|
+
* @example
|
|
512
|
+
* Hash a message with TurboSHAKE256.
|
|
513
|
+
* ```ts
|
|
514
|
+
* turboshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
export const turboshake256 = /* @__PURE__ */ genTurbo(136, 64);
|
|
518
|
+
// Same as NIST rightEncode, but returns `[0]` for the zero string.
|
|
519
|
+
// Callers still need to keep `x < 256^255` per RFC 9861 §3.3.
|
|
520
|
+
function rightEncodeK12(n) {
|
|
521
|
+
n = BigInt(n);
|
|
522
|
+
const res = [];
|
|
523
|
+
for (; n > 0; n >>= _8n)
|
|
524
|
+
res.unshift(Number(n & _ffn));
|
|
525
|
+
res.push(res.length);
|
|
526
|
+
return Uint8Array.from(res);
|
|
527
|
+
}
|
|
528
|
+
const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
529
|
+
/** Internal K12 hash class. */
|
|
530
|
+
export class _KangarooTwelve extends Keccak {
|
|
531
|
+
chunkLen = 8192;
|
|
532
|
+
leafHash;
|
|
533
|
+
leafLen;
|
|
534
|
+
personalization;
|
|
535
|
+
chunkPos = 0; // Position of current block in chunk
|
|
536
|
+
chunksDone = 0; // How many chunks we already have
|
|
537
|
+
constructor(blockLen, leafLen, outputLen, rounds, opts) {
|
|
538
|
+
super(blockLen, 0x07, outputLen, true, rounds);
|
|
539
|
+
// RFC 9861 §3 defines output length L as a positive integer.
|
|
540
|
+
if (outputLen < 1)
|
|
541
|
+
throw new Error('"dkLen" must be >= 1');
|
|
542
|
+
this.leafLen = leafLen;
|
|
543
|
+
this.personalization =
|
|
544
|
+
opts.personalization === undefined
|
|
545
|
+
? EMPTY_BUFFER
|
|
546
|
+
: copyBytes(abytes(opts.personalization, undefined, 'personalization'));
|
|
547
|
+
}
|
|
548
|
+
update(data) {
|
|
549
|
+
abytes(data);
|
|
550
|
+
const { chunkLen, blockLen, leafLen, rounds } = this;
|
|
551
|
+
for (let pos = 0, len = data.length; pos < len;) {
|
|
552
|
+
if (this.chunkPos == chunkLen) {
|
|
553
|
+
if (this.leafHash)
|
|
554
|
+
super.update(this.leafHash.digest());
|
|
555
|
+
else {
|
|
556
|
+
// RFC 9861 §3.2 switches from SingleNode (`07`) to FinalNode (`06`)
|
|
557
|
+
// once S exceeds 8192 bytes and prefixes S_0 with
|
|
558
|
+
// `03 00 00 00 00 00 00 00`.
|
|
559
|
+
this.suffix = 0x06; // Its safe to change suffix here since its used only in digest()
|
|
560
|
+
super.update(Uint8Array.from([3, 0, 0, 0, 0, 0, 0, 0]));
|
|
561
|
+
}
|
|
562
|
+
// Secondary chunks S_1..S_(n-1) become fixed-length
|
|
563
|
+
// CV_i = TurboSHAKE*(S_i, `0B`, 32|64) chaining values.
|
|
564
|
+
this.leafHash = new Keccak(blockLen, 0x0b, leafLen, false, rounds);
|
|
565
|
+
this.chunksDone++;
|
|
566
|
+
this.chunkPos = 0;
|
|
567
|
+
}
|
|
568
|
+
const take = Math.min(chunkLen - this.chunkPos, len - pos);
|
|
569
|
+
const chunk = data.subarray(pos, pos + take);
|
|
570
|
+
if (this.leafHash)
|
|
571
|
+
this.leafHash.update(chunk);
|
|
572
|
+
else
|
|
573
|
+
super.update(chunk);
|
|
574
|
+
this.chunkPos += take;
|
|
575
|
+
pos += take;
|
|
576
|
+
}
|
|
577
|
+
return this;
|
|
578
|
+
}
|
|
579
|
+
finish() {
|
|
580
|
+
if (this.finished)
|
|
581
|
+
return;
|
|
582
|
+
const { personalization } = this;
|
|
583
|
+
// RFC 9861 §3.2 forms S = M || C || length_encode(|C|) before any tree hashing logic.
|
|
584
|
+
this.update(personalization).update(rightEncodeK12(personalization.length));
|
|
585
|
+
// Leaf hash
|
|
586
|
+
if (this.leafHash) {
|
|
587
|
+
// Multi-chunk K12 appends
|
|
588
|
+
// CV_1..CV_(n-1) || length_encode(n-1) || `FF FF`
|
|
589
|
+
// before the final TurboSHAKE call.
|
|
590
|
+
super.update(this.leafHash.digest());
|
|
591
|
+
super.update(rightEncodeK12(this.chunksDone));
|
|
592
|
+
super.update(Uint8Array.from([0xff, 0xff]));
|
|
593
|
+
}
|
|
594
|
+
super.finish.call(this);
|
|
595
|
+
}
|
|
596
|
+
destroy() {
|
|
597
|
+
super.destroy.call(this);
|
|
598
|
+
if (this.leafHash)
|
|
599
|
+
this.leafHash.destroy();
|
|
600
|
+
// Personalization is copied on create/clone, so destroy can wipe it
|
|
601
|
+
// without touching caller input.
|
|
602
|
+
if (this.personalization !== EMPTY_BUFFER)
|
|
603
|
+
clean(this.personalization);
|
|
604
|
+
this.personalization = EMPTY_BUFFER;
|
|
605
|
+
}
|
|
606
|
+
_cloneInto(to) {
|
|
607
|
+
const { blockLen, leafLen, leafHash, outputLen, rounds } = this;
|
|
608
|
+
const personalization = this.personalization === EMPTY_BUFFER ? EMPTY_BUFFER : copyBytes(this.personalization);
|
|
609
|
+
// Personalization is absorbed only during finish(), so clones need the same pending value.
|
|
610
|
+
to ||= new _KangarooTwelve(blockLen, leafLen, outputLen, rounds, {
|
|
611
|
+
personalization,
|
|
612
|
+
});
|
|
613
|
+
super._cloneInto(to);
|
|
614
|
+
// Reused destinations can carry a stale leaf from an older multi-chunk state.
|
|
615
|
+
if (leafHash)
|
|
616
|
+
to.leafHash = leafHash._cloneInto(to.leafHash);
|
|
617
|
+
else if (to.leafHash) {
|
|
618
|
+
to.leafHash.destroy();
|
|
619
|
+
to.leafHash = undefined;
|
|
620
|
+
}
|
|
621
|
+
// Snapshot the pending personalization so clone state does not alias caller-owned input.
|
|
622
|
+
to.personalization = personalization;
|
|
623
|
+
to.leafLen = this.leafLen;
|
|
624
|
+
to.chunkPos = this.chunkPos;
|
|
625
|
+
to.chunksDone = this.chunksDone;
|
|
626
|
+
return to;
|
|
627
|
+
}
|
|
628
|
+
clone() {
|
|
629
|
+
return this._cloneInto();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* 128-bit KangarooTwelve (k12): reduced 12-round keccak.
|
|
634
|
+
* @param msg - message bytes to hash
|
|
635
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
636
|
+
* 32 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
|
|
637
|
+
* @returns Digest bytes.
|
|
638
|
+
* @example
|
|
639
|
+
* Hash a message with KangarooTwelve-128.
|
|
640
|
+
* ```ts
|
|
641
|
+
* kt128(new Uint8Array([1, 2, 3]));
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
export const kt128 = /* @__PURE__ */ createHasher((opts = {}) => new _KangarooTwelve(168, 32, chooseLen(opts, 32), 12, opts));
|
|
645
|
+
/**
|
|
646
|
+
* 256-bit KangarooTwelve (k12): reduced 12-round keccak.
|
|
647
|
+
* @param msg - message bytes to hash
|
|
648
|
+
* @param opts - Optional output and personalization settings. Defaults to
|
|
649
|
+
* 64 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
|
|
650
|
+
* @returns Digest bytes.
|
|
651
|
+
* @example
|
|
652
|
+
* Hash a message with KangarooTwelve-256.
|
|
653
|
+
* ```ts
|
|
654
|
+
* kt256(new Uint8Array([1, 2, 3]));
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
export const kt256 = /* @__PURE__ */ createHasher((opts = {}) => new _KangarooTwelve(136, 64, chooseLen(opts, 64), 12, opts));
|
|
658
|
+
const genHopMAC = (hash) => (key, message, personalization, dkLen) => {
|
|
659
|
+
const h = hash;
|
|
660
|
+
return h(key, { personalization: h(message, { personalization }), dkLen });
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* 128-bit KangarooTwelve-based MAC.
|
|
664
|
+
*
|
|
665
|
+
* These untested (there is no test vectors or implementation available). Use at your own risk.
|
|
666
|
+
* HopMAC128(Key, M, C, L) = KT128(Key, KT128(M, C, 32), L)
|
|
667
|
+
* HopMAC256(Key, M, C, L) = KT256(Key, KT256(M, C, 64), L)
|
|
668
|
+
* The inner KangarooTwelve call always uses a fixed 32-byte digest here,
|
|
669
|
+
* regardless of the outer `dkLen`.
|
|
670
|
+
* @param key - MAC key bytes
|
|
671
|
+
* @param message - message bytes to authenticate
|
|
672
|
+
* @param personalization - personalization bytes mixed into the inner hash
|
|
673
|
+
* @param dkLen - optional output length in bytes
|
|
674
|
+
* @returns Authentication tag bytes.
|
|
675
|
+
* @example
|
|
676
|
+
* Authenticate a message with HopMAC128.
|
|
677
|
+
* ```ts
|
|
678
|
+
* HopMAC128(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 32);
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
export const HopMAC128 = /* @__PURE__ */ genHopMAC(kt128);
|
|
682
|
+
/**
|
|
683
|
+
* 256-bit KangarooTwelve-based MAC.
|
|
684
|
+
* Like `HopMAC128`, there are no test vectors or known independent
|
|
685
|
+
* implementations available for cross-checking.
|
|
686
|
+
* @param key - MAC key bytes
|
|
687
|
+
* @param message - message bytes to authenticate
|
|
688
|
+
* @param personalization - personalization bytes mixed into the inner hash
|
|
689
|
+
* @param dkLen - optional output length in bytes. The inner KangarooTwelve
|
|
690
|
+
* call still uses a fixed 64-byte digest here, regardless of the outer
|
|
691
|
+
* `dkLen`.
|
|
692
|
+
* @returns Authentication tag bytes.
|
|
693
|
+
* @example
|
|
694
|
+
* Authenticate a message with HopMAC256.
|
|
695
|
+
* ```ts
|
|
696
|
+
* HopMAC256(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 64);
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
export const HopMAC256 = /* @__PURE__ */ genHopMAC(kt256);
|
|
700
|
+
/**
|
|
701
|
+
* More at
|
|
702
|
+
* {@link https://github.com/XKCP/XKCP/tree/master/lib/high/Keccak/PRG}.
|
|
703
|
+
* Accepted capacities must keep `rho = 1598 - capacity` byte-aligned, and
|
|
704
|
+
* `.clean()` later also requires `rate > 801`.
|
|
705
|
+
*/
|
|
706
|
+
export class _KeccakPRG extends Keccak {
|
|
707
|
+
rate;
|
|
708
|
+
constructor(capacity) {
|
|
709
|
+
anumber(capacity);
|
|
710
|
+
const rate = 1600 - capacity;
|
|
711
|
+
const rho = rate - 2;
|
|
712
|
+
// Rho must be full bytes
|
|
713
|
+
if (capacity < 0 || capacity > 1600 - 10 || rho % 8)
|
|
714
|
+
throw new Error('invalid capacity');
|
|
715
|
+
// blockLen = rho in bytes
|
|
716
|
+
super(rho / 8, 0, 0, true);
|
|
717
|
+
this.rate = rate;
|
|
718
|
+
this.posOut = Math.floor((rate + 7) / 8);
|
|
719
|
+
}
|
|
720
|
+
keccak() {
|
|
721
|
+
// Duplex padding
|
|
722
|
+
this.state[this.pos] ^= 0x01;
|
|
723
|
+
this.state[this.blockLen] ^= 0x02; // Rho is full bytes
|
|
724
|
+
super.keccak();
|
|
725
|
+
this.pos = 0;
|
|
726
|
+
this.posOut = 0;
|
|
727
|
+
}
|
|
728
|
+
update(data) {
|
|
729
|
+
super.update(data);
|
|
730
|
+
this.posOut = this.blockLen;
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
finish() { }
|
|
734
|
+
digestInto(_out) {
|
|
735
|
+
throw new Error('digest is not allowed, use .randomBytes() instead');
|
|
736
|
+
}
|
|
737
|
+
addEntropy(seed) {
|
|
738
|
+
this.update(seed);
|
|
739
|
+
}
|
|
740
|
+
randomBytes(length) {
|
|
741
|
+
return this.xof(length);
|
|
742
|
+
}
|
|
743
|
+
clean() {
|
|
744
|
+
// clean() mutates live sponge state just like randomBytes(),
|
|
745
|
+
// so destroyed instances must reject it.
|
|
746
|
+
aexists(this, false);
|
|
747
|
+
if (this.rate < 1600 / 2 + 1)
|
|
748
|
+
throw new Error('rate is too low to use .forget()');
|
|
749
|
+
this.keccak();
|
|
750
|
+
for (let i = 0; i < this.blockLen; i++)
|
|
751
|
+
this.state[i] = 0;
|
|
752
|
+
this.pos = this.blockLen;
|
|
753
|
+
this.keccak();
|
|
754
|
+
this.posOut = this.blockLen;
|
|
755
|
+
}
|
|
756
|
+
_cloneInto(to) {
|
|
757
|
+
const { rate } = this;
|
|
758
|
+
to ||= new _KeccakPRG(1600 - rate);
|
|
759
|
+
super._cloneInto(to);
|
|
760
|
+
to.rate = rate;
|
|
761
|
+
return to;
|
|
762
|
+
}
|
|
763
|
+
clone() {
|
|
764
|
+
return this._cloneInto();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* KeccakPRG: pseudo-random generator based on Keccak.
|
|
769
|
+
* See {@link https://keccak.team/files/CSF-0.1.pdf}.
|
|
770
|
+
* @param capacity - sponge capacity in bits. Accepted values are those that
|
|
771
|
+
* keep `rho = 1598 - capacity` byte-aligned; the default `254` is chosen
|
|
772
|
+
* because it satisfies that duplex layout while leaving a wide byte-aligned
|
|
773
|
+
* rate.
|
|
774
|
+
* @returns PRG instance backed by a Keccak sponge.
|
|
775
|
+
* @example
|
|
776
|
+
* Create a Keccak-based pseudorandom generator and read bytes from it.
|
|
777
|
+
* ```ts
|
|
778
|
+
* const prg = keccakprg(254);
|
|
779
|
+
* prg.randomBytes(8);
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
export const keccakprg = (capacity = 254) => new _KeccakPRG(capacity);
|
|
783
|
+
//# sourceMappingURL=sha3-addons.js.map
|