Add comprehensive installation and setup documentation

- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
This commit is contained in:
Dorian
2026-01-27 17:18:21 +00:00
parent a81f655133
commit 0d073fa89e
22658 changed files with 4494151 additions and 6 deletions

4
apps/web5-dwn/node_modules/protons-runtime/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.
MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0

64
apps/web5-dwn/node_modules/protons-runtime/README.md generated vendored Normal file
View File

@@ -0,0 +1,64 @@
# protons-runtime <!-- omit in toc -->
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/protons.svg?style=flat-square)](https://codecov.io/gh/ipfs/protons)
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/protons/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/protons/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Shared code to make your bundle smaller when running protons in your app
# About
<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->
This module contains serialization/deserialization code used when encoding/decoding protobufs.
It should be declared as a dependency of your project:
```console
npm i protons-runtime
```
# Install
```console
$ npm i protons-runtime
```
Contains shared code to reduce code duplication between modules transpiled by protons.
# API Docs
- <https://ipfs.github.io/protons/modules/protons_runtime.html>
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
# Contribute
Contributions welcome! Please check out [the issues](https://github.com/ipfs/protons/issues).
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,46 @@
import type { Writer, Reader } from './index.js';
export declare enum CODEC_TYPES {
VARINT = 0,
BIT64 = 1,
LENGTH_DELIMITED = 2,
START_GROUP = 3,
END_GROUP = 4,
BIT32 = 5
}
export interface EncodeOptions {
lengthDelimited?: boolean;
writeDefaults?: boolean;
}
export interface EncodeFunction<T> {
(value: Partial<T>, writer: Writer, opts?: EncodeOptions): void;
}
type CollectionTypes = any[] | Map<any, any>;
type PrimitiveTypes = boolean | number | string | bigint | Uint8Array;
type CollectionLimits<T> = {
[K in keyof T]: T[K] extends CollectionTypes ? number : T[K] extends PrimitiveTypes ? never : Limits<T[K]>;
};
type ArrayElementLimits<T> = {
[K in keyof T as `${string & K}$`]: T[K] extends Array<infer ElementType> ? (ElementType extends PrimitiveTypes ? never : Limits<ElementType>) : (T[K] extends PrimitiveTypes ? never : Limits<T[K]>);
};
type MapValueLimits<T> = {
[K in keyof T as `${string & K}$value`]: T[K] extends Map<any, infer MapValueType> ? (MapValueType extends PrimitiveTypes ? never : Limits<MapValueType>) : (T[K] extends PrimitiveTypes ? never : Limits<T[K]>);
};
type Limits<T> = Partial<CollectionLimits<T> & ArrayElementLimits<T> & MapValueLimits<T>>;
export interface DecodeOptions<T> {
/**
* Runtime-specified limits for lengths of repeated/map fields
*/
limits?: Limits<T>;
}
export interface DecodeFunction<T> {
(reader: Reader, length?: number, opts?: DecodeOptions<T>): T;
}
export interface Codec<T> {
name: string;
type: CODEC_TYPES;
encode: EncodeFunction<T>;
decode: DecodeFunction<T>;
}
export declare function createCodec<T>(name: string, type: CODEC_TYPES, encode: EncodeFunction<T>, decode: DecodeFunction<T>): Codec<T>;
export {};
//# sourceMappingURL=codec.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGhD,oBAAY,WAAW;IACrB,MAAM,IAAI;IACV,KAAK,IAAA;IACL,gBAAgB,IAAA;IAChB,WAAW,IAAA;IACX,SAAS,IAAA;IACT,KAAK,IAAA;CACN;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;CAChE;AAGD,KAAK,eAAe,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAG5C,KAAK,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAA;AAGrE,KAAK,gBAAgB,CAAE,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,eAAe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AC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;CAC9D;AAED,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;CAC1B;AAED,wBAAgB,WAAW,CAAE,CAAC,EAAG,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAOhI"}

View File

@@ -0,0 +1,19 @@
// https://developers.google.com/protocol-buffers/docs/encoding#structure
export var CODEC_TYPES;
(function (CODEC_TYPES) {
CODEC_TYPES[CODEC_TYPES["VARINT"] = 0] = "VARINT";
CODEC_TYPES[CODEC_TYPES["BIT64"] = 1] = "BIT64";
CODEC_TYPES[CODEC_TYPES["LENGTH_DELIMITED"] = 2] = "LENGTH_DELIMITED";
CODEC_TYPES[CODEC_TYPES["START_GROUP"] = 3] = "START_GROUP";
CODEC_TYPES[CODEC_TYPES["END_GROUP"] = 4] = "END_GROUP";
CODEC_TYPES[CODEC_TYPES["BIT32"] = 5] = "BIT32";
})(CODEC_TYPES || (CODEC_TYPES = {}));
export function createCodec(name, type, encode, decode) {
return {
name,
type,
encode,
decode
};
}
//# sourceMappingURL=codec.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,CAAN,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,iDAAU,CAAA;IACV,+CAAK,CAAA;IACL,qEAAgB,CAAA;IAChB,2DAAW,CAAA;IACX,uDAAS,CAAA;IACT,+CAAK,CAAA;AACP,CAAC,EAPW,WAAW,KAAX,WAAW,QAOtB;AA0DD,MAAM,UAAU,WAAW,CAAM,IAAY,EAAE,IAAiB,EAAE,MAAyB,EAAE,MAAyB;IACpH,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,MAAM;KACP,CAAA;AACH,CAAC"}

View File

@@ -0,0 +1,3 @@
import type { Codec } from '../codec.js';
export declare function enumeration<T>(v: any): Codec<T>;
//# sourceMappingURL=enum.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../src/codecs/enum.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkC,KAAK,EAAE,MAAM,aAAa,CAAA;AAExE,wBAAgB,WAAW,CAAE,CAAC,EAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAyBjD"}

View File

@@ -0,0 +1,22 @@
import { createCodec, CODEC_TYPES } from '../codec.js';
export function enumeration(v) {
function findValue(val) {
// Use the reverse mapping to look up the enum key for the stored value
// https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
if (v[val.toString()] == null) {
throw new Error('Invalid enum value');
}
return v[val];
}
const encode = function enumEncode(val, writer) {
const enumValue = findValue(val);
writer.int32(enumValue);
};
const decode = function enumDecode(reader) {
const val = reader.int32();
return findValue(val);
};
// @ts-expect-error yeah yeah
return createCodec('enum', CODEC_TYPES.VARINT, encode, decode);
}
//# sourceMappingURL=enum.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../src/codecs/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGtD,MAAM,UAAU,WAAW,CAAM,CAAM;IACrC,SAAS,SAAS,CAAE,GAAoB;QACtC,uEAAuE;QACvE,2EAA2E;QAC3E,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;QACvC,CAAC;QAED,OAAO,CAAC,CAAC,GAAG,CAAC,CAAA;IACf,CAAC;IAED,MAAM,MAAM,GAAoC,SAAS,UAAU,CAAE,GAAG,EAAE,MAAM;QAC9E,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;QAEhC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACzB,CAAC,CAAA;IAED,MAAM,MAAM,GAAoC,SAAS,UAAU,CAAE,MAAM;QACzE,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;QAE1B,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC,CAAA;IAED,6BAA6B;IAC7B,OAAO,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAChE,CAAC"}

View File

@@ -0,0 +1,6 @@
import type { EncodeFunction, DecodeFunction, Codec } from '../codec.js';
export interface Factory<A, T> {
new (obj: A): T;
}
export declare function message<T>(encode: EncodeFunction<T>, decode: DecodeFunction<T>): Codec<T>;
//# sourceMappingURL=message.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/codecs/message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExE,MAAM,WAAW,OAAO,CAAC,CAAC,EAAE,CAAC;IAC3B,KAAK,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;CAChB;AAED,wBAAgB,OAAO,CAAE,CAAC,EAAG,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAE3F"}

View File

@@ -0,0 +1,5 @@
import { createCodec, CODEC_TYPES } from '../codec.js';
export function message(encode, decode) {
return createCodec('message', CODEC_TYPES.LENGTH_DELIMITED, encode, decode);
}
//# sourceMappingURL=message.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/codecs/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAOtD,MAAM,UAAU,OAAO,CAAM,MAAyB,EAAE,MAAyB;IAC/E,OAAO,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAC7E,CAAC"}

View File

@@ -0,0 +1,4 @@
import type { Codec, DecodeOptions } from './codec.js';
import type { Uint8ArrayList } from 'uint8arraylist';
export declare function decodeMessage<T>(buf: Uint8Array | Uint8ArrayList, codec: Pick<Codec<T>, 'decode'>, opts?: DecodeOptions<T>): T;
//# sourceMappingURL=decode.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,wBAAgB,aAAa,CAAE,CAAC,EAAG,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAIhI"}

View File

@@ -0,0 +1,6 @@
import { createReader } from './utils/reader.js';
export function decodeMessage(buf, codec, opts) {
const reader = createReader(buf);
return codec.decode(reader, undefined, opts);
}
//# sourceMappingURL=decode.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIhD,MAAM,UAAU,aAAa,CAAM,GAAgC,EAAE,KAA+B,EAAE,IAAuB;IAC3H,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;IAEhC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;AAC9C,CAAC"}

View File

@@ -0,0 +1,3 @@
import type { Codec } from './codec.js';
export declare function encodeMessage<T>(message: Partial<T>, codec: Pick<Codec<T>, 'encode'>): Uint8Array;
//# sourceMappingURL=encode.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,wBAAgB,aAAa,CAAE,CAAC,EAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,UAAU,CAQnG"}

View File

@@ -0,0 +1,9 @@
import { createWriter } from './utils/writer.js';
export function encodeMessage(message, codec) {
const w = createWriter();
codec.encode(message, w, {
lengthDelimited: false
});
return w.finish();
}
//# sourceMappingURL=encode.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,MAAM,UAAU,aAAa,CAAM,OAAmB,EAAE,KAA+B;IACrF,MAAM,CAAC,GAAG,YAAY,EAAE,CAAA;IAExB,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE;QACvB,eAAe,EAAE,KAAK;KACvB,CAAC,CAAA;IAEF,OAAO,CAAC,CAAC,MAAM,EAAE,CAAA;AACnB,CAAC"}

View File

@@ -0,0 +1,323 @@
/**
* @packageDocumentation
*
* This module contains serialization/deserialization code used when encoding/decoding protobufs.
*
* It should be declared as a dependency of your project:
*
* ```console
* npm i protons-runtime
* ```
*/
import type { Codec } from './codec.js';
export interface FieldDef {
name: string;
codec: Codec<any>;
optional?: true;
repeats?: true;
packed?: true;
}
export { decodeMessage } from './decode.js';
export { encodeMessage } from './encode.js';
export { enumeration } from './codecs/enum.js';
export { message } from './codecs/message.js';
export { createReader as reader } from './utils/reader.js';
export { createWriter as writer } from './utils/writer.js';
export type { Codec, EncodeOptions, DecodeOptions } from './codec.js';
export interface Writer {
/**
* Current length
*/
len: number;
/**
* Writes an unsigned 32 bit value as a varint
*/
uint32(value: number): this;
/**
* Writes a signed 32 bit value as a varint`
*/
int32(value: number): this;
/**
* Writes a 32 bit value as a varint, zig-zag encoded
*/
sint32(value: number): this;
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64(value: bigint): this;
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64Number(value: number): this;
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64String(value: string): this;
/**
* Writes a signed 64 bit value as a varint
*/
int64(value: bigint): this;
/**
* Writes a signed 64 bit value as a varint
*/
int64Number(value: number): this;
/**
* Writes a signed 64 bit value as a varint
*/
int64String(value: string): this;
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64(value: bigint): this;
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64Number(value: number): this;
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64String(value: string): this;
/**
* Writes a boolish value as a varint
*/
bool(value: boolean): this;
/**
* Writes an unsigned 32 bit value as fixed 32 bits
*/
fixed32(value: number): this;
/**
* Writes a signed 32 bit value as fixed 32 bits
*/
sfixed32(value: number): this;
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64(value: bigint): this;
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64Number(value: number): this;
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64String(value: string): this;
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64(value: bigint): this;
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64Number(value: number): this;
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64String(value: string): this;
/**
* Writes a float (32 bit)
*/
float(value: number): this;
/**
* Writes a double (64 bit float)
*/
double(value: number): this;
/**
* Writes a sequence of bytes
*/
bytes(value: Uint8Array): this;
/**
* Writes a string
*/
string(value: string): this;
/**
* Forks this writer's state by pushing it to a stack.
* Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
*/
fork(): this;
/**
* Resets this instance to the last state.
*/
reset(): this;
/**
* Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
*/
ldelim(): this;
/**
* Finishes the write operation
*/
finish(): Uint8Array;
}
export interface Reader {
/**
* Read buffer
*/
buf: Uint8Array;
/**
* Read buffer position
*/
pos: number;
/**
* Read buffer length
*/
len: number;
/**
* Reads a varint as an unsigned 32 bit value
*/
uint32(): number;
/**
* Reads a varint as a signed 32 bit value
*/
int32(): number;
/**
* Reads a zig-zag encoded varint as a signed 32 bit value
*/
sint32(): number;
/**
* Reads a varint as a boolean
*/
bool(): boolean;
/**
* Reads fixed 32 bits as an unsigned 32 bit integer
*/
fixed32(): number;
/**
* Reads fixed 32 bits as a signed 32 bit integer
*/
sfixed32(): number;
/**
* Reads a float (32 bit) as a number
*/
float(): number;
/**
* Reads a double (64 bit float) as a number
*/
double(): number;
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes(): Uint8Array;
/**
* Reads a string preceded by its byte length as a varint
*/
string(): string;
/**
* Skips the specified number of bytes if specified, otherwise skips a varints`
*/
skip(length?: number): void;
/**
* Skips the next element of the specified wire type
*/
skipType(wireType: number): void;
/**
* Reads a varint as a signed 64 bit value
*/
int64(): bigint;
/**
* Reads a varint as a signed 64 bit value
*/
int64Number(): number;
/**
* Reads a varint as a signed 64 bit value
*/
int64String(): string;
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64(): bigint;
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64Number(): number;
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64String(): string;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64(): bigint;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64Number(): number;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64String(): string;
/**
* Reads fixed 64 bits
*/
fixed64(): bigint;
/**
* Reads fixed 64 bits
*/
fixed64Number(): number;
/**
* Reads fixed 64 bits
*/
fixed64String(): string;
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64(): bigint;
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64Number(): number;
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64String(): string;
}
/**
* This will be removed in a future release
*
* @deprecated
*/
export declare class CodeError extends Error {
code: string;
constructor(message: string, code: string);
}
/**
* Thrown when a repeated field has too many elements
*/
export declare class MaxLengthError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code: string;
name: string;
}
/**
* Thrown when a map has too many elements
*/
export declare class MaxSizeError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code: string;
name: string;
}
export declare class ParseError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code: string;
name: string;
}
export declare class NoMessagesFoundError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code: string;
name: string;
}
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,C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AEvB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAA;IAElB;;OAEG;IACH,cAAc,IAAI,MAAM,CAAA;IAExB;;OAEG;IACH,cAAc,IAAI,MAAM,CAAA;CACzB;AAED;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAC3B,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAK3C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;IACI,IAAI,SAAmB;IACvB,IAAI,SAAmB;CAC/B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC;;;;OAIG;IACI,IAAI,SAAiB;IACrB,IAAI,SAAiB;CAC7B;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC;;;;OAIG;IACI,IAAI,SAAoB;IACxB,IAAI,SAAe;CAC3B;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C;;;;OAIG;IACI,IAAI,SAA0B;IAC9B,IAAI,SAAyB;CACrC"}

