liminal 0.1.0-beta.25
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 +202 -0
- package/README.md +26 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/client/Adapter.d.ts +46 -0
- package/esm/client/Adapter.d.ts.map +1 -0
- package/esm/client/Adapter.js +2 -0
- package/esm/client/Adapter.js.map +1 -0
- package/esm/client/Liminal.d.ts +19 -0
- package/esm/client/Liminal.d.ts.map +1 -0
- package/esm/client/Liminal.js +154 -0
- package/esm/client/Liminal.js.map +1 -0
- package/esm/client/Tool.d.ts +15 -0
- package/esm/client/Tool.d.ts.map +1 -0
- package/esm/client/Tool.js +23 -0
- package/esm/client/Tool.js.map +1 -0
- package/esm/client/constants.d.ts +2 -0
- package/esm/client/constants.d.ts.map +1 -0
- package/esm/client/constants.js +7 -0
- package/esm/client/constants.js.map +1 -0
- package/esm/client/mod.d.ts +5 -0
- package/esm/client/mod.d.ts.map +1 -0
- package/esm/client/mod.js +6 -0
- package/esm/client/mod.js.map +1 -0
- package/esm/core/DescriptionContext.d.ts +11 -0
- package/esm/core/DescriptionContext.d.ts.map +1 -0
- package/esm/core/DescriptionContext.js +103 -0
- package/esm/core/DescriptionContext.js.map +1 -0
- package/esm/core/L.d.ts +4 -0
- package/esm/core/L.d.ts.map +1 -0
- package/esm/core/L.js +4 -0
- package/esm/core/L.js.map +1 -0
- package/esm/core/ReduceDependencies.d.ts +6 -0
- package/esm/core/ReduceDependencies.d.ts.map +1 -0
- package/esm/core/ReduceDependencies.js +2 -0
- package/esm/core/ReduceDependencies.js.map +1 -0
- package/esm/core/Type.d.ts +30 -0
- package/esm/core/Type.d.ts.map +1 -0
- package/esm/core/Type.js +2 -0
- package/esm/core/Type.js.map +1 -0
- package/esm/core/TypeVisitor.d.ts +15 -0
- package/esm/core/TypeVisitor.d.ts.map +1 -0
- package/esm/core/TypeVisitor.js +12 -0
- package/esm/core/TypeVisitor.js.map +1 -0
- package/esm/core/annotations/Annotation.d.ts +7 -0
- package/esm/core/annotations/Annotation.d.ts.map +1 -0
- package/esm/core/annotations/Annotation.js +2 -0
- package/esm/core/annotations/Annotation.js.map +1 -0
- package/esm/core/annotations/Assertion.d.ts +8 -0
- package/esm/core/annotations/Assertion.d.ts.map +1 -0
- package/esm/core/annotations/Assertion.js +8 -0
- package/esm/core/annotations/Assertion.js.map +1 -0
- package/esm/core/annotations/Description.d.ts +7 -0
- package/esm/core/annotations/Description.d.ts.map +1 -0
- package/esm/core/annotations/Description.js +8 -0
- package/esm/core/annotations/Description.js.map +1 -0
- package/esm/core/annotations/Param.d.ts +13 -0
- package/esm/core/annotations/Param.d.ts.map +1 -0
- package/esm/core/annotations/Param.js +11 -0
- package/esm/core/annotations/Param.js.map +1 -0
- package/esm/core/annotations/Template.d.ts +10 -0
- package/esm/core/annotations/Template.d.ts.map +1 -0
- package/esm/core/annotations/Template.js +2 -0
- package/esm/core/annotations/Template.js.map +1 -0
- package/esm/core/annotations/mod.d.ts +6 -0
- package/esm/core/annotations/mod.d.ts.map +1 -0
- package/esm/core/annotations/mod.js +7 -0
- package/esm/core/annotations/mod.js.map +1 -0
- package/esm/core/assert.d.ts +22 -0
- package/esm/core/assert.d.ts.map +1 -0
- package/esm/core/assert.js +155 -0
- package/esm/core/assert.js.map +1 -0
- package/esm/core/declareIntrinsic.d.ts +4 -0
- package/esm/core/declareIntrinsic.d.ts.map +1 -0
- package/esm/core/declareIntrinsic.js +26 -0
- package/esm/core/declareIntrinsic.js.map +1 -0
- package/esm/core/deserialize.d.ts +3 -0
- package/esm/core/deserialize.d.ts.map +1 -0
- package/esm/core/deserialize.js +32 -0
- package/esm/core/deserialize.js.map +1 -0
- package/esm/core/display.d.ts +3 -0
- package/esm/core/display.d.ts.map +1 -0
- package/esm/core/display.js +75 -0
- package/esm/core/display.js.map +1 -0
- package/esm/core/inspect.node.d.ts +5 -0
- package/esm/core/inspect.node.d.ts.map +1 -0
- package/esm/core/inspect.node.js +7 -0
- package/esm/core/inspect.node.js.map +1 -0
- package/esm/core/intrinsics.d.ts +19 -0
- package/esm/core/intrinsics.d.ts.map +1 -0
- package/esm/core/intrinsics.js +64 -0
- package/esm/core/intrinsics.js.map +1 -0
- package/esm/core/intrinsics_util.d.ts +6 -0
- package/esm/core/intrinsics_util.d.ts.map +1 -0
- package/esm/core/intrinsics_util.js +46 -0
- package/esm/core/intrinsics_util.js.map +1 -0
- package/esm/core/isType.d.ts +4 -0
- package/esm/core/isType.d.ts.map +1 -0
- package/esm/core/isType.js +18 -0
- package/esm/core/isType.js.map +1 -0
- package/esm/core/mod.d.ts +13 -0
- package/esm/core/mod.d.ts.map +1 -0
- package/esm/core/mod.js +14 -0
- package/esm/core/mod.js.map +1 -0
- package/esm/core/signature.d.ts +4 -0
- package/esm/core/signature.d.ts.map +1 -0
- package/esm/core/signature.js +93 -0
- package/esm/core/signature.js.map +1 -0
- package/esm/core/utility/Flatten.d.ts +8 -0
- package/esm/core/utility/Flatten.d.ts.map +1 -0
- package/esm/core/utility/Flatten.js +6 -0
- package/esm/core/utility/Flatten.js.map +1 -0
- package/esm/core/utility/Intersection.d.ts +12 -0
- package/esm/core/utility/Intersection.d.ts.map +1 -0
- package/esm/core/utility/Intersection.js +5 -0
- package/esm/core/utility/Intersection.js.map +1 -0
- package/esm/core/utility/Option.d.ts +3 -0
- package/esm/core/utility/Option.d.ts.map +1 -0
- package/esm/core/utility/Option.js +5 -0
- package/esm/core/utility/Option.js.map +1 -0
- package/esm/core/utility/Record.d.ts +3 -0
- package/esm/core/utility/Record.d.ts.map +1 -0
- package/esm/core/utility/Record.js +6 -0
- package/esm/core/utility/Record.js.map +1 -0
- package/esm/core/utility/Set.d.ts +4 -0
- package/esm/core/utility/Set.d.ts.map +1 -0
- package/esm/core/utility/Set.js +7 -0
- package/esm/core/utility/Set.js.map +1 -0
- package/esm/core/utility/TaggedUnion.d.ts +13 -0
- package/esm/core/utility/TaggedUnion.d.ts.map +1 -0
- package/esm/core/utility/TaggedUnion.js +8 -0
- package/esm/core/utility/TaggedUnion.js.map +1 -0
- package/esm/core/utility/Tuple.d.ts +9 -0
- package/esm/core/utility/Tuple.d.ts.map +1 -0
- package/esm/core/utility/Tuple.js +11 -0
- package/esm/core/utility/Tuple.js.map +1 -0
- package/esm/core/utility/mod.d.ts +8 -0
- package/esm/core/utility/mod.d.ts.map +1 -0
- package/esm/core/utility/mod.js +9 -0
- package/esm/core/utility/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/almost_equals.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/almost_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/array_includes.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/array_includes.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/array_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assert.d.ts +16 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assert.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assertion_error.js +31 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assertion_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equal.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equal.js +184 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equals.d.ts +35 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equals.js +59 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/exists.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/exists.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/exists.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/fail.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/fail.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/fail.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/false.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/false.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/instance_of.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/instance_of.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/is_error.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/is_error.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/is_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/mod.d.ts +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/mod.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_equals.d.ts +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_equals.js +34 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_instance_of.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_instance_of.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/object_match.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/object_match.js +161 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/object_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/rejects.d.ts +42 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/rejects.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/rejects.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/strict_equals.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/string_includes.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/string_includes.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/string_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/throws.d.ts +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/throws.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/throws.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unimplemented.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unimplemented.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unimplemented.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unreachable.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unreachable.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unreachable.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_base32_common.d.ts +17 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_base32_common.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_base32_common.js +184 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_base32_common.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +27 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/ascii85.d.ts +59 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/ascii85.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/ascii85.js +153 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/ascii85.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base32.d.ts +38 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base32.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base32.js +70 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base32.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base58.d.ts +38 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base58.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base58.js +132 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base58.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64.d.ts +38 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64.js +164 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64url.d.ts +38 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64url.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64url.js +82 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/base64url.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js +110 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/mod.d.ts +22 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/mod.js +23 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/varint.d.ts +118 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/varint.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/varint.js +208 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/varint.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +111 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +277 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +180 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +38 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +208 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +3 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js.map +1 -0
- package/esm/json_schema/Hydrated.d.ts +4 -0
- package/esm/json_schema/Hydrated.d.ts.map +1 -0
- package/esm/json_schema/Hydrated.js +49 -0
- package/esm/json_schema/Hydrated.js.map +1 -0
- package/esm/json_schema/JSONSchema.d.ts +50 -0
- package/esm/json_schema/JSONSchema.d.ts.map +1 -0
- package/esm/json_schema/JSONSchema.js +46 -0
- package/esm/json_schema/JSONSchema.js.map +1 -0
- package/esm/json_schema/MetaType.d.ts +4 -0
- package/esm/json_schema/MetaType.d.ts.map +1 -0
- package/esm/json_schema/MetaType.js +25 -0
- package/esm/json_schema/MetaType.js.map +1 -0
- package/esm/json_schema/MetaTypeMigration.d.ts +19 -0
- package/esm/json_schema/MetaTypeMigration.d.ts.map +1 -0
- package/esm/json_schema/MetaTypeMigration.js +15 -0
- package/esm/json_schema/MetaTypeMigration.js.map +1 -0
- package/esm/json_schema/PathLike.d.ts +4 -0
- package/esm/json_schema/PathLike.d.ts.map +1 -0
- package/esm/json_schema/PathLike.js +3 -0
- package/esm/json_schema/PathLike.js.map +1 -0
- package/esm/json_schema/mod.d.ts +7 -0
- package/esm/json_schema/mod.d.ts.map +1 -0
- package/esm/json_schema/mod.js +8 -0
- package/esm/json_schema/mod.js.map +1 -0
- package/esm/json_schema/toJSONSchema.d.ts +4 -0
- package/esm/json_schema/toJSONSchema.d.ts.map +1 -0
- package/esm/json_schema/toJSONSchema.js +117 -0
- package/esm/json_schema/toJSONSchema.js.map +1 -0
- package/esm/mod.d.ts +4 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +4 -0
- package/esm/mod.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/providers/OpenAI/OpenAIAdapter.d.ts +17 -0
- package/esm/providers/OpenAI/OpenAIAdapter.d.ts.map +1 -0
- package/esm/providers/OpenAI/OpenAIAdapter.js +56 -0
- package/esm/providers/OpenAI/OpenAIAdapter.js.map +1 -0
- package/esm/providers/OpenAI/OpenAIResponseFormat.d.ts +18 -0
- package/esm/providers/OpenAI/OpenAIResponseFormat.d.ts.map +1 -0
- package/esm/providers/OpenAI/OpenAIResponseFormat.js +26 -0
- package/esm/providers/OpenAI/OpenAIResponseFormat.js.map +1 -0
- package/esm/providers/OpenAI/TokenAllowance.d.ts +17 -0
- package/esm/providers/OpenAI/TokenAllowance.d.ts.map +1 -0
- package/esm/providers/OpenAI/TokenAllowance.js +32 -0
- package/esm/providers/OpenAI/TokenAllowance.js.map +1 -0
- package/esm/providers/OpenAI/mod.d.ts +6 -0
- package/esm/providers/OpenAI/mod.d.ts.map +1 -0
- package/esm/providers/OpenAI/mod.js +7 -0
- package/esm/providers/OpenAI/mod.js.map +1 -0
- package/esm/providers/OpenAI/openai_util.d.ts +4 -0
- package/esm/providers/OpenAI/openai_util.d.ts.map +1 -0
- package/esm/providers/OpenAI/openai_util.js +14 -0
- package/esm/providers/OpenAI/openai_util.js.map +1 -0
- package/esm/providers/OpenAI/refine.d.ts +2 -0
- package/esm/providers/OpenAI/refine.d.ts.map +1 -0
- package/esm/providers/OpenAI/refine.js +166 -0
- package/esm/providers/OpenAI/refine.js.map +1 -0
- package/esm/util/ArrayOfLength.d.ts +2 -0
- package/esm/util/ArrayOfLength.d.ts.map +1 -0
- package/esm/util/ArrayOfLength.js +2 -0
- package/esm/util/ArrayOfLength.js.map +1 -0
- package/esm/util/PromiseOr.d.ts +2 -0
- package/esm/util/PromiseOr.d.ts.map +1 -0
- package/esm/util/PromiseOr.js +2 -0
- package/esm/util/PromiseOr.js.map +1 -0
- package/esm/util/WeakMemo.d.ts +7 -0
- package/esm/util/WeakMemo.d.ts.map +1 -0
- package/esm/util/WeakMemo.js +32 -0
- package/esm/util/WeakMemo.js.map +1 -0
- package/esm/util/collect.d.ts +2 -0
- package/esm/util/collect.d.ts.map +1 -0
- package/esm/util/collect.js +8 -0
- package/esm/util/collect.js.map +1 -0
- package/esm/util/isPromise.d.ts +2 -0
- package/esm/util/isPromise.d.ts.map +1 -0
- package/esm/util/isPromise.js +7 -0
- package/esm/util/isPromise.js.map +1 -0
- package/esm/util/isTemplateStringsArray.d.ts +2 -0
- package/esm/util/isTemplateStringsArray.d.ts.map +1 -0
- package/esm/util/isTemplateStringsArray.js +4 -0
- package/esm/util/isTemplateStringsArray.js.map +1 -0
- package/esm/util/mod.d.ts +10 -0
- package/esm/util/mod.d.ts.map +1 -0
- package/esm/util/mod.js +11 -0
- package/esm/util/mod.js.map +1 -0
- package/esm/util/recombine.d.ts +2 -0
- package/esm/util/recombine.d.ts.map +1 -0
- package/esm/util/recombine.js +11 -0
- package/esm/util/recombine.js.map +1 -0
- package/esm/util/splitLast.d.ts +2 -0
- package/esm/util/splitLast.d.ts.map +1 -0
- package/esm/util/splitLast.js +8 -0
- package/esm/util/splitLast.js.map +1 -0
- package/esm/util/type_util.d.ts +5 -0
- package/esm/util/type_util.d.ts.map +1 -0
- package/esm/util/type_util.js +2 -0
- package/esm/util/type_util.js.map +1 -0
- package/package.json +22 -0
- package/src/_dnt.shims.ts +60 -0
- package/src/client/Adapter.ts +50 -0
- package/src/client/Liminal.ts +113 -0
- package/src/client/Tool.ts +17 -0
- package/src/client/constants.ts +6 -0
- package/src/client/mod.ts +6 -0
- package/src/core/DescriptionContext.ts +89 -0
- package/src/core/L.ts +3 -0
- package/src/core/ReduceDependencies.ts +9 -0
- package/src/core/Type.ts +45 -0
- package/src/core/TypeVisitor.ts +44 -0
- package/src/core/annotations/Annotation.ts +14 -0
- package/src/core/annotations/Assertion.ts +18 -0
- package/src/core/annotations/Description.ts +16 -0
- package/src/core/annotations/Param.ts +30 -0
- package/src/core/annotations/Template.ts +11 -0
- package/src/core/annotations/mod.ts +7 -0
- package/src/core/assert.ts +145 -0
- package/src/core/declareIntrinsic.ts +45 -0
- package/src/core/deserialize.ts +36 -0
- package/src/core/display.ts +68 -0
- package/src/core/inspect.node.ts +13 -0
- package/src/core/intrinsics.ts +86 -0
- package/src/core/intrinsics_util.ts +50 -0
- package/src/core/isType.ts +20 -0
- package/src/core/mod.ts +15 -0
- package/src/core/signature.ts +90 -0
- package/src/core/utility/Flatten.ts +14 -0
- package/src/core/utility/Intersection.ts +24 -0
- package/src/core/utility/Option.ts +6 -0
- package/src/core/utility/Record.ts +7 -0
- package/src/core/utility/Set.ts +8 -0
- package/src/core/utility/TaggedUnion.ts +23 -0
- package/src/core/utility/Tuple.ts +24 -0
- package/src/core/utility/mod.ts +9 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/almost_equals.ts +55 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/array_includes.ts +57 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/assert.ts +23 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/assertion_error.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/equal.ts +210 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/equals.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/exists.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/fail.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/false.ts +26 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/greater.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/instance_of.ts +64 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/is_error.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/less.ts +29 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/less_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/mod.ts +47 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/not_equals.ts +37 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/not_instance_of.ts +33 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/not_match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.ts +42 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/object_match.ts +203 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/rejects.ts +123 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/strict_equals.ts +67 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/string_includes.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/throws.ts +111 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/unimplemented.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.10/unreachable.ts +21 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/_base32_common.ts +218 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.ts +29 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/ascii85.ts +203 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/base32.ts +73 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/base58.ts +173 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/base64.ts +174 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/base64url.ts +88 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/hex.ts +120 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/mod.ts +24 -0
- package/src/deps/jsr.io/@std/encoding/1.0.6/varint.ts +242 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +134 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +317 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +204 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +39 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +233 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +18 -0
- package/src/json_schema/Hydrated.ts +52 -0
- package/src/json_schema/JSONSchema.ts +95 -0
- package/src/json_schema/MetaType.ts +32 -0
- package/src/json_schema/MetaTypeMigration.ts +31 -0
- package/src/json_schema/PathLike.ts +9 -0
- package/src/json_schema/mod.ts +8 -0
- package/src/json_schema/toJSONSchema.ts +114 -0
- package/src/mod.ts +3 -0
- package/src/providers/OpenAI/OpenAIAdapter.ts +89 -0
- package/src/providers/OpenAI/OpenAIResponseFormat.ts +54 -0
- package/src/providers/OpenAI/TokenAllowance.ts +29 -0
- package/src/providers/OpenAI/mod.ts +7 -0
- package/src/providers/OpenAI/openai_util.ts +19 -0
- package/src/providers/OpenAI/refine.ts +171 -0
- package/src/util/ArrayOfLength.ts +5 -0
- package/src/util/PromiseOr.ts +1 -0
- package/src/util/WeakMemo.ts +13 -0
- package/src/util/collect.ts +7 -0
- package/src/util/isPromise.ts +8 -0
- package/src/util/isTemplateStringsArray.ts +3 -0
- package/src/util/mod.ts +11 -0
- package/src/util/recombine.ts +10 -0
- package/src/util/splitLast.ts +7 -0
- package/src/util/type_util.ts +3 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Copyright (c) 2014 Jameson Little. MIT License.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* common code for base32 and base32hex encodings.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { validateBinaryLike } from "./_validate_binary_like.js";
|
|
10
|
+
|
|
11
|
+
const placeHolderPadLookup = [0, 1, , 2, 3, , 4];
|
|
12
|
+
|
|
13
|
+
function getPadLength(placeHoldersLen: number): number {
|
|
14
|
+
const maybeLen = placeHolderPadLookup[placeHoldersLen];
|
|
15
|
+
if (typeof maybeLen !== "number") {
|
|
16
|
+
throw new Error("Invalid pad length");
|
|
17
|
+
}
|
|
18
|
+
return maybeLen;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getLens(b32: string): [number, number] {
|
|
22
|
+
const len = b32.length;
|
|
23
|
+
|
|
24
|
+
if (len % 8 > 0) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Cannot decode base32 string as the length must be a multiple of 8: received length ${len}`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let validLen = b32.indexOf("=");
|
|
31
|
+
if (validLen === -1) validLen = len;
|
|
32
|
+
|
|
33
|
+
const placeHoldersLen = validLen === len ? 0 : 8 - (validLen % 8);
|
|
34
|
+
|
|
35
|
+
return [validLen, placeHoldersLen];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getByteLength(validLen: number, placeHoldersLen: number): number {
|
|
39
|
+
return ((validLen + placeHoldersLen) * 5) / 8 - getPadLength(placeHoldersLen);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Decodes an encoded string with the given lookup table.
|
|
44
|
+
*
|
|
45
|
+
* @param b32 The string to encode.
|
|
46
|
+
* @param lookup The lookup table
|
|
47
|
+
* @returns The encoded string.
|
|
48
|
+
*/
|
|
49
|
+
export function decode(b32: string, lookup: ReadonlyArray<string>): Uint8Array {
|
|
50
|
+
const revLookup: number[] = [];
|
|
51
|
+
lookup.forEach((c, i) => (revLookup[c.charCodeAt(0)] = i));
|
|
52
|
+
|
|
53
|
+
let tmp: number;
|
|
54
|
+
const [validLen, placeHoldersLen] = getLens(b32);
|
|
55
|
+
|
|
56
|
+
const arr = new Uint8Array(getByteLength(validLen, placeHoldersLen));
|
|
57
|
+
|
|
58
|
+
let curByte = 0;
|
|
59
|
+
|
|
60
|
+
// if there are placeholders, only get up to the last complete 8 chars
|
|
61
|
+
const len = placeHoldersLen > 0 ? validLen - 8 : validLen;
|
|
62
|
+
|
|
63
|
+
let i: number;
|
|
64
|
+
for (i = 0; i < len; i += 8) {
|
|
65
|
+
tmp = (revLookup[b32.charCodeAt(i)]! << 20) |
|
|
66
|
+
(revLookup[b32.charCodeAt(i + 1)]! << 15) |
|
|
67
|
+
(revLookup[b32.charCodeAt(i + 2)]! << 10) |
|
|
68
|
+
(revLookup[b32.charCodeAt(i + 3)]! << 5) |
|
|
69
|
+
revLookup[b32.charCodeAt(i + 4)]!;
|
|
70
|
+
arr[curByte++] = (tmp >> 17) & 0xff;
|
|
71
|
+
arr[curByte++] = (tmp >> 9) & 0xff;
|
|
72
|
+
arr[curByte++] = (tmp >> 1) & 0xff;
|
|
73
|
+
|
|
74
|
+
tmp = ((tmp & 1) << 15) |
|
|
75
|
+
(revLookup[b32.charCodeAt(i + 5)]! << 10) |
|
|
76
|
+
(revLookup[b32.charCodeAt(i + 6)]! << 5) |
|
|
77
|
+
revLookup[b32.charCodeAt(i + 7)]!;
|
|
78
|
+
arr[curByte++] = (tmp >> 8) & 0xff;
|
|
79
|
+
arr[curByte++] = tmp & 0xff;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (placeHoldersLen === 1) {
|
|
83
|
+
tmp = (revLookup[b32.charCodeAt(i)]! << 20) |
|
|
84
|
+
(revLookup[b32.charCodeAt(i + 1)]! << 15) |
|
|
85
|
+
(revLookup[b32.charCodeAt(i + 2)]! << 10) |
|
|
86
|
+
(revLookup[b32.charCodeAt(i + 3)]! << 5) |
|
|
87
|
+
revLookup[b32.charCodeAt(i + 4)]!;
|
|
88
|
+
arr[curByte++] = (tmp >> 17) & 0xff;
|
|
89
|
+
arr[curByte++] = (tmp >> 9) & 0xff;
|
|
90
|
+
arr[curByte++] = (tmp >> 1) & 0xff;
|
|
91
|
+
tmp = ((tmp & 1) << 7) |
|
|
92
|
+
(revLookup[b32.charCodeAt(i + 5)]! << 2) |
|
|
93
|
+
(revLookup[b32.charCodeAt(i + 6)]! >> 3);
|
|
94
|
+
arr[curByte++] = tmp & 0xff;
|
|
95
|
+
} else if (placeHoldersLen === 3) {
|
|
96
|
+
tmp = (revLookup[b32.charCodeAt(i)]! << 19) |
|
|
97
|
+
(revLookup[b32.charCodeAt(i + 1)]! << 14) |
|
|
98
|
+
(revLookup[b32.charCodeAt(i + 2)]! << 9) |
|
|
99
|
+
(revLookup[b32.charCodeAt(i + 3)]! << 4) |
|
|
100
|
+
(revLookup[b32.charCodeAt(i + 4)]! >> 1);
|
|
101
|
+
arr[curByte++] = (tmp >> 16) & 0xff;
|
|
102
|
+
arr[curByte++] = (tmp >> 8) & 0xff;
|
|
103
|
+
arr[curByte++] = tmp & 0xff;
|
|
104
|
+
} else if (placeHoldersLen === 4) {
|
|
105
|
+
tmp = (revLookup[b32.charCodeAt(i)]! << 11) |
|
|
106
|
+
(revLookup[b32.charCodeAt(i + 1)]! << 6) |
|
|
107
|
+
(revLookup[b32.charCodeAt(i + 2)]! << 1) |
|
|
108
|
+
(revLookup[b32.charCodeAt(i + 3)]! >> 4);
|
|
109
|
+
arr[curByte++] = (tmp >> 8) & 0xff;
|
|
110
|
+
arr[curByte++] = tmp & 0xff;
|
|
111
|
+
} else if (placeHoldersLen === 6) {
|
|
112
|
+
tmp = (revLookup[b32.charCodeAt(i)]! << 3) |
|
|
113
|
+
(revLookup[b32.charCodeAt(i + 1)]! >> 2);
|
|
114
|
+
arr[curByte++] = tmp & 0xff;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return arr;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function encodeChunk(
|
|
121
|
+
uint8: Uint8Array,
|
|
122
|
+
start: number,
|
|
123
|
+
end: number,
|
|
124
|
+
lookup: ReadonlyArray<string>,
|
|
125
|
+
): string {
|
|
126
|
+
let tmp: number;
|
|
127
|
+
const output = [];
|
|
128
|
+
for (let i = start; i < end; i += 5) {
|
|
129
|
+
tmp = ((uint8[i]! << 16) & 0xff0000) |
|
|
130
|
+
((uint8[i + 1]! << 8) & 0xff00) |
|
|
131
|
+
(uint8[i + 2]! & 0xff);
|
|
132
|
+
output.push(lookup[(tmp >> 19) & 0x1f]);
|
|
133
|
+
output.push(lookup[(tmp >> 14) & 0x1f]);
|
|
134
|
+
output.push(lookup[(tmp >> 9) & 0x1f]);
|
|
135
|
+
output.push(lookup[(tmp >> 4) & 0x1f]);
|
|
136
|
+
tmp = ((tmp & 0xf) << 16) |
|
|
137
|
+
((uint8[i + 3]! << 8) & 0xff00) |
|
|
138
|
+
(uint8[i + 4]! & 0xff);
|
|
139
|
+
output.push(lookup[(tmp >> 15) & 0x1f]);
|
|
140
|
+
output.push(lookup[(tmp >> 10) & 0x1f]);
|
|
141
|
+
output.push(lookup[(tmp >> 5) & 0x1f]);
|
|
142
|
+
output.push(lookup[tmp & 0x1f]);
|
|
143
|
+
}
|
|
144
|
+
return output.join("");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Encodes the given data using the lookup table.
|
|
149
|
+
*
|
|
150
|
+
* @param data The data to encode.
|
|
151
|
+
* @param lookup The lookup table.
|
|
152
|
+
* @returns The encoded string.
|
|
153
|
+
*/
|
|
154
|
+
export function encode(
|
|
155
|
+
data: ArrayBuffer | Uint8Array | string,
|
|
156
|
+
lookup: ReadonlyArray<string>,
|
|
157
|
+
): string {
|
|
158
|
+
const uint8 = validateBinaryLike(data);
|
|
159
|
+
|
|
160
|
+
let tmp: number;
|
|
161
|
+
const len = uint8.length;
|
|
162
|
+
const extraBytes = len % 5;
|
|
163
|
+
const parts = [];
|
|
164
|
+
const maxChunkLength = 16385; // must be multiple of 5
|
|
165
|
+
const len2 = len - extraBytes;
|
|
166
|
+
|
|
167
|
+
// go through the array every 5 bytes, we'll deal with trailing stuff later
|
|
168
|
+
for (let i = 0; i < len2; i += maxChunkLength) {
|
|
169
|
+
parts.push(
|
|
170
|
+
encodeChunk(
|
|
171
|
+
uint8,
|
|
172
|
+
i,
|
|
173
|
+
i + maxChunkLength > len2 ? len2 : i + maxChunkLength,
|
|
174
|
+
lookup,
|
|
175
|
+
),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
180
|
+
if (extraBytes === 4) {
|
|
181
|
+
tmp = ((uint8[len2]! & 0xff) << 16) |
|
|
182
|
+
((uint8[len2 + 1]! & 0xff) << 8) |
|
|
183
|
+
(uint8[len2 + 2]! & 0xff);
|
|
184
|
+
parts.push(lookup[(tmp >> 19) & 0x1f]);
|
|
185
|
+
parts.push(lookup[(tmp >> 14) & 0x1f]);
|
|
186
|
+
parts.push(lookup[(tmp >> 9) & 0x1f]);
|
|
187
|
+
parts.push(lookup[(tmp >> 4) & 0x1f]);
|
|
188
|
+
tmp = ((tmp & 0xf) << 11) | (uint8[len2 + 3]! << 3);
|
|
189
|
+
parts.push(lookup[(tmp >> 10) & 0x1f]);
|
|
190
|
+
parts.push(lookup[(tmp >> 5) & 0x1f]);
|
|
191
|
+
parts.push(lookup[tmp & 0x1f]);
|
|
192
|
+
parts.push("=");
|
|
193
|
+
} else if (extraBytes === 3) {
|
|
194
|
+
tmp = ((uint8[len2]! & 0xff) << 17) |
|
|
195
|
+
((uint8[len2 + 1]! & 0xff) << 9) |
|
|
196
|
+
((uint8[len2 + 2]! & 0xff) << 1);
|
|
197
|
+
parts.push(lookup[(tmp >> 20) & 0x1f]);
|
|
198
|
+
parts.push(lookup[(tmp >> 15) & 0x1f]);
|
|
199
|
+
parts.push(lookup[(tmp >> 10) & 0x1f]);
|
|
200
|
+
parts.push(lookup[(tmp >> 5) & 0x1f]);
|
|
201
|
+
parts.push(lookup[tmp & 0x1f]);
|
|
202
|
+
parts.push("===");
|
|
203
|
+
} else if (extraBytes === 2) {
|
|
204
|
+
tmp = ((uint8[len2]! & 0xff) << 12) | ((uint8[len2 + 1]! & 0xff) << 4);
|
|
205
|
+
parts.push(lookup[(tmp >> 15) & 0x1f]);
|
|
206
|
+
parts.push(lookup[(tmp >> 10) & 0x1f]);
|
|
207
|
+
parts.push(lookup[(tmp >> 5) & 0x1f]);
|
|
208
|
+
parts.push(lookup[tmp & 0x1f]);
|
|
209
|
+
parts.push("====");
|
|
210
|
+
} else if (extraBytes === 1) {
|
|
211
|
+
tmp = (uint8[len2]! & 0xff) << 2;
|
|
212
|
+
parts.push(lookup[(tmp >> 5) & 0x1f]);
|
|
213
|
+
parts.push(lookup[tmp & 0x1f]);
|
|
214
|
+
parts.push("======");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return parts.join("");
|
|
218
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
|
|
5
|
+
function getTypeName(value: unknown): string {
|
|
6
|
+
const type = typeof value;
|
|
7
|
+
if (type !== "object") {
|
|
8
|
+
return type;
|
|
9
|
+
} else if (value === null) {
|
|
10
|
+
return "null";
|
|
11
|
+
} else {
|
|
12
|
+
return value?.constructor?.name ?? "object";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function validateBinaryLike(source: unknown): Uint8Array {
|
|
17
|
+
if (typeof source === "string") {
|
|
18
|
+
return encoder.encode(source);
|
|
19
|
+
} else if (source instanceof Uint8Array) {
|
|
20
|
+
return source;
|
|
21
|
+
} else if (source instanceof ArrayBuffer) {
|
|
22
|
+
return new Uint8Array(source);
|
|
23
|
+
}
|
|
24
|
+
throw new TypeError(
|
|
25
|
+
`Cannot validate the input as it must be a Uint8Array, a string, or an ArrayBuffer: received a value of the type ${
|
|
26
|
+
getTypeName(source)
|
|
27
|
+
}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for working with {@link https://en.wikipedia.org/wiki/Ascii85 | ascii85} encoding.
|
|
6
|
+
*
|
|
7
|
+
* ## Specifying a standard and delimiter
|
|
8
|
+
*
|
|
9
|
+
* By default, all functions are using the most popular Adobe version of ascii85
|
|
10
|
+
* and not adding any delimiter. However, there are three more standards
|
|
11
|
+
* supported - btoa (different delimiter and additional compression of 4 bytes
|
|
12
|
+
* equal to 32), {@link https://rfc.zeromq.org/spec/32/ | Z85} and
|
|
13
|
+
* {@link https://www.rfc-editor.org/rfc/rfc1924.html | RFC 1924}. It's possible to use a
|
|
14
|
+
* different encoding by specifying it in `options` object as a second parameter.
|
|
15
|
+
*
|
|
16
|
+
* Similarly, it's possible to make `encode` add a delimiter (`<~` and `~>` for
|
|
17
|
+
* Adobe, `xbtoa Begin` and `xbtoa End` with newlines between the delimiters and
|
|
18
|
+
* encoded data for btoa. Checksums for btoa are not supported. Delimiters are not
|
|
19
|
+
* supported by other encodings.)
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { validateBinaryLike } from "./_validate_binary_like.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Supported ascii85 standards for {@linkcode EncodeAscii85Options} and
|
|
28
|
+
* {@linkcode DecodeAscii85Options}.
|
|
29
|
+
*/
|
|
30
|
+
export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85";
|
|
31
|
+
|
|
32
|
+
/** Options for {@linkcode encodeAscii85}. */
|
|
33
|
+
export interface EncodeAscii85Options {
|
|
34
|
+
/**
|
|
35
|
+
* Character set and delimiter (if supported and used).
|
|
36
|
+
*
|
|
37
|
+
* @default {"Adobe"}
|
|
38
|
+
*/
|
|
39
|
+
standard?: Ascii85Standard;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to use a delimiter (if supported).
|
|
42
|
+
*
|
|
43
|
+
* @default {false}
|
|
44
|
+
*/
|
|
45
|
+
delimiter?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const rfc1924 =
|
|
49
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~" as const;
|
|
50
|
+
const Z85 =
|
|
51
|
+
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#" as const;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Converts data into an ascii85-encoded string.
|
|
55
|
+
*
|
|
56
|
+
* @param data The data to encode.
|
|
57
|
+
* @param options Options for encoding.
|
|
58
|
+
*
|
|
59
|
+
* @returns The ascii85-encoded string.
|
|
60
|
+
*
|
|
61
|
+
* @example Usage
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { encodeAscii85 } from "@std/encoding/ascii85";
|
|
64
|
+
* import { assertEquals } from "@std/assert";
|
|
65
|
+
*
|
|
66
|
+
* assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function encodeAscii85(
|
|
70
|
+
data: ArrayBuffer | Uint8Array | string,
|
|
71
|
+
options: EncodeAscii85Options = {},
|
|
72
|
+
): string {
|
|
73
|
+
let uint8 = validateBinaryLike(data);
|
|
74
|
+
|
|
75
|
+
const { standard = "Adobe" } = options;
|
|
76
|
+
|
|
77
|
+
let output: string[] = [];
|
|
78
|
+
let v: number;
|
|
79
|
+
let n = 0;
|
|
80
|
+
let difference = 0;
|
|
81
|
+
if (uint8.length % 4 !== 0) {
|
|
82
|
+
const tmp = uint8;
|
|
83
|
+
difference = 4 - (tmp.length % 4);
|
|
84
|
+
uint8 = new Uint8Array(tmp.length + difference);
|
|
85
|
+
uint8.set(tmp);
|
|
86
|
+
}
|
|
87
|
+
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
|
88
|
+
for (let i = 0; i < uint8.length; i += 4) {
|
|
89
|
+
v = view.getUint32(i);
|
|
90
|
+
// Adobe and btoa standards compress 4 zeroes to single "z" character
|
|
91
|
+
if (
|
|
92
|
+
(standard === "Adobe" || standard === "btoa") &&
|
|
93
|
+
v === 0 &&
|
|
94
|
+
i < uint8.length - difference - 3
|
|
95
|
+
) {
|
|
96
|
+
output[n++] = "z";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
// btoa compresses 4 spaces - that is, bytes equal to 32 - into single "y" character
|
|
100
|
+
if (standard === "btoa" && v === 538976288) {
|
|
101
|
+
output[n++] = "y";
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (let j = 4; j >= 0; j--) {
|
|
105
|
+
output[n + j] = String.fromCharCode((v % 85) + 33);
|
|
106
|
+
v = Math.trunc(v / 85);
|
|
107
|
+
}
|
|
108
|
+
n += 5;
|
|
109
|
+
}
|
|
110
|
+
switch (standard) {
|
|
111
|
+
case "Adobe":
|
|
112
|
+
if (options?.delimiter) {
|
|
113
|
+
return `<~${output.slice(0, output.length - difference).join("")}~>`;
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
case "btoa":
|
|
117
|
+
if (options?.delimiter) {
|
|
118
|
+
return `xbtoa Begin\n${
|
|
119
|
+
output
|
|
120
|
+
.slice(0, output.length - difference)
|
|
121
|
+
.join("")
|
|
122
|
+
}\nxbtoa End`;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case "RFC 1924":
|
|
126
|
+
output = output.map((val) => rfc1924[val.charCodeAt(0) - 33]!);
|
|
127
|
+
break;
|
|
128
|
+
case "Z85":
|
|
129
|
+
output = output.map((val) => Z85[val.charCodeAt(0) - 33]!);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
return output.slice(0, output.length - difference).join("");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Options for {@linkcode decodeAscii85}. */
|
|
136
|
+
export type DecodeAscii85Options = Omit<EncodeAscii85Options, "delimiter">;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Decodes a ascii85-encoded string.
|
|
140
|
+
*
|
|
141
|
+
* @param ascii85 The ascii85-encoded string to decode.
|
|
142
|
+
* @param options Options for decoding.
|
|
143
|
+
* @returns The decoded data.
|
|
144
|
+
*
|
|
145
|
+
* @example Usage
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { decodeAscii85 } from "@std/encoding/ascii85";
|
|
148
|
+
* import { assertEquals } from "@std/assert";
|
|
149
|
+
*
|
|
150
|
+
* assertEquals(
|
|
151
|
+
* decodeAscii85("87cURD]j7BEbo80"),
|
|
152
|
+
* new TextEncoder().encode("Hello world!"),
|
|
153
|
+
* );
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export function decodeAscii85(
|
|
157
|
+
ascii85: string,
|
|
158
|
+
options: DecodeAscii85Options = {},
|
|
159
|
+
): Uint8Array {
|
|
160
|
+
const { standard = "Adobe" } = options;
|
|
161
|
+
|
|
162
|
+
// translate all encodings to most basic adobe/btoa one and decompress some special characters ("z" and "y")
|
|
163
|
+
switch (standard) {
|
|
164
|
+
case "Adobe":
|
|
165
|
+
ascii85 = ascii85.replaceAll(/(<~|~>)/g, "").replaceAll("z", "!!!!!");
|
|
166
|
+
break;
|
|
167
|
+
case "btoa":
|
|
168
|
+
ascii85 = ascii85
|
|
169
|
+
.replaceAll(/(xbtoa Begin|xbtoa End|\n)/g, "")
|
|
170
|
+
.replaceAll("z", "!!!!!")
|
|
171
|
+
.replaceAll("y", "+<VdL");
|
|
172
|
+
break;
|
|
173
|
+
case "RFC 1924":
|
|
174
|
+
ascii85 = ascii85.replaceAll(
|
|
175
|
+
/./g,
|
|
176
|
+
(match) => String.fromCharCode(rfc1924.indexOf(match) + 33),
|
|
177
|
+
);
|
|
178
|
+
break;
|
|
179
|
+
case "Z85":
|
|
180
|
+
ascii85 = ascii85.replaceAll(
|
|
181
|
+
/./g,
|
|
182
|
+
(match) => String.fromCharCode(Z85.indexOf(match) + 33),
|
|
183
|
+
);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
// remove all invalid characters
|
|
187
|
+
ascii85 = ascii85.replaceAll(/[^!-u]/g, "");
|
|
188
|
+
const len = ascii85.length;
|
|
189
|
+
const output = new Uint8Array(len + 4 - (len % 4));
|
|
190
|
+
const view = new DataView(output.buffer);
|
|
191
|
+
let v = 0;
|
|
192
|
+
let n = 0;
|
|
193
|
+
let max = 0;
|
|
194
|
+
for (let i = 0; i < len;) {
|
|
195
|
+
for (max += 5; i < max; i++) {
|
|
196
|
+
v = v * 85 + (i < len ? ascii85.charCodeAt(i) : 117) - 33;
|
|
197
|
+
}
|
|
198
|
+
view.setUint32(n, v);
|
|
199
|
+
v = 0;
|
|
200
|
+
n += 4;
|
|
201
|
+
}
|
|
202
|
+
return output.slice(0, Math.trunc(len * 0.8));
|
|
203
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Copyright (c) 2014 Jameson Little. MIT License.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utilities for
|
|
7
|
+
* {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6 | base32}
|
|
8
|
+
* encoding and decoding.
|
|
9
|
+
*
|
|
10
|
+
* Modified from {@link https://github.com/beatgammit/base64-js}.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { encodeBase32, decodeBase32 } from "@std/encoding/base32";
|
|
14
|
+
* import { assertEquals } from "@std/assert";
|
|
15
|
+
*
|
|
16
|
+
* assertEquals(encodeBase32("foobar"), "MZXW6YTBOI======");
|
|
17
|
+
*
|
|
18
|
+
* assertEquals(
|
|
19
|
+
* decodeBase32("MZXW6YTBOI======"),
|
|
20
|
+
* new TextEncoder().encode("foobar")
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { decode, encode } from "./_base32_common.js";
|
|
27
|
+
|
|
28
|
+
const lookup: string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".split("");
|
|
29
|
+
const revLookup: number[] = [];
|
|
30
|
+
lookup.forEach((c, i) => (revLookup[c.charCodeAt(0)] = i));
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Decodes a base32-encoded string.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
|
|
36
|
+
*
|
|
37
|
+
* @param b32 The base32-encoded string to decode.
|
|
38
|
+
* @returns The decoded data.
|
|
39
|
+
*
|
|
40
|
+
* @example Usage
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { decodeBase32 } from "@std/encoding/base32";
|
|
43
|
+
* import { assertEquals } from "@std/assert";
|
|
44
|
+
*
|
|
45
|
+
* assertEquals(
|
|
46
|
+
* decodeBase32("GZRTMMDDGA======"),
|
|
47
|
+
* new TextEncoder().encode("6c60c0"),
|
|
48
|
+
* );
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function decodeBase32(b32: string): Uint8Array {
|
|
52
|
+
return decode(b32, lookup);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Converts data into a base32-encoded string.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
|
|
59
|
+
*
|
|
60
|
+
* @param data The data to encode.
|
|
61
|
+
* @returns The base32-encoded string.
|
|
62
|
+
*
|
|
63
|
+
* @example Usage
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { encodeBase32 } from "@std/encoding/base32";
|
|
66
|
+
* import { assertEquals } from "@std/assert";
|
|
67
|
+
*
|
|
68
|
+
* assertEquals(encodeBase32("6c60c0"), "GZRTMMDDGA======");
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function encodeBase32(data: ArrayBuffer | Uint8Array | string): string {
|
|
72
|
+
return encode(data, lookup);
|
|
73
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for
|
|
6
|
+
* {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03 | base58}
|
|
7
|
+
* encoding and decoding.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { encodeBase58, decodeBase58 } from "@std/encoding/base58";
|
|
11
|
+
* import { assertEquals } from "@std/assert";
|
|
12
|
+
*
|
|
13
|
+
* const hello = new TextEncoder().encode("Hello World!");
|
|
14
|
+
*
|
|
15
|
+
* assertEquals(encodeBase58(hello), "2NEpo7TZRRrLZSi2U");
|
|
16
|
+
*
|
|
17
|
+
* assertEquals(decodeBase58("2NEpo7TZRRrLZSi2U"), hello);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { validateBinaryLike } from "./_validate_binary_like.js";
|
|
24
|
+
|
|
25
|
+
// deno-fmt-ignore
|
|
26
|
+
const mapBase58: Record<string, number> = {
|
|
27
|
+
"1": 0, "2": 1, "3": 2, "4": 3, "5": 4, "6": 5, "7": 6, "8": 7, "9": 8, A: 9,
|
|
28
|
+
B: 10, C: 11, D: 12, E: 13, F: 14, G: 15, H: 16, J: 17, K: 18, L: 19, M: 20,
|
|
29
|
+
N: 21, P: 22, Q: 23, R: 24, S: 25, T: 26, U: 27, V: 28, W: 29, X: 30, Y: 31,
|
|
30
|
+
Z: 32, a: 33, b: 34, c: 35, d: 36, e: 37, f: 38, g: 39, h: 40, i: 41, j: 42,
|
|
31
|
+
k: 43, m: 44, n: 45, o: 46, p: 47, q: 48, r: 49, s: 50, t: 51, u: 52, v: 53,
|
|
32
|
+
w: 54, x: 55, y: 56, z: 57
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const base58alphabet =
|
|
36
|
+
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Converts data into a base58-encoded string.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-3}
|
|
42
|
+
*
|
|
43
|
+
* @param data The data to encode.
|
|
44
|
+
* @returns The base58-encoded string.
|
|
45
|
+
*
|
|
46
|
+
* @example Usage
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { encodeBase58 } from "@std/encoding/base58";
|
|
49
|
+
* import { assertEquals } from "@std/assert";
|
|
50
|
+
*
|
|
51
|
+
* assertEquals(encodeBase58("Hello World!"), "2NEpo7TZRRrLZSi2U");
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function encodeBase58(data: ArrayBuffer | Uint8Array | string): string {
|
|
55
|
+
const uint8tData = validateBinaryLike(data);
|
|
56
|
+
|
|
57
|
+
let length = 0;
|
|
58
|
+
let zeroes = 0;
|
|
59
|
+
|
|
60
|
+
// Counting leading zeroes
|
|
61
|
+
let index = 0;
|
|
62
|
+
while (uint8tData[index] === 0) {
|
|
63
|
+
zeroes++;
|
|
64
|
+
index++;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const notZeroUint8Data = uint8tData.slice(index);
|
|
68
|
+
|
|
69
|
+
const size = Math.round((uint8tData.length * 138) / 100 + 1);
|
|
70
|
+
const b58Encoding: number[] = [];
|
|
71
|
+
|
|
72
|
+
notZeroUint8Data.forEach((byte) => {
|
|
73
|
+
let i = 0;
|
|
74
|
+
let carry = byte;
|
|
75
|
+
|
|
76
|
+
for (
|
|
77
|
+
let reverseIterator = size - 1;
|
|
78
|
+
(carry > 0 || i < length) && reverseIterator !== -1;
|
|
79
|
+
reverseIterator--, i++
|
|
80
|
+
) {
|
|
81
|
+
carry += (b58Encoding[reverseIterator] ?? 0) * 256;
|
|
82
|
+
b58Encoding[reverseIterator] = Math.round(carry % 58);
|
|
83
|
+
carry = Math.floor(carry / 58);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
length = i;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const strResult: string[] = Array.from({
|
|
90
|
+
length: b58Encoding.length + zeroes,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (zeroes > 0) {
|
|
94
|
+
strResult.fill("1", 0, zeroes);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
b58Encoding.forEach((byteValue) =>
|
|
98
|
+
strResult.push(base58alphabet[byteValue]!)
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return strResult.join("");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Decodes a base58-encoded string.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-4}
|
|
108
|
+
*
|
|
109
|
+
* @param b58 The base58-encoded string to decode.
|
|
110
|
+
* @returns The decoded data.
|
|
111
|
+
*
|
|
112
|
+
* @example Usage
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { decodeBase58 } from "@std/encoding/base58";
|
|
115
|
+
* import { assertEquals } from "@std/assert";
|
|
116
|
+
*
|
|
117
|
+
* assertEquals(
|
|
118
|
+
* decodeBase58("2NEpo7TZRRrLZSi2U"),
|
|
119
|
+
* new TextEncoder().encode("Hello World!")
|
|
120
|
+
* );
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function decodeBase58(b58: string): Uint8Array {
|
|
124
|
+
const splitInput = b58.trim().split("");
|
|
125
|
+
|
|
126
|
+
let length = 0;
|
|
127
|
+
let ones = 0;
|
|
128
|
+
|
|
129
|
+
// Counting leading ones
|
|
130
|
+
let index = 0;
|
|
131
|
+
while (splitInput[index] === "1") {
|
|
132
|
+
ones++;
|
|
133
|
+
index++;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const notZeroData = splitInput.slice(index);
|
|
137
|
+
|
|
138
|
+
const size = Math.round((b58.length * 733) / 1000 + 1);
|
|
139
|
+
const output: number[] = [];
|
|
140
|
+
|
|
141
|
+
notZeroData.forEach((char, idx) => {
|
|
142
|
+
let carry = mapBase58[char];
|
|
143
|
+
let i = 0;
|
|
144
|
+
|
|
145
|
+
if (carry === undefined) {
|
|
146
|
+
throw new TypeError(
|
|
147
|
+
`Invalid base58 char at index ${idx} with value ${char}`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (
|
|
152
|
+
let reverseIterator = size - 1;
|
|
153
|
+
(carry > 0 || i < length) && reverseIterator !== -1;
|
|
154
|
+
reverseIterator--, i++
|
|
155
|
+
) {
|
|
156
|
+
carry += 58 * (output[reverseIterator] ?? 0);
|
|
157
|
+
output[reverseIterator] = Math.round(carry % 256);
|
|
158
|
+
carry = Math.floor(carry / 256);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
length = i;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const validOutput = output.filter((item) => item !== undefined);
|
|
165
|
+
|
|
166
|
+
if (ones > 0) {
|
|
167
|
+
const onesResult = Array.from({ length: ones }).fill(0, 0, ones);
|
|
168
|
+
|
|
169
|
+
return new Uint8Array([...onesResult, ...validOutput] as number[]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return new Uint8Array(validOutput);
|
|
173
|
+
}
|