View File

@@ -0,0 +1,72 @@
/**
* @packageDocumentation
*
* This module contains serialization/deserialization code used when encoding/decoding protobufs.
*
* It should be declared as a dependency of your project:
*
* ```console
* npm i protons-runtime
* ```
*/
export { decodeMessage } from './decode.js';
export { encodeMessage } from './encode.js';
export { enumeration } from './codecs/enum.js';
export { message } from './codecs/message.js';
export { createReader as reader } from './utils/reader.js';
export { createWriter as writer } from './utils/writer.js';
/**
* This will be removed in a future release
*
* @deprecated
*/
export class CodeError extends Error {
code;
constructor(message, code) {
super(message);
this.code = code;
}
}
/**
* Thrown when a repeated field has too many elements
*/
export class MaxLengthError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code = 'ERR_MAX_LENGTH';
name = 'MaxLengthError';
}
/**
* Thrown when a map has too many elements
*/
export class MaxSizeError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code = 'ERR_MAX_SIZE';
name = 'MaxSizeError';
}
export class ParseError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code = 'ERR_PARSE_ERROR';
name = 'ParseError';
}
export class NoMessagesFoundError extends Error {
/**
* This will be removed in a future release
*
* @deprecated use the `.name` property instead
*/
code = 'ERR_NO_MESSAGES_FOUND';
name = 'NoMessagesFoundError';
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,EACL,aAAa,EACd,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,aAAa,EACd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAoT1D;;;;GAIG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC3B,IAAI,CAAQ;IAEnB,YAAa,OAAe,EAAE,IAAY;QACxC,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;IACI,IAAI,GAAG,gBAAgB,CAAA;IACvB,IAAI,GAAG,gBAAgB,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;;;;OAIG;IACI,IAAI,GAAG,cAAc,CAAA;IACrB,IAAI,GAAG,cAAc,CAAA;CAC7B;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC;;;;OAIG;IACI,IAAI,GAAG,iBAAiB,CAAA;IACxB,IAAI,GAAG,YAAY,CAAA;CAC3B;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;;;;OAIG;IACI,IAAI,GAAG,uBAAuB,CAAA;IAC9B,IAAI,GAAG,sBAAsB,CAAA;CACrC"}

View File

@@ -0,0 +1,33 @@
/**
* Writes a 32 bit float to a buffer using little endian byte order
*/
export declare function writeFloatLE(val: number, buf: Uint8Array, pos: number): void;
/**
* Writes a 32 bit float to a buffer using big endian byte order
*/
export declare function writeFloatBE(val: number, buf: Uint8Array, pos: number): void;
/**
* Reads a 32 bit float from a buffer using little endian byte order
*/
export declare function readFloatLE(buf: Uint8Array, pos: number): number;
/**
* Reads a 32 bit float from a buffer using big endian byte order
*/
export declare function readFloatBE(buf: Uint8Array, pos: number): number;
/**
* Writes a 64 bit double to a buffer using little endian byte order
*/
export declare function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void;
/**
* Writes a 64 bit double to a buffer using big endian byte order
*/
export declare function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void;
/**
* Reads a 64 bit double from a buffer using little endian byte order
*/
export declare function readDoubleLE(buf: Uint8Array, pos: number): number;
/**
* Reads a 64 bit double from a buffer using big endian byte order
*/
export declare function readDoubleBE(buf: Uint8Array, pos: number): number;
//# sourceMappingURL=float.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"float.d.ts","sourceRoot":"","sources":["../../../src/utils/float.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjE;AAKD;;GAEG;AACH,wBAAgB,aAAa,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAU9E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAU9E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAUlE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAUlE"}

View File

@@ -0,0 +1,101 @@
const f32 = new Float32Array([-0]);
const f8b = new Uint8Array(f32.buffer);
/**
* Writes a 32 bit float to a buffer using little endian byte order
*/
export function writeFloatLE(val, buf, pos) {
f32[0] = val;
buf[pos] = f8b[0];
buf[pos + 1] = f8b[1];
buf[pos + 2] = f8b[2];
buf[pos + 3] = f8b[3];
}
/**
* Writes a 32 bit float to a buffer using big endian byte order
*/
export function writeFloatBE(val, buf, pos) {
f32[0] = val;
buf[pos] = f8b[3];
buf[pos + 1] = f8b[2];
buf[pos + 2] = f8b[1];
buf[pos + 3] = f8b[0];
}
/**
* Reads a 32 bit float from a buffer using little endian byte order
*/
export function readFloatLE(buf, pos) {
f8b[0] = buf[pos];
f8b[1] = buf[pos + 1];
f8b[2] = buf[pos + 2];
f8b[3] = buf[pos + 3];
return f32[0];
}
/**
* Reads a 32 bit float from a buffer using big endian byte order
*/
export function readFloatBE(buf, pos) {
f8b[3] = buf[pos];
f8b[2] = buf[pos + 1];
f8b[1] = buf[pos + 2];
f8b[0] = buf[pos + 3];
return f32[0];
}
const f64 = new Float64Array([-0]);
const d8b = new Uint8Array(f64.buffer);
/**
* Writes a 64 bit double to a buffer using little endian byte order
*/
export function writeDoubleLE(val, buf, pos) {
f64[0] = val;
buf[pos] = d8b[0];
buf[pos + 1] = d8b[1];
buf[pos + 2] = d8b[2];
buf[pos + 3] = d8b[3];
buf[pos + 4] = d8b[4];
buf[pos + 5] = d8b[5];
buf[pos + 6] = d8b[6];
buf[pos + 7] = d8b[7];
}
/**
* Writes a 64 bit double to a buffer using big endian byte order
*/
export function writeDoubleBE(val, buf, pos) {
f64[0] = val;
buf[pos] = d8b[7];
buf[pos + 1] = d8b[6];
buf[pos + 2] = d8b[5];
buf[pos + 3] = d8b[4];
buf[pos + 4] = d8b[3];
buf[pos + 5] = d8b[2];
buf[pos + 6] = d8b[1];
buf[pos + 7] = d8b[0];
}
/**
* Reads a 64 bit double from a buffer using little endian byte order
*/
export function readDoubleLE(buf, pos) {
d8b[0] = buf[pos];
d8b[1] = buf[pos + 1];
d8b[2] = buf[pos + 2];
d8b[3] = buf[pos + 3];
d8b[4] = buf[pos + 4];
d8b[5] = buf[pos + 5];
d8b[6] = buf[pos + 6];
d8b[7] = buf[pos + 7];
return f64[0];
}
/**
* Reads a 64 bit double from a buffer using big endian byte order
*/
export function readDoubleBE(buf, pos) {
d8b[7] = buf[pos];
d8b[6] = buf[pos + 1];
d8b[5] = buf[pos + 2];
d8b[4] = buf[pos + 3];
d8b[3] = buf[pos + 4];
d8b[2] = buf[pos + 5];
d8b[1] = buf[pos + 6];
d8b[0] = buf[pos + 7];
return f64[0];
}
//# sourceMappingURL=float.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"float.js","sourceRoot":"","sources":["../../../src/utils/float.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAClC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAEtC;;GAEG;AACH,MAAM,UAA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AG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAE,GAAe,EAAE,GAAW;IACxD,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;AACf,CAAC"}

View File

@@ -0,0 +1,54 @@
/**
* Constructs new long bits.
*
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
* @memberof util
* @function Object() { [native code] }
* @param {number} lo - Low 32 bits, unsigned
* @param {number} hi - High 32 bits, unsigned
*/
export declare class LongBits {
lo: number;
hi: number;
constructor(lo: number, hi: number);
/**
* Converts this long bits to a possibly unsafe JavaScript number
*/
toNumber(unsigned?: boolean): number;
/**
* Converts this long bits to a bigint
*/
toBigInt(unsigned?: boolean): bigint;
/**
* Converts this long bits to a string
*/
toString(unsigned?: boolean): string;
/**
* Zig-zag encodes this long bits
*/
zzEncode(): this;
/**
* Zig-zag decodes this long bits
*/
zzDecode(): this;
/**
* Calculates the length of this longbits when encoded as a varint.
*/
length(): number;
/**
* Constructs new long bits from the specified number
*/
static fromBigInt(value: bigint): LongBits;
/**
* Constructs new long bits from the specified number
*/
static fromNumber(value: number): LongBits;
/**
* Constructs new long bits from a number, long or string
*/
static from(value: bigint | number | string | {
low: number;
high: number;
}): LongBits;
}
//# sourceMappingURL=longbits.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"longbits.d.ts","sourceRoot":"","sources":["../../../src/utils/longbits.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,qBAAa,QAAQ;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;gBAEJ,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAenC;;OAEG;IACH,QAAQ,CAAE,QAAQ,GAAE,OAAe,GAAG,MAAM;IAY5C;;OAEG;IACH,QAAQ,CAAE,QAAQ,GAAE,OAAe,GAAG,MAAM;IAiB5C;;OAEG;IACH,QAAQ,CAAE,QAAQ,GAAE,OAAe,GAAG,MAAM;IAI5C;;OAEG;IACH,QAAQ,IAAK,IAAI;IAOjB;;OAEG;IACH,QAAQ,IAAK,IAAI;IAOjB;;OAEG;IACH,MAAM,IAAK,MAAM;IAejB;;OAEG;IACH,MAAM,CAAC,UAAU,CAAE,KAAK,EAAE,MAAM,GAAG,QAAQ;IA+B3C;;OAEG;IACH,MAAM,CAAC,UAAU,CAAE,KAAK,EAAE,MAAM,GAAG,QAAQ;IAiB3C;;OAEG;IACH,MAAM,CAAC,IAAI,CAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;CAYxF"}

View File

@@ -0,0 +1,174 @@
// the largest BigInt we can safely downcast to a Number
const MAX_SAFE_NUMBER_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
const MIN_SAFE_NUMBER_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
/**
* Constructs new long bits.
*
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
* @memberof util
* @function Object() { [native code] }
* @param {number} lo - Low 32 bits, unsigned
* @param {number} hi - High 32 bits, unsigned
*/
export class LongBits {
lo;
hi;
constructor(lo, hi) {
// note that the casts below are theoretically unnecessary as of today, but older statically
// generated converter code might still call the ctor with signed 32bits. kept for compat.
/**
* Low bits
*/
this.lo = lo | 0;
/**
* High bits
*/
this.hi = hi | 0;
}
/**
* Converts this long bits to a possibly unsafe JavaScript number
*/
toNumber(unsigned = false) {
if (!unsigned && (this.hi >>> 31) > 0) {
const lo = ~this.lo + 1 >>> 0;
let hi = ~this.hi >>> 0;
if (lo === 0) {
hi = hi + 1 >>> 0;
}
return -(lo + hi * 4294967296);
}
return this.lo + this.hi * 4294967296;
}
/**
* Converts this long bits to a bigint
*/
toBigInt(unsigned = false) {
if (unsigned) {
return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
}
if ((this.hi >>> 31) !== 0) {
const lo = ~this.lo + 1 >>> 0;
let hi = ~this.hi >>> 0;
if (lo === 0) {
hi = hi + 1 >>> 0;
}
return -(BigInt(lo) + (BigInt(hi) << 32n));
}
return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
}
/**
* Converts this long bits to a string
*/
toString(unsigned = false) {
return this.toBigInt(unsigned).toString();
}
/**
* Zig-zag encodes this long bits
*/
zzEncode() {
const mask = this.hi >> 31;
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
this.lo = (this.lo << 1 ^ mask) >>> 0;
return this;
}
/**
* Zig-zag decodes this long bits
*/
zzDecode() {
const mask = -(this.lo & 1);
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
this.hi = (this.hi >>> 1 ^ mask) >>> 0;
return this;
}
/**
* Calculates the length of this longbits when encoded as a varint.
*/
length() {
const part0 = this.lo;
const part1 = (this.lo >>> 28 | this.hi << 4) >>> 0;
const part2 = this.hi >>> 24;
return part2 === 0
? part1 === 0
? part0 < 16384
? part0 < 128 ? 1 : 2
: part0 < 2097152 ? 3 : 4
: part1 < 16384
? part1 < 128 ? 5 : 6
: part1 < 2097152 ? 7 : 8
: part2 < 128 ? 9 : 10;
}
/**
* Constructs new long bits from the specified number
*/
static fromBigInt(value) {
if (value === 0n) {
return zero;
}
if (value < MAX_SAFE_NUMBER_INTEGER && value > MIN_SAFE_NUMBER_INTEGER) {
return this.fromNumber(Number(value));
}
const negative = value < 0n;
if (negative) {
value = -value;
}
let hi = value >> 32n;
let lo = value - (hi << 32n);
if (negative) {
hi = ~hi | 0n;
lo = ~lo | 0n;
if (++lo > TWO_32) {
lo = 0n;
if (++hi > TWO_32) {
hi = 0n;
}
}
}
return new LongBits(Number(lo), Number(hi));
}
/**
* Constructs new long bits from the specified number
*/
static fromNumber(value) {
if (value === 0) {
return zero;
}
const sign = value < 0;
if (sign) {
value = -value;
}
let lo = value >>> 0;
let hi = (value - lo) / 4294967296 >>> 0;
if (sign) {
hi = ~hi >>> 0;
lo = ~lo >>> 0;
if (++lo > 4294967295) {
lo = 0;
if (++hi > 4294967295) {
hi = 0;
}
}
}
return new LongBits(lo, hi);
}
/**
* Constructs new long bits from a number, long or string
*/
static from(value) {
if (typeof value === 'number') {
return LongBits.fromNumber(value);
}
if (typeof value === 'bigint') {
return LongBits.fromBigInt(value);
}
if (typeof value === 'string') {
return LongBits.fromBigInt(BigInt(value));
}
return value.low != null || value.high != null ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
}
}
const zero = new LongBits(0, 0);
zero.toBigInt = function () { return 0n; };
zero.zzEncode = zero.zzDecode = function () { return this; };
zero.length = function () { return 1; };
const TWO_32 = 4294967296n;
//# sourceMappingURL=longbits.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
/**
* A general purpose buffer pool
*/
export default function pool(size?: number): (size: number) => Uint8Array;
//# sourceMappingURL=pool.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/utils/pool.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAwBzE"}

View File

@@ -0,0 +1,26 @@
import { allocUnsafe } from 'uint8arrays/alloc';
/**
* A general purpose buffer pool
*/
export default function pool(size) {
const SIZE = size ?? 8192;
const MAX = SIZE >>> 1;
let slab;
let offset = SIZE;
return function poolAlloc(size) {
if (size < 1 || size > MAX) {
return allocUnsafe(size);
}
if (offset + size > SIZE) {
slab = allocUnsafe(SIZE);
offset = 0;
}
const buf = slab.subarray(offset, offset += size);
if ((offset & 7) !== 0) {
// align to 32 bit
offset = (offset | 7) + 1;
}
return buf;
};
}
//# sourceMappingURL=pool.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/utils/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAE,IAAa;IACzC,MAAM,IAAI,GAAG,IAAI,IAAI,IAAI,CAAA;IACzB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,CAAA;IACtB,IAAI,IAAgB,CAAA;IACpB,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,OAAO,SAAS,SAAS,CAAE,IAAY;QACrC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;YAC3B,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;QAC1B,CAAC;QAED,IAAI,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;YACzB,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;YACxB,MAAM,GAAG,CAAC,CAAA;QACZ,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,CAAA;QAEjD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,kBAAkB;YAClB,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAA;IACZ,CAAC,CAAA;AACH,CAAC"}

View File

@@ -0,0 +1,129 @@
import type { Reader } from '../index.js';
import type { Uint8ArrayList } from 'uint8arraylist';
/**
* Constructs a new reader instance using the specified buffer.
*/
export declare class Uint8ArrayReader implements Reader {
buf: Uint8Array;
pos: number;
len: number;
_slice: (begin?: number, end?: number) => Uint8Array<ArrayBufferLike>;
constructor(buffer: Uint8Array);
/**
* Reads a varint as an unsigned 32 bit value
*/
uint32(): number;
/**
* Reads a varint as a signed 32 bit value
*/
int32(): number;
/**
* Reads a zig-zag encoded varint as a signed 32 bit value
*/
sint32(): number;
/**
* Reads a varint as a boolean
*/
bool(): boolean;
/**
* Reads fixed 32 bits as an unsigned 32 bit integer
*/
fixed32(): number;
/**
* Reads fixed 32 bits as a signed 32 bit integer
*/
sfixed32(): number;
/**
* Reads a float (32 bit) as a number
*/
float(): number;
/**
* Reads a double (64 bit float) as a number
*/
double(): number;
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes(): Uint8Array;
/**
* Reads a string preceded by its byte length as a varint
*/
string(): string;
/**
* Skips the specified number of bytes if specified, otherwise skips a varint
*/
skip(length?: number): this;
/**
* Skips the next element of the specified wire type
*/
skipType(wireType: number): this;
private readLongVarint;
private readFixed64;
/**
* Reads a varint as a signed 64 bit value
*/
int64(): bigint;
/**
* Reads a varint as a signed 64 bit value returned as a possibly unsafe
* JavaScript number
*/
int64Number(): number;
/**
* Reads a varint as a signed 64 bit value returned as a string
*/
int64String(): string;
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64(): bigint;
/**
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe
* JavaScript number
*/
uint64Number(): number;
/**
* Reads a varint as an unsigned 64 bit value returned as a string
*/
uint64String(): string;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64(): bigint;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
* possibly unsafe JavaScript number
*/
sint64Number(): number;
/**
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
* string
*/
sint64String(): string;
/**
* Reads fixed 64 bits
*/
fixed64(): bigint;
/**
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number
*/
fixed64Number(): number;
/**
* Reads fixed 64 bits returned as a string
*/
fixed64String(): string;
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64(): bigint;
/**
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe
* JavaScript number
*/
sfixed64Number(): number;
/**
* Reads zig-zag encoded fixed 64 bits returned as a string
*/
sfixed64String(): string;
}
export declare function createReader(buf: Uint8Array | Uint8ArrayList): Reader;
//# sourceMappingURL=reader.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../../src/utils/reader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAcpD;;GAEG;AACH,qBAAa,gBAAiB,YAAW,MAAM;IACtC,GAAG,EAAE,UAAU,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;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,GAAG,EAAE,UAAU,GAAG,cAAc,GAAG,MAAM,CAEtE"}

View File

@@ -0,0 +1,370 @@
import { decodeUint8Array, encodingLength } from 'uint8-varint';
import { readFloatLE, readDoubleLE } from './float.js';
import { LongBits } from './longbits.js';
import * as utf8 from './utf8.js';
/* istanbul ignore next */
function indexOutOfRange(reader, writeLength) {
return RangeError(`index out of range: ${reader.pos} + ${writeLength ?? 1} > ${reader.len}`);
}
function readFixed32End(buf, end) {
return (buf[end - 4] |
buf[end - 3] << 8 |
buf[end - 2] << 16 |
buf[end - 1] << 24) >>> 0;
}
/**
* Constructs a new reader instance using the specified buffer.
*/
export class Uint8ArrayReader {
buf;
pos;
len;
_slice = Uint8Array.prototype.subarray;
constructor(buffer) {
/**
* Read buffer
*/
this.buf = buffer;
/**
* Read buffer position
*/
this.pos = 0;
/**
* Read buffer length
*/
this.len = buffer.length;
}
/**
* Reads a varint as an unsigned 32 bit value
*/
uint32() {
let value = 4294967295;
value = (this.buf[this.pos] & 127) >>> 0;
if (this.buf[this.pos++] < 128) {
return value;
}
value = (value | (this.buf[this.pos] & 127) << 7) >>> 0;
if (this.buf[this.pos++] < 128) {
return value;
}
value = (value | (this.buf[this.pos] & 127) << 14) >>> 0;
if (this.buf[this.pos++] < 128) {
return value;
}
value = (value | (this.buf[this.pos] & 127) << 21) >>> 0;
if (this.buf[this.pos++] < 128) {
return value;
}
value = (value | (this.buf[this.pos] & 15) << 28) >>> 0;
if (this.buf[this.pos++] < 128) {
return value;
}
if ((this.pos += 5) > this.len) {
this.pos = this.len;
throw indexOutOfRange(this, 10);
}
return value;
}
/**
* Reads a varint as a signed 32 bit value
*/
int32() {
return this.uint32() | 0;
}
/**
* Reads a zig-zag encoded varint as a signed 32 bit value
*/
sint32() {
const value = this.uint32();
return value >>> 1 ^ -(value & 1) | 0;
}
/**
* Reads a varint as a boolean
*/
bool() {
return this.uint32() !== 0;
}
/**
* Reads fixed 32 bits as an unsigned 32 bit integer
*/
fixed32() {
if (this.pos + 4 > this.len) {
throw indexOutOfRange(this, 4);
}
const res = readFixed32End(this.buf, this.pos += 4);
return res;
}
/**
* Reads fixed 32 bits as a signed 32 bit integer
*/
sfixed32() {
if (this.pos + 4 > this.len) {
throw indexOutOfRange(this, 4);
}
const res = readFixed32End(this.buf, this.pos += 4) | 0;
return res;
}
/**
* Reads a float (32 bit) as a number
*/
float() {
if (this.pos + 4 > this.len) {
throw indexOutOfRange(this, 4);
}
const value = readFloatLE(this.buf, this.pos);
this.pos += 4;
return value;
}
/**
* Reads a double (64 bit float) as a number
*/
double() {
/* istanbul ignore if */
if (this.pos + 8 > this.len) {
throw indexOutOfRange(this, 4);
}
const value = readDoubleLE(this.buf, this.pos);
this.pos += 8;
return value;
}
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes() {
const length = this.uint32();
const start = this.pos;
const end = this.pos + length;
/* istanbul ignore if */
if (end > this.len) {
throw indexOutOfRange(this, length);
}
this.pos += length;
return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
? new Uint8Array(0)
: this.buf.subarray(start, end);
}
/**
* Reads a string preceded by its byte length as a varint
*/
string() {
const bytes = this.bytes();
return utf8.read(bytes, 0, bytes.length);
}
/**
* Skips the specified number of bytes if specified, otherwise skips a varint
*/
skip(length) {
if (typeof length === 'number') {
/* istanbul ignore if */
if (this.pos + length > this.len) {
throw indexOutOfRange(this, length);
}
this.pos += length;
}
else {
do {
/* istanbul ignore if */
if (this.pos >= this.len) {
throw indexOutOfRange(this);
}
} while ((this.buf[this.pos++] & 128) !== 0);
}
return this;
}
/**
* Skips the next element of the specified wire type
*/
skipType(wireType) {
switch (wireType) {
case 0:
this.skip();
break;
case 1:
this.skip(8);
break;
case 2:
this.skip(this.uint32());
break;
case 3:
while ((wireType = this.uint32() & 7) !== 4) {
this.skipType(wireType);
}
break;
case 5:
this.skip(4);
break;
/* istanbul ignore next */
default:
throw Error(`invalid wire type ${wireType} at offset ${this.pos}`);
}
return this;
}
readLongVarint() {
// tends to deopt with local vars for octet etc.
const bits = new LongBits(0, 0);
let i = 0;
if (this.len - this.pos > 4) { // fast route (lo)
for (; i < 4; ++i) {
// 1st..4th
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
if (this.buf[this.pos++] < 128) {
return bits;
}
}
// 5th
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
if (this.buf[this.pos++] < 128) {
return bits;
}
i = 0;
}
else {
for (; i < 3; ++i) {
/* istanbul ignore if */
if (this.pos >= this.len) {
throw indexOutOfRange(this);
}
// 1st..3th
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
if (this.buf[this.pos++] < 128) {
return bits;
}
}
// 4th
bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
return bits;
}
if (this.len - this.pos > 4) { // fast route (hi)
for (; i < 5; ++i) {
// 6th..10th
bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
if (this.buf[this.pos++] < 128) {
return bits;
}
}
}
else {
for (; i < 5; ++i) {
if (this.pos >= this.len) {
throw indexOutOfRange(this);
}
// 6th..10th
bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
if (this.buf[this.pos++] < 128) {
return bits;
}
}
}
throw Error('invalid varint encoding');
}
readFixed64() {
if (this.pos + 8 > this.len) {
throw indexOutOfRange(this, 8);
}
const lo = readFixed32End(this.buf, this.pos += 4);
const hi = readFixed32End(this.buf, this.pos += 4);
return new LongBits(lo, hi);
}
/**
* Reads a varint as a signed 64 bit value
*/
int64() {
return this.readLongVarint().toBigInt();
}
/**
* Reads a varint as a signed 64 bit value returned as a possibly unsafe
* JavaScript number
*/
int64Number() {
return this.readLongVarint().toNumber();
}
/**
* Reads a varint as a signed 64 bit value returned as a string
*/
int64String() {
return this.readLongVarint().toString();
}
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64() {
return this.readLongVarint().toBigInt(true);
}
/**
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe
* JavaScript number
*/
uint64Number() {
const value = decodeUint8Array(this.buf, this.pos);
this.pos += encodingLength(value);
return value;
}
/**
* Reads a varint as an unsigned 64 bit value returned as a string
*/
uint64String() {
return this.readLongVarint().toString(true);
}
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64() {
return this.readLongVarint().zzDecode().toBigInt();
}
/**
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
* possibly unsafe JavaScript number
*/
sint64Number() {
return this.readLongVarint().zzDecode().toNumber();
}
/**
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
* string
*/
sint64String() {
return this.readLongVarint().zzDecode().toString();
}
/**
* Reads fixed 64 bits
*/
fixed64() {
return this.readFixed64().toBigInt();
}
/**
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number
*/
fixed64Number() {
return this.readFixed64().toNumber();
}
/**
* Reads fixed 64 bits returned as a string
*/
fixed64String() {
return this.readFixed64().toString();
}
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64() {
return this.readFixed64().toBigInt();
}
/**
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe
* JavaScript number
*/
sfixed64Number() {
return this.readFixed64().toNumber();
}
/**
* Reads zig-zag encoded fixed 64 bits returned as a string
*/
sfixed64String() {
return this.readFixed64().toString();
}
}
export function createReader(buf) {
return new Uint8ArrayReader(buf instanceof Uint8Array ? buf : buf.subarray());
}
//# sourceMappingURL=reader.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,13 @@
/**
* Calculates the UTF8 byte length of a string
*/
export declare function length(string: string): number;
/**
* Reads UTF8 bytes as a string
*/
export declare function read(buffer: Uint8Array, start: number, end: number): string;
/**
* Writes a string as UTF8 bytes
*/
export declare function write(string: string, buffer: Uint8Array, offset: number): number;
//# sourceMappingURL=utf8.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../../src/utils/utf8.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAmB9C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA0C5E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA4BjF"}

View File

@@ -0,0 +1,98 @@
/**
* Calculates the UTF8 byte length of a string
*/
export function length(string) {
let len = 0;
let c = 0;
for (let i = 0; i < string.length; ++i) {
c = string.charCodeAt(i);
if (c < 128) {
len += 1;
}
else if (c < 2048) {
len += 2;
}
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
++i;
len += 4;
}
else {
len += 3;
}
}
return len;
}
/**
* Reads UTF8 bytes as a string
*/
export function read(buffer, start, end) {
const len = end - start;
if (len < 1) {
return '';
}
let parts;
const chunk = [];
let i = 0; // char offset
let t; // temporary
while (start < end) {
t = buffer[start++];
if (t < 128) {
chunk[i++] = t;
}
else if (t > 191 && t < 224) {
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
}
else if (t > 239 && t < 365) {
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
chunk[i++] = 0xD800 + (t >> 10);
chunk[i++] = 0xDC00 + (t & 1023);
}
else {
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
}
if (i > 8191) {
(parts ?? (parts = [])).push(String.fromCharCode.apply(String, chunk));
i = 0;
}
}
if (parts != null) {
if (i > 0) {
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
}
return parts.join('');
}
return String.fromCharCode.apply(String, chunk.slice(0, i));
}
/**
* Writes a string as UTF8 bytes
*/
export function write(string, buffer, offset) {
const start = offset;
let c1; // character 1
let c2; // character 2
for (let i = 0; i < string.length; ++i) {
c1 = string.charCodeAt(i);
if (c1 < 128) {
buffer[offset++] = c1;
}
else if (c1 < 2048) {
buffer[offset++] = c1 >> 6 | 192;
buffer[offset++] = c1 & 63 | 128;
}
else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
++i;
buffer[offset++] = c1 >> 18 | 240;
buffer[offset++] = c1 >> 12 & 63 | 128;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
}
else {
buffer[offset++] = c1 >> 12 | 224;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
}
}
return offset - start;
}
//# sourceMappingURL=utf8.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../../src/utils/utf8.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,MAAM,CAAE,MAAc;IACpC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACvC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAExB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;YACZ,GAAG,IAAI,CAAC,CAAA;QACV,CAAC;aAAM,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;YACpB,GAAG,IAAI,CAAC,CAAA;QACV,CAAC;aAAM,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,MAAM,IAAI,CAAC,MAAM,C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EAAE,GAAG,GAAG,CAAA;YACrC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;YACjC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAA;YACrC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,GAAG,KAAK,CAAA;AACvB,CAAC"}

View File

@@ -0,0 +1,6 @@
import type { Writer } from '../index.js';
/**
* Creates a new writer
*/
export declare function createWriter(): Writer;
//# sourceMappingURL=writer.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../src/utils/writer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAgfzC;;GAEG;AACH,wBAAgB,YAAY,IAAK,MAAM,CAEtC"}

View File

@@ -0,0 +1,436 @@
import { encodeUint8Array, encodingLength } from 'uint8-varint';
import { allocUnsafe } from 'uint8arrays/alloc';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { writeFloatLE, writeDoubleLE } from './float.js';
import { LongBits } from './longbits.js';
import pool from './pool.js';
import * as utf8 from './utf8.js';
/**
* Constructs a new writer operation instance.
*
* @classdesc Scheduled writer operation
*/
class Op {
/**
* Function to call
*/
fn;
/**
* Value byte length
*/
len;
/**
* Next operation
*/
next;
/**
* Value to write
*/
val;
constructor(fn, len, val) {
this.fn = fn;
this.len = len;
this.next = undefined;
this.val = val; // type varies
}
}
/* istanbul ignore next */
function noop() { }
/**
* Constructs a new writer state instance
*/
class State {
/**
* Current head
*/
head;
/**
* Current tail
*/
tail;
/**
* Current buffer length
*/
len;
/**
* Next state
*/
next;
constructor(writer) {
this.head = writer.head;
this.tail = writer.tail;
this.len = writer.len;
this.next = writer.states;
}
}
const bufferPool = pool();
/**
* Allocates a buffer of the specified size
*/
function alloc(size) {
if (globalThis.Buffer != null) {
return allocUnsafe(size);
}
return bufferPool(size);
}
/**
* When a value is written, the writer calculates its byte length and puts it into a linked
* list of operations to perform when finish() is called. This both allows us to allocate
* buffers of the exact required size and reduces the amount of work we have to do compared
* to first calculating over objects and then encoding over objects. In our case, the encoding
* part is just a linked list walk calling operations with already prepared values.
*/
class Uint8ArrayWriter {
/**
* Current length
*/
len;
/**
* Operations head
*/
head;
/**
* Operations tail
*/
tail;
/**
* Linked forked states
*/
states;
constructor() {
this.len = 0;
this.head = new Op(noop, 0, 0);
this.tail = this.head;
this.states = null;
}
/**
* Pushes a new operation to the queue
*/
_push(fn, len, val) {
this.tail = this.tail.next = new Op(fn, len, val);
this.len += len;
return this;
}
/**
* Writes an unsigned 32 bit value as a varint
*/
uint32(value) {
// here, the call to this.push has been inlined and a varint specific Op subclass is used.
// uint32 is by far the most frequently used operation and benefits significantly from this.
this.len += (this.tail = this.tail.next = new VarintOp((value = value >>> 0) <
128
? 1
: value < 16384
? 2
: value < 2097152
? 3
: value < 268435456
? 4
: 5, value)).len;
return this;
}
/**
* Writes a signed 32 bit value as a varint`
*/
int32(value) {
return value < 0
? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
: this.uint32(value);
}
/**
* Writes a 32 bit value as a varint, zig-zag encoded
*/
sint32(value) {
return this.uint32((value << 1 ^ value >> 31) >>> 0);
}
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64(value) {
const bits = LongBits.fromBigInt(value);
return this._push(writeVarint64, bits.length(), bits);
}
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64Number(value) {
return this._push(encodeUint8Array, encodingLength(value), value);
}
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64String(value) {
return this.uint64(BigInt(value));
}
/**
* Writes a signed 64 bit value as a varint
*/
int64(value) {
return this.uint64(value);
}
/**
* Writes a signed 64 bit value as a varint
*/
int64Number(value) {
return this.uint64Number(value);
}
/**
* Writes a signed 64 bit value as a varint
*/
int64String(value) {
return this.uint64String(value);
}
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64(value) {
const bits = LongBits.fromBigInt(value).zzEncode();
return this._push(writeVarint64, bits.length(), bits);
}
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64Number(value) {
const bits = LongBits.fromNumber(value).zzEncode();
return this._push(writeVarint64, bits.length(), bits);
}
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64String(value) {
return this.sint64(BigInt(value));
}
/**
* Writes a boolish value as a varint
*/
bool(value) {
return this._push(writeByte, 1, value ? 1 : 0);
}
/**
* Writes an unsigned 32 bit value as fixed 32 bits
*/
fixed32(value) {
return this._push(writeFixed32, 4, value >>> 0);
}
/**
* Writes a signed 32 bit value as fixed 32 bits
*/
sfixed32(value) {
return this.fixed32(value);
}
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64(value) {
const bits = LongBits.fromBigInt(value);
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
}
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64Number(value) {
const bits = LongBits.fromNumber(value);
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
}
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64String(value) {
return this.fixed64(BigInt(value));
}
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64(value) {
return this.fixed64(value);
}
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64Number(value) {
return this.fixed64Number(value);
}
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64String(value) {
return this.fixed64String(value);
}
/**
* Writes a float (32 bit)
*/
float(value) {
return this._push(writeFloatLE, 4, value);
}
/**
* Writes a double (64 bit float).
*
* @function
* @param {number} value - Value to write
* @returns {Writer} `this`
*/
double(value) {
return this._push(writeDoubleLE, 8, value);
}
/**
* Writes a sequence of bytes
*/
bytes(value) {
const len = value.length >>> 0;
if (len === 0) {
return this._push(writeByte, 1, 0);
}
return this.uint32(len)._push(writeBytes, len, value);
}
/**
* Writes a string
*/
string(value) {
const len = utf8.length(value);
return len !== 0
? this.uint32(len)._push(utf8.write, len, value)
: this._push(writeByte, 1, 0);
}
/**
* Forks this writer's state by pushing it to a stack.
* Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
*/
fork() {
this.states = new State(this);
this.head = this.tail = new Op(noop, 0, 0);
this.len = 0;
return this;
}
/**
* Resets this instance to the last state
*/
reset() {
if (this.states != null) {
this.head = this.states.head;
this.tail = this.states.tail;
this.len = this.states.len;
this.states = this.states.next;
}
else {
this.head = this.tail = new Op(noop, 0, 0);
this.len = 0;
}
return this;
}
/**
* Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
*/
ldelim() {
const head = this.head;
const tail = this.tail;
const len = this.len;
this.reset().uint32(len);
if (len !== 0) {
this.tail.next = head.next; // skip noop
this.tail = tail;
this.len += len;
}
return this;
}
/**
* Finishes the write operation
*/
finish() {
let head = this.head.next; // skip noop
const buf = alloc(this.len);
let pos = 0;
while (head != null) {
head.fn(head.val, buf, pos);
pos += head.len;
head = head.next;
}
// this.head = this.tail = null;
return buf;
}
}
function writeByte(val, buf, pos) {
buf[pos] = val & 255;
}
function writeVarint32(val, buf, pos) {
while (val > 127) {
buf[pos++] = val & 127 | 128;
val >>>= 7;
}
buf[pos] = val;
}
/**
* Constructs a new varint writer operation instance.
*
* @classdesc Scheduled varint writer operation
*/
class VarintOp extends Op {
next;
constructor(len, val) {
super(writeVarint32, len, val);
this.next = undefined;
}
}
function writeVarint64(val, buf, pos) {
while (val.hi !== 0) {
buf[pos++] = val.lo & 127 | 128;
val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
val.hi >>>= 7;
}
while (val.lo > 127) {
buf[pos++] = val.lo & 127 | 128;
val.lo = val.lo >>> 7;
}
buf[pos++] = val.lo;
}
function writeFixed32(val, buf, pos) {
buf[pos] = val & 255;
buf[pos + 1] = val >>> 8 & 255;
buf[pos + 2] = val >>> 16 & 255;
buf[pos + 3] = val >>> 24;
}
function writeBytes(val, buf, pos) {
buf.set(val, pos);
}
if (globalThis.Buffer != null) {
Uint8ArrayWriter.prototype.bytes = function (value) {
const len = value.length >>> 0;
this.uint32(len);
if (len > 0) {
this._push(writeBytesBuffer, len, value);
}
return this;
};
Uint8ArrayWriter.prototype.string = function (value) {
const len = globalThis.Buffer.byteLength(value);
this.uint32(len);
if (len > 0) {
this._push(writeStringBuffer, len, value);
}
return this;
};
}
function writeBytesBuffer(val, buf, pos) {
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
// also works for plain array values
}
function writeStringBuffer(val, buf, pos) {
if (val.length < 40) {
// plain js is faster for short strings (probably due to redundant assertions)
utf8.write(val, buf, pos);
// @ts-expect-error buf isn't a Uint8Array?
}
else if (buf.utf8Write != null) {
// @ts-expect-error buf isn't a Uint8Array?
buf.utf8Write(val, pos);
}
else {
buf.set(uint8ArrayFromString(val), pos);
}
}
/**
* Creates a new writer
*/
export function createWriter() {
return new Uint8ArrayWriter();
}
//# sourceMappingURL=writer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
{
"CodeError": "https://ipfs.github.io/protons/classes/protons-runtime.CodeError.html",
".:CodeError": "https://ipfs.github.io/protons/classes/protons-runtime.CodeError.html",
"MaxLengthError": "https://ipfs.github.io/protons/classes/protons-runtime.MaxLengthError.html",
".:MaxLengthError": "https://ipfs.github.io/protons/classes/protons-runtime.MaxLengthError.html",
"MaxSizeError": "https://ipfs.github.io/protons/classes/protons-runtime.MaxSizeError.html",
".:MaxSizeError": "https://ipfs.github.io/protons/classes/protons-runtime.MaxSizeError.html",
"NoMessagesFoundError": "https://ipfs.github.io/protons/classes/protons-runtime.NoMessagesFoundError.html",
".:NoMessagesFoundError": "https://ipfs.github.io/protons/classes/protons-runtime.NoMessagesFoundError.html",
"ParseError": "https://ipfs.github.io/protons/classes/protons-runtime.ParseError.html",
".:ParseError": "https://ipfs.github.io/protons/classes/protons-runtime.ParseError.html",
"Codec": "https://ipfs.github.io/protons/interfaces/protons-runtime.Codec.html",
"DecodeOptions": "https://ipfs.github.io/protons/interfaces/protons-runtime.DecodeOptions.html",
"EncodeOptions": "https://ipfs.github.io/protons/interfaces/protons-runtime.EncodeOptions.html",
"FieldDef": "https://ipfs.github.io/protons/interfaces/protons-runtime.FieldDef.html",
".:FieldDef": "https://ipfs.github.io/protons/interfaces/protons-runtime.FieldDef.html",
"Reader": "https://ipfs.github.io/protons/interfaces/protons-runtime.Reader.html",
".:Reader": "https://ipfs.github.io/protons/interfaces/protons-runtime.Reader.html",
"Writer": "https://ipfs.github.io/protons/interfaces/protons-runtime.Writer.html",
".:Writer": "https://ipfs.github.io/protons/interfaces/protons-runtime.Writer.html",
"decodeMessage": "https://ipfs.github.io/protons/functions/protons-runtime.decodeMessage.html",
"encodeMessage": "https://ipfs.github.io/protons/functions/protons-runtime.encodeMessage.html",
"enumeration": "https://ipfs.github.io/protons/functions/protons-runtime.enumeration.html",
"message": "https://ipfs.github.io/protons/functions/protons-runtime.message.html",
"reader": "https://ipfs.github.io/protons/functions/protons-runtime.reader.html",
"writer": "https://ipfs.github.io/protons/functions/protons-runtime.writer.html"
}

View File

@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.
MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0

View File

@@ -0,0 +1,251 @@
# multiformats
[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)
[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
> Interface for multihash, multicodec, multibase and CID
# About
<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->
This library defines common interfaces and low level building blocks for various interrelated multiformat technologies (multicodec, multihash, multibase, and CID). They can be used to implement custom base encoders / decoders / codecs, codec encoders /decoders and multihash hashers that comply to the interface that layers above assume.
This library provides implementations for most basics and many others can be found in linked repositories.
```TypeScript
import { CID } from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'
const bytes = json.encode({ hello: 'world' })
const hash = await sha256.digest(bytes)
const cid = CID.create(1, json.code, hash)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
## Creating Blocks
```TypeScript
import * as Block from 'multiformats/block'
import * as codec from '@ipld/dag-cbor'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
const value = { hello: 'world' }
// encode a block
let block = await Block.encode({ value, codec, hasher })
block.value // { hello: 'world' }
block.bytes // Uint8Array
block.cid // CID() w/ sha2-256 hash address and dag-cbor codec
// you can also decode blocks from their binary state
block = await Block.decode({ bytes: block.bytes, codec, hasher })
// if you have the cid you can also verify the hash on decode
block = await Block.create({ bytes: block.bytes, cid: block.cid, codec, hasher })
```
## Multibase Encoders / Decoders / Codecs
CIDs can be serialized to string representation using multibase encoders that implement [`MultibaseEncoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides quite a few implementations that can be imported:
```TypeScript
import { base64 } from "multiformats/bases/base64"
cid.toString(base64.encoder)
//> 'mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA'
```
Parsing CID string serialized CIDs requires multibase decoder that implements [`MultibaseDecoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides a decoder for every encoder it provides:
```TypeScript
CID.parse('mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA', base64.decoder)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
Dual of multibase encoder & decoder is defined as multibase codec and it exposes
them as `encoder` and `decoder` properties. For added convenience codecs also
implement `MultibaseEncoder` and `MultibaseDecoder` interfaces so they could be
used as either or both:
```TypeScript
cid.toString(base64)
CID.parse(cid.toString(base64), base64)
```
**Note:** CID implementation comes bundled with `base32` and `base58btc`
multibase codecs so that CIDs can be base serialized to (version specific)
default base encoding and parsed without having to supply base encoders/decoders:
```TypeScript
const v1 = CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
v1.toString()
//> 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'
const v0 = CID.parse('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
v0.toString()
//> 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
v0.toV1().toString()
//> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
```
## Multicodec Encoders / Decoders / Codecs
This library defines [`BlockEncoder`, `BlockDecoder` and `BlockCodec` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts).
Codec implementations should conform to the `BlockCodec` interface which implements both `BlockEncoder` and `BlockDecoder`.
Here is an example implementation of JSON `BlockCodec`.
```TypeScript
export const { name, code, encode, decode } = {
name: 'json',
code: 0x0200,
encode: json => new TextEncoder().encode(JSON.stringify(json)),
decode: bytes => JSON.parse(new TextDecoder().decode(bytes))
}
```
## Multihash Hashers
This library defines [`MultihashHasher` and `MultihashDigest` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts) and convinient function for implementing them:
```TypeScript
import * as hasher from 'multiformats/hashes/hasher'
const sha256 = hasher.from({
// As per multiformats table
// https://github.com/multiformats/multicodec/blob/master/table.csv#L9
name: 'sha2-256',
code: 0x12,
encode: (input) => new Uint8Array(crypto.createHash('sha256').update(input).digest())
})
const hash = await sha256.digest(json.encode({ hello: 'world' }))
CID.create(1, json.code, hash)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
## Traversal
This library contains higher-order functions for traversing graphs of data easily.
`walk()` walks through the links in each block of a DAG calling a user-supplied loader function for each one, in depth-first order with no duplicate block visits. The loader should return a `Block` object and can be used to inspect and collect block ordering for a full DAG walk. The loader should `throw` on error, and return `null` if a block should be skipped by `walk()`.
```TypeScript
import { walk } from 'multiformats/traversal'
import * as Block from 'multiformats/block'
import * as codec from 'multiformats/codecs/json'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
// build a DAG (a single block for this simple example)
const value = { hello: 'world' }
const block = await Block.encode({ value, codec, hasher })
const { cid } = block
console.log(cid)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
// create a loader function that also collects CIDs of blocks in
// their traversal order
const load = (cid, blocks) => async (cid) => {
// fetch a block using its cid
// e.g.: const block = await fetchBlockByCID(cid)
blocks.push(cid)
return block
}
// collect blocks in this DAG starting from the root `cid`
const blocks = []
await walk({ cid, load: load(cid, blocks) })
console.log(blocks)
//> [CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)]
```
## Legacy interface
[`blockcodec-to-ipld-format`](https://github.com/ipld/js-blockcodec-to-ipld-format) converts a multiformats [`BlockCodec`](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts#L21) into an
[`interface-ipld-format`](https://github.com/ipld/interface-ipld-format) for use with the [`ipld`](https://github.com/ipld/ipld) package. This can help bridge IPLD codecs implemented using the structure and interfaces defined here to existing code that assumes, or requires `interface-ipld-format`. This bridge also includes the relevant TypeScript definitions.
## Implementations
By default, no base encodings (other than base32 & base58btc), hash functions,
or codec implementations are exposed by `multiformats`, you need to
import the ones you need yourself.
### Multibase codecs
| bases | import | repo |
| ------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------- |
| `base16` | `multiformats/bases/base16` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |
| `base32`, `base32pad`, `base32hex`, `base32hexpad`, `base32z` | `multiformats/bases/base32` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |
| `base64`, `base64pad`, `base64url`, `base64urlpad` | `multiformats/bases/base64` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |
| `base58btc`, `base58flick4` | `multiformats/bases/base58` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |
Other (less useful) bases implemented in [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) include: `base2`, `base8`, `base10`, `base36` and `base256emoji`.
### Multihash hashers
| hashes | import | repo |
| ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `sha2-256`, `sha2-512` | `multiformats/hashes/sha2` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes) |
| `sha3-224`, `sha3-256`, `sha3-384`,`sha3-512`, `shake-128`, `shake-256`, `keccak-224`, `keccak-256`, `keccak-384`, `keccak-512` | `@multiformats/sha3` | [multiformats/js-sha3](https://github.com/multiformats/js-sha3) |
| `identity` | `multiformats/hashes/identity` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes/identity.js) |
| `murmur3-128`, `murmur3-32` | `@multiformats/murmur3` | [multiformats/js-murmur3](https://github.com/multiformats/js-murmur3) |
| `blake2b-*`, `blake2s-*` | `@multiformats/blake2` | [multiformats/js-blake2](https://github.com/multiformats/js-blake2) |
### IPLD codecs (multicodec)
| codec | import | repo |
| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------ |
| `raw` | `multiformats/codecs/raw` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |
| `json` | `multiformats/codecs/json` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |
| `dag-cbor` | `@ipld/dag-cbor` | [ipld/js-dag-cbor](https://github.com/ipld/js-dag-cbor) |
| `dag-json` | `@ipld/dag-json` | [ipld/js-dag-json](https://github.com/ipld/js-dag-json) |
| `dag-pb` | `@ipld/dag-pb` | [ipld/js-dag-pb](https://github.com/ipld/js-dag-pb) |
| `dag-jose` | `dag-jose` | [ceramicnetwork/js-dag-jose](https://github.com/ceramicnetwork/js-dag-jose) |
# Install
```console
$ npm i multiformats
```
## Browser `<script>` tag
Loading this module through a script tag will make its exports available as `Multiformats` in the global namespace.
```html
<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
```
# API Docs
- <https://multiformats.github.io/js-multiformats>
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](https://github.com/multiformats/js-multiformats/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/multiformats/js-multiformats/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,74 @@
import type { BaseCodec, BaseDecoder, BaseEncoder, CombobaseDecoder, Multibase, MultibaseCodec, MultibaseDecoder, MultibaseEncoder, UnibaseDecoder } from './interface.js';
interface EncodeFn {
(bytes: Uint8Array): string;
}
interface DecodeFn {
(text: string): Uint8Array;
}
/**
* Class represents both BaseEncoder and MultibaseEncoder meaning it
* can be used to encode to multibase or base encode without multibase
* prefix.
*/
declare class Encoder<Base extends string, Prefix extends string> implements MultibaseEncoder<Prefix>, BaseEncoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseEncode: EncodeFn;
constructor(name: Base, prefix: Prefix, baseEncode: EncodeFn);
encode(bytes: Uint8Array): Multibase<Prefix>;
}
/**
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
* to decode multibases (with matching prefix) or just base decode strings
* with corresponding base encoding.
*/
declare class Decoder<Base extends string, Prefix extends string> implements MultibaseDecoder<Prefix>, UnibaseDecoder<Prefix>, BaseDecoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseDecode: DecodeFn;
private readonly prefixCodePoint;
constructor(name: Base, prefix: Prefix, baseDecode: DecodeFn);
decode(text: string): Uint8Array;
or<OtherPrefix extends string>(decoder: UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
}
type Decoders<Prefix extends string> = Record<Prefix, UnibaseDecoder<Prefix>>;
declare class ComposedDecoder<Prefix extends string> implements MultibaseDecoder<Prefix>, CombobaseDecoder<Prefix> {
readonly decoders: Decoders<Prefix>;
constructor(decoders: Decoders<Prefix>);
or<OtherPrefix extends string>(decoder: UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
decode(input: string): Uint8Array;
}
export declare function or<L extends string, R extends string>(left: UnibaseDecoder<L> | CombobaseDecoder<L>, right: UnibaseDecoder<R> | CombobaseDecoder<R>): ComposedDecoder<L | R>;
export declare class Codec<Base extends string, Prefix extends string> implements MultibaseCodec<Prefix>, MultibaseEncoder<Prefix>, MultibaseDecoder<Prefix>, BaseCodec, BaseEncoder, BaseDecoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseEncode: EncodeFn;
readonly baseDecode: DecodeFn;
readonly encoder: Encoder<Base, Prefix>;
readonly decoder: Decoder<Base, Prefix>;
constructor(name: Base, prefix: Prefix, baseEncode: EncodeFn, baseDecode: DecodeFn);
encode(input: Uint8Array): string;
decode(input: string): Uint8Array;
}
export declare function from<Base extends string, Prefix extends string>({ name, prefix, encode, decode }: {
name: Base;
prefix: Prefix;
encode: EncodeFn;
decode: DecodeFn;
}): Codec<Base, Prefix>;
export declare function baseX<Base extends string, Prefix extends string>({ name, prefix, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
}): Codec<Base, Prefix>;
/**
* RFC4648 Factory
*/
export declare function rfc4648<Base extends string, Prefix extends string>({ name, prefix, bitsPerChar, alphabet }: {
name: Base;
prefix: Prefix;
bitsPerChar: number;
alphabet: string;
}): Codec<Base, Prefix>;
export {};
//# sourceMappingURL=base.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/bases/base.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE1K,UAAU,QAAQ;IAAG,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAA;CAAE;AAClD,UAAU,QAAQ;IAAG,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE;AAEjD;;;;GAIG;AACH,cAAM,OAAO,CAAC,IAAI,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,CAAE,YAAW,gBAAgB,CAAC,MAAM,CAAC,EAAE,WAAW;IACxG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAA;gBAEhB,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ;IAM7D,MAAM,CAAE,KAAK,EAAE,UAAU,GAAG,SA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CAAC,IAAI,EAAE,MAAM,CAAC,CAE5L;AAED,wBAAgB,KAAK,CAAE,IAAI,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAQrK;AAqFD;;GAEG;AACH,wBAAgB,OAAO,CAAE,IAAI,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAAG,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAYzM"}

View File

@@ -0,0 +1,206 @@
import { coerce } from '../bytes.js';
import basex from '../vendor/base-x.js';
/**
* Class represents both BaseEncoder and MultibaseEncoder meaning it
* can be used to encode to multibase or base encode without multibase
* prefix.
*/
class Encoder {
name;
prefix;
baseEncode;
constructor(name, prefix, baseEncode) {
this.name = name;
this.prefix = prefix;
this.baseEncode = baseEncode;
}
encode(bytes) {
if (bytes instanceof Uint8Array) {
return `${this.prefix}${this.baseEncode(bytes)}`;
}
else {
throw Error('Unknown type, must be binary type');
}
}
}
/**
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
* to decode multibases (with matching prefix) or just base decode strings
* with corresponding base encoding.
*/
class Decoder {
name;
prefix;
baseDecode;
prefixCodePoint;
constructor(name, prefix, baseDecode) {
this.name = name;
this.prefix = prefix;
const prefixCodePoint = prefix.codePointAt(0);
/* c8 ignore next 3 */
if (prefixCodePoint === undefined) {
throw new Error('Invalid prefix character');
}
this.prefixCodePoint = prefixCodePoint;
this.baseDecode = baseDecode;
}
decode(text) {
if (typeof text === 'string') {
if (text.codePointAt(0) !== this.prefixCodePoint) {
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
}
return this.baseDecode(text.slice(this.prefix.length));
}
else {
throw Error('Can only multibase decode strings');
}
}
or(decoder) {
return or(this, decoder);
}
}
class ComposedDecoder {
decoders;
constructor(decoders) {
this.decoders = decoders;
}
or(decoder) {
return or(this, decoder);
}
decode(input) {
const prefix = input[0];
const decoder = this.decoders[prefix];
if (decoder != null) {
return decoder.decode(input);
}
else {
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
}
}
}
export function or(left, right) {
return new ComposedDecoder({
...(left.decoders ?? { [left.prefix]: left }),
...(right.decoders ?? { [right.prefix]: right })
});
}
export class Codec {
name;
prefix;
baseEncode;
baseDecode;
encoder;
decoder;
constructor(name, prefix, baseEncode, baseDecode) {
this.name = name;
this.prefix = prefix;
this.baseEncode = baseEncode;
this.baseDecode = baseDecode;
this.encoder = new Encoder(name, prefix, baseEncode);
this.decoder = new Decoder(name, prefix, baseDecode);
}
encode(input) {
return this.encoder.encode(input);
}
decode(input) {
return this.decoder.decode(input);
}
}
export function from({ name, prefix, encode, decode }) {
return new Codec(name, prefix, encode, decode);
}
export function baseX({ name, prefix, alphabet }) {
const { encode, decode } = basex(alphabet, name);
return from({
prefix,
name,
encode,
decode: (text) => coerce(decode(text))
});
}
function decode(string, alphabetIdx, bitsPerChar, name) {
// Count the padding bytes:
let end = string.length;
while (string[end - 1] === '=') {
--end;
}
// Allocate the output:
const out = new Uint8Array((end * bitsPerChar / 8) | 0);
// Parse the data:
let bits = 0; // Number of bits currently in the buffer
let buffer = 0; // Bits waiting to be written out, MSB first
let written = 0; // Next byte to write
for (let i = 0; i < end; ++i) {
// Read one character from the string:
const value = alphabetIdx[string[i]];
if (value === undefined) {
throw new SyntaxError(`Non-${name} character`);
}
// Append the bits to the buffer:
buffer = (buffer << bitsPerChar) | value;
bits += bitsPerChar;
// Write out some bits if the buffer has a byte's worth:
if (bits >= 8) {
bits -= 8;
out[written++] = 0xff & (buffer >> bits);
}
}
// Verify that we have received just enough bits:
if (bits >= bitsPerChar || (0xff & (buffer << (8 - bits))) !== 0) {
throw new SyntaxError('Unexpected end of data');
}
return out;
}
function encode(data, alphabet, bitsPerChar) {
const pad = alphabet[alphabet.length - 1] === '=';
const mask = (1 << bitsPerChar) - 1;
let out = '';
let bits = 0; // Number of bits currently in the buffer
let buffer = 0; // Bits waiting to be written out, MSB first
for (let i = 0; i < data.length; ++i) {
// Slurp data into the buffer:
buffer = (buffer << 8) | data[i];
bits += 8;
// Write out as much as we can:
while (bits > bitsPerChar) {
bits -= bitsPerChar;
out += alphabet[mask & (buffer >> bits)];
}
}
// Partial character:
if (bits !== 0) {
out += alphabet[mask & (buffer << (bitsPerChar - bits))];
}
// Add padding characters until we hit a byte boundary:
if (pad) {
while (((out.length * bitsPerChar) & 7) !== 0) {
out += '=';
}
}
return out;
}
function createAlphabetIdx(alphabet) {
// Build the character lookup table:
const alphabetIdx = {};
for (let i = 0; i < alphabet.length; ++i) {
alphabetIdx[alphabet[i]] = i;
}
return alphabetIdx;
}
/**
* RFC4648 Factory
*/
export function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
const alphabetIdx = createAlphabetIdx(alphabet);
return from({
prefix,
name,
encode(input) {
return encode(input, alphabet, bitsPerChar);
},
decode(input) {
return decode(input, alphabetIdx, bitsPerChar, name);
}
});
}
//# sourceMappingURL=base.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export declare const base10: import("./base.js").Codec<"base10", "9">;
//# sourceMappingURL=base10.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base10.d.ts","sourceRoot":"","sources":["../../../src/bases/base10.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,0CAIjB,CAAA"}

View File

@@ -0,0 +1,7 @@
import { baseX } from './base.js';
export const base10 = baseX({
prefix: '9',
name: 'base10',
alphabet: '0123456789'
});
//# sourceMappingURL=base10.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base10.js","sourceRoot":"","sources":["../../../src/bases/base10.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;IAC1B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,YAAY;CACvB,CAAC,CAAA"}

View File

@@ -0,0 +1,3 @@
export declare const base16: import("./base.js").Codec<"base16", "f">;
export declare const base16upper: import("./base.js").Codec<"base16upper", "F">;
//# sourceMappingURL=base16.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base16.d.ts","sourceRoot":"","sources":["../../../src/bases/base16.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,0CAKjB,CAAA;AAEF,eAAO,MAAM,WAAW,+CAKtB,CAAA"}

View File

@@ -0,0 +1,14 @@
import { rfc4648 } from './base.js';
export const base16 = rfc4648({
prefix: 'f',
name: 'base16',
alphabet: '0123456789abcdef',
bitsPerChar: 4
});
export const base16upper = rfc4648({
prefix: 'F',
name: 'base16upper',
alphabet: '0123456789ABCDEF',
bitsPerChar: 4
});
//# sourceMappingURL=base16.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base16.js","sourceRoot":"","sources":["../../../src/bases/base16.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,kBAAkB;IAC5B,WAAW,EAAE,CAAC;CACf,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;IACjC,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,aAAa;IACnB,QAAQ,EAAE,kBAAkB;IAC5B,WAAW,EAAE,CAAC;CACf,CAAC,CAAA"}

View File

@@ -0,0 +1,2 @@
export declare const base2: import("./base.js").Codec<"base2", "0">;
//# sourceMappingURL=base2.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base2.d.ts","sourceRoot":"","sources":["../../../src/bases/base2.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,yCAKhB,CAAA"}

View File

@@ -0,0 +1,8 @@
import { rfc4648 } from './base.js';
export const base2 = rfc4648({
prefix: '0',
name: 'base2',
alphabet: '01',
bitsPerChar: 1
});
//# sourceMappingURL=base2.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base2.js","sourceRoot":"","sources":["../../../src/bases/base2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,CAAC;CACf,CAAC,CAAA"}

View File

@@ -0,0 +1,2 @@
export declare const base256emoji: import("./base.js").Codec<"base256emoji", "🚀">;
//# sourceMappingURL=base256emoji.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base256emoji.d.ts","sourceRoot":"","sources":["../../../src/bases/base256emoji.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,YAAY,iDAKvB,CAAA"}

View File

@@ -0,0 +1,39 @@
import { from } from './base.js';
const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
const alphabetBytesToChars = (alphabet.reduce((p, c, i) => { p[i] = c; return p; }, ([])));
const alphabetCharsToBytes = (alphabet.reduce((p, c, i) => {
const codePoint = c.codePointAt(0);
if (codePoint == null) {
throw new Error(`Invalid character: ${c}`);
}
p[codePoint] = i;
return p;
}, ([])));
function encode(data) {
return data.reduce((p, c) => {
p += alphabetBytesToChars[c];
return p;
}, '');
}
function decode(str) {
const byts = [];
for (const char of str) {
const codePoint = char.codePointAt(0);
if (codePoint == null) {
throw new Error(`Invalid character: ${char}`);
}
const byt = alphabetCharsToBytes[codePoint];
if (byt == null) {
throw new Error(`Non-base256emoji character: ${char}`);
}
byts.push(byt);
}
return new Uint8Array(byts);
}
export const base256emoji = from({
prefix: '🚀',
name: 'base256emoji',
encode,
decode
});
//# sourceMappingURL=base256emoji.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base256emoji.js","sourceRoot":"","sources":["../../../src/bases/base256emoji.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,QAAQ,GAAG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G,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAA;QAC3C,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAA;QACxD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,cAAc;IACpB,MAAM;IACN,MAAM;CACP,CAAC,CAAA"}

View File

@@ -0,0 +1,10 @@
export declare const base32: import("./base.js").Codec<"base32", "b">;
export declare const base32upper: import("./base.js").Codec<"base32upper", "B">;
export declare const base32pad: import("./base.js").Codec<"base32pad", "c">;
export declare const base32padupper: import("./base.js").Codec<"base32padupper", "C">;
export declare const base32hex: import("./base.js").Codec<"base32hex", "v">;
export declare const base32hexupper: import("./base.js").Codec<"base32hexupper", "V">;
export declare const base32hexpad: import("./base.js").Codec<"base32hexpad", "t">;
export declare const base32hexpadupper: import("./base.js").Codec<"base32hexpadupper", "T">;
export declare const base32z: import("./base.js").Codec<"base32z", "h">;
//# sourceMappingURL=base32.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../../../src/bases/base32.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,0CAKjB,CAAA;AAEF,eAAO,MAAM,WAAW,+CAKtB,CAAA;AAEF,eAAO,MAAM,SAAS,6CAKpB,CAAA;AAEF,eAAO,MAAM,cAAc,kDAKzB,CAAA;AAEF,eAAO,MAAM,SAAS,6CAKpB,CAAA;AAEF,eAAO,MAAM,cAAc,kDAKzB,CAAA;AAEF,eAAO,MAAM,YAAY,gDAKvB,CAAA;AAEF,eAAO,MAAM,iBAAiB,qDAK5B,CAAA;AAEF,eAAO,MAAM,OAAO,2CAKlB,CAAA"}

View File

@@ -0,0 +1,56 @@
import { rfc4648 } from './base.js';
export const base32 = rfc4648({
prefix: 'b',
name: 'base32',
alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
bitsPerChar: 5
});
export const base32upper = rfc4648({
prefix: 'B',
name: 'base32upper',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
bitsPerChar: 5
});
export const base32pad = rfc4648({
prefix: 'c',
name: 'base32pad',
alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
bitsPerChar: 5
});
export const base32padupper = rfc4648({
prefix: 'C',
name: 'base32padupper',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
bitsPerChar: 5
});
export const base32hex = rfc4648({
prefix: 'v',
name: 'base32hex',
alphabet: '0123456789abcdefghijklmnopqrstuv',
bitsPerChar: 5
});
export const base32hexupper = rfc4648({
prefix: 'V',
name: 'base32hexupper',
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
bitsPerChar: 5
});
export const base32hexpad = rfc4648({
prefix: 't',
name: 'base32hexpad',
alphabet: '0123456789abcdefghijklmnopqrstuv=',
bitsPerChar: 5
});
export const base32hexpadupper = rfc4648({
prefix: 'T',
name: 'base32hexpadupper',
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
bitsPerChar: 5
});
export const base32z = rfc4648({
prefix: 'h',
name: 'base32z',
alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
bitsPerChar: 5
});
//# sourceMappingURL=base32.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base32.js","sourceRoot":"","sources":["../../../src/bases/base32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,kCAAkC;IAC5C,WAAW,EAAE,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AAC;IAC7B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,kCAAkC;IAC5C,WAAW,EAAE,CAAC;CACf,CAAC,CAAA"}

View File

@@ -0,0 +1,3 @@
export declare const base36: import("./base.js").Codec<"base36", "k">;
export declare const base36upper: import("./base.js").Codec<"base36upper", "K">;
//# sourceMappingURL=base36.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base36.d.ts","sourceRoot":"","sources":["../../../src/bases/base36.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,0CAIjB,CAAA;AAEF,eAAO,MAAM,WAAW,+CAItB,CAAA"}

View File

@@ -0,0 +1,12 @@
import { baseX } from './base.js';
export const base36 = baseX({
prefix: 'k',
name: 'base36',
alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
});
export const base36upper = baseX({
prefix: 'K',
name: 'base36upper',
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
});
//# sourceMappingURL=base36.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base36.js","sourceRoot":"","sources":["../../../src/bases/base36.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;IAC1B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,sCAAsC;CACjD,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;IAC/B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,aAAa;IACnB,QAAQ,EAAE,sCAAsC;CACjD,CAAC,CAAA"}

View File

@@ -0,0 +1,3 @@
export declare const base58btc: import("./base.js").Codec<"base58btc", "z">;
export declare const base58flickr: import("./base.js").Codec<"base58flickr", "Z">;
//# sourceMappingURL=base58.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../../src/bases/base58.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,6CAIpB,CAAA;AAEF,eAAO,MAAM,YAAY,gDAIvB,CAAA"}

View File

@@ -0,0 +1,12 @@
import { baseX } from './base.js';
export const base58btc = baseX({
name: 'base58btc',
prefix: 'z',
alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
});
export const base58flickr = baseX({
name: 'base58flickr',
prefix: 'Z',
alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
});
//# sourceMappingURL=base58.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../../../src/bases/base58.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;IAC7B,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,4DAA4D;CACvE,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;IAChC,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,4DAA4D;CACvE,CAAC,CAAA"}

View File

@@ -0,0 +1,5 @@
export declare const base64: import("./base.js").Codec<"base64", "m">;
export declare const base64pad: import("./base.js").Codec<"base64pad", "M">;
export declare const base64url: import("./base.js").Codec<"base64url", "u">;
export declare const base64urlpad: import("./base.js").Codec<"base64urlpad", "U">;
//# sourceMappingURL=base64.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../src/bases/base64.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,0CAKjB,CAAA;AAEF,eAAO,MAAM,SAAS,6CAKpB,CAAA;AAEF,eAAO,MAAM,SAAS,6CAKpB,CAAA;AAEF,eAAO,MAAM,YAAY,gDAKvB,CAAA"}

View File

@@ -0,0 +1,26 @@
import { rfc4648 } from './base.js';
export const base64 = rfc4648({
prefix: 'm',
name: 'base64',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
bitsPerChar: 6
});
export const base64pad = rfc4648({
prefix: 'M',
name: 'base64pad',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
bitsPerChar: 6
});
export const base64url = rfc4648({
prefix: 'u',
name: 'base64url',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
bitsPerChar: 6
});
export const base64urlpad = rfc4648({
prefix: 'U',
name: 'base64urlpad',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
bitsPerChar: 6
});
//# sourceMappingURL=base64.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../src/bases/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,kEAAkE;IAC5E,WAAW,EAAE,CAAC;CACf,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,mEAAmE;IAC7E,WAAW,EAAE,CAAC;CACf,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,kEAAkE;IAC5E,WAAW,EAAE,CAAC;CACf,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC;IAClC,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,cAAc;IACpB,QAAQ,EAAE,mEAAmE;IAC7E,WAAW,EAAE,CAAC;CACf,CAAC,CAAA"}

View File

@@ -0,0 +1,2 @@
export declare const base8: import("./base.js").Codec<"base8", "7">;
//# sourceMappingURL=base8.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base8.d.ts","sourceRoot":"","sources":["../../../src/bases/base8.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,yCAKhB,CAAA"}

View File

@@ -0,0 +1,8 @@
import { rfc4648 } from './base.js';
export const base8 = rfc4648({
prefix: '7',
name: 'base8',
alphabet: '01234567',
bitsPerChar: 3
});
//# sourceMappingURL=base8.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base8.js","sourceRoot":"","sources":["../../../src/bases/base8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,CAAC;CACf,CAAC,CAAA"}

View File

@@ -0,0 +1,2 @@
export declare const identity: import("./base.js").Codec<"identity", "\0">;
//# sourceMappingURL=identity.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/bases/identity.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,6CAKnB,CAAA"}

View File

@@ -0,0 +1,9 @@
import { fromString, toString } from '../bytes.js';
import { from } from './base.js';
export const identity = from({
prefix: '\x00',
name: 'identity',
encode: (buf) => toString(buf),
decode: (str) => fromString(str)
});
//# sourceMappingURL=identity.js.map

Some files were not shown because too many files have changed in this diff Show More