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
+5
View File
@@ -0,0 +1,5 @@
import * as P from './index.js';
export declare function table(data: any[]): void;
export declare function decode(coder: P.CoderType<any>, data: string | P.Bytes, forcePrint?: boolean): ReturnType<(typeof coder)['decode']>;
export declare function diff(coder: P.CoderType<any>, actual: string | P.Bytes, expected: string | P.Bytes, skipSame?: boolean): void;
//# sourceMappingURL=debugger.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"debugger.d.ts","sourceRoot":"","sources":["../debugger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AA0GhC,wBAAgB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,QAsChC;AAmBD,wBAAgB,MAAM,CACpB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EACvB,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EACtB,UAAU,UAAQ,GACjB,UAAU,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CA2BtC;AA4CD,wBAAgB,IAAI,CAClB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EACvB,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EACxB,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAC1B,QAAQ,UAAO,QA0BhB"}
+268
View File
@@ -0,0 +1,268 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.diff = exports.decode = exports.table = void 0;
const base_1 = require("@scure/base");
const P = require("./index.js");
const UNKNOWN = '(???)';
const bold = '\x1b[1m';
const gray = '\x1b[90m';
const reset = '\x1b[0m';
const red = '\x1b[31m';
const green = '\x1b[32m';
const yellow = '\x1b[33m';
class DebugReader extends P.Reader {
constructor() {
super(...arguments);
this.debugLst = [];
}
get lastElm() {
if (this.debugLst.length)
return this.debugLst[this.debugLst.length - 1];
return { start: 0, end: 0, path: '' };
}
fieldPathPush(s) {
const last = this.lastElm;
if (last.end === undefined)
last.end = this.pos;
else if (last.end !== this.pos) {
this.debugLst.push({
path: [...this.fieldPath, UNKNOWN].join('/'),
start: last.end,
end: this.pos,
});
}
this.cur = { path: [...this.fieldPath, s].join('/'), start: this.pos };
super.fieldPathPush(s);
}
fieldPathPop() {
// happens if pop after pop (exit from nested structure)
if (!this.cur) {
const last = this.lastElm;
if (last.end === undefined)
last.end = this.pos;
else if (last.end !== this.pos) {
this.debugLst.push({ start: last.end, end: this.pos, path: last.path + `/${UNKNOWN}` });
}
}
else {
this.cur.end = this.pos;
const lastItem = this.path[this.path.length - 1];
const lastField = this.fieldPath[this.fieldPath.length - 1];
if (lastItem && lastField !== undefined)
this.cur.value = lastItem[lastField];
this.debugLst.push(this.cur);
this.cur = undefined;
}
super.fieldPathPop();
}
finishDebug() {
const end = this.data.length;
if (this.cur)
this.debugLst.push({ end, ...this.cur });
const last = this.lastElm;
if (!last || last.end !== end)
this.debugLst.push({ start: this.pos, end, path: UNKNOWN });
}
}
function toBytes(data) {
if (P.isBytes(data))
return data;
if (typeof data !== 'string')
throw new Error('PD: data should be string or Uint8Array');
try {
return base_1.base64.decode(data);
}
catch (e) { }
try {
return base_1.hex.decode(data);
}
catch (e) { }
throw new Error(`PD: data has unknown string format: ${data}`);
}
function mapData(lst, data) {
let end = 0;
const res = [];
for (const elm of lst) {
if (elm.start !== end)
throw new Error(`PD: elm start=${elm.start} after prev elm end=${end}`);
if (elm.end === undefined)
throw new Error(`PD: elm.end is undefined=${elm}`);
res.push({ path: elm.path, data: data.slice(elm.start, elm.end), value: elm.value });
end = elm.end;
}
if (end !== data.length)
throw new Error('PD: not all data mapped');
return res;
}
function chrWidth(s) {
/*
It is almost impossible to find out real characters width in terminal since it depends on terminal itself, current unicode version and moon's phase.
So, we just stripping ANSI, tabs and unicode supplimental characters. Emoji support requires big tables (and have no guarantee to work), so we ignore it for now.
Also, no support for full width unicode characters for now.
*/
return s
.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g, '')
.replace('\t', ' ')
.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ' ').length;
}
function wrap(s, padding = 0) {
// @ts-ignore
const limit = process.stdout.columns - 3 - padding;
if (chrWidth(s) <= limit)
return s;
while (chrWidth(s) > limit)
s = s.slice(0, -1);
return `${s}${reset}...`;
}
function table(data) {
let res = [];
const str = (v) => (v === undefined ? '' : '' + v);
const pad = (s, width) => `${s}${''.padEnd(Math.max(0, width - chrWidth(s)), ' ')}`;
let widths = {};
for (let elm of data) {
for (let k in elm) {
widths[k] = Math.max(widths[k] || 0, chrWidth(str(k)), str(elm[k])
.split('\n')
.reduce((a, b) => Math.max(a, chrWidth(b)), 0));
}
}
const columns = Object.keys(widths);
if (!data.length || !columns.length)
throw new Error('No data');
const padding = ` ${reset}${gray}${reset} `;
res.push(wrap(` ${columns.map((c) => `${bold}${pad(c, widths[c])}`).join(padding)}${reset}`, 3));
for (let idx = 0; idx < data.length; idx++) {
const elm = data[idx];
const row = columns.map((i) => str(elm[i]).split('\n'));
let message = [...Array(Math.max(...row.map((i) => i.length))).keys()]
.map((line) => row.map((c, i) => pad(str(c[line]), widths[columns[i]])))
.map((line, _) => wrap(` ${line.join(padding)} `, 1))
.join('\n');
res.push(message);
}
for (let i = 0; i < res.length; i++) {
const border = columns
.map((c) => ''.padEnd(widths[c], '─'))
.join(`${i === res.length - 1 ? '┴' : '┼'}`);
res[i] += wrap(`\n${reset}${gray}${border}${reset}`);
}
// @ts-ignore
console.log(res.join('\n'));
}
exports.table = table;
function fmtData(data, perLine = 8) {
const res = [];
for (let i = 0; i < data.length; i += perLine) {
res.push(base_1.hex.encode(data.slice(i, i + perLine)));
}
return res.map((i) => `${bold}${i}${reset}`).join('\n');
}
function fmtValue(value) {
if (P.isBytes(value))
return `b(${green}${base_1.hex.encode(value)}${reset} len=${value.length})`;
if (typeof value === 'string')
return `s(${green}"${value}"${reset} len=${value.length})`;
if (typeof value === 'number' || typeof value === 'bigint')
return `n(${value})`;
// console.log('fmt', value);
// if (Object.prototype.toString.call(value) === '[object Object]') return inspect(value);
return '' + value;
}
function decode(coder, data, forcePrint = false) {
data = toBytes(data);
const r = new DebugReader(data);
let res, e;
try {
res = coder.decodeStream(r);
r.finish();
}
catch (_e) {
e = _e;
}
r.finishDebug();
if (e || forcePrint) {
// @ts-ignore
console.log('==== DECODED BEFORE ERROR ====');
table(mapData(r.debugLst, data).map((elm) => ({
Data: fmtData(elm.data),
Len: elm.data.length,
Path: `${green}${elm.path}${reset}`,
Value: fmtValue(elm.value),
})));
// @ts-ignore
console.log('==== /DECODED BEFORE ERROR ====');
}
if (e)
throw e;
return res;
}
exports.decode = decode;
function getMap(coder, data) {
data = toBytes(data);
const r = new DebugReader(data);
coder.decodeStream(r);
r.finish();
r.finishDebug();
return mapData(r.debugLst, data);
}
function diffData(a, e) {
const len = Math.max(a.length, e.length);
let outA = '', outE = '';
const charHex = (n) => n.toString(16).padStart(2, '0');
for (let i = 0; i < len; i++) {
const [aI, eI] = [a[i], e[i]];
if (i && !(i % 8)) {
if (aI !== undefined)
outA += '\n';
if (eI !== undefined)
outE += '\n';
}
if (aI !== undefined)
outA += aI === eI ? charHex(aI) : `${yellow}${charHex(aI)}${reset}`;
if (eI !== undefined)
outE += aI === eI ? charHex(eI) : `${yellow}${charHex(eI)}${reset}`;
}
return [outA, outE];
}
function diffPath(a, e) {
if (a === e)
return a;
return `A: ${red}${a}${reset}\nE: ${green}${e}${reset}`;
}
function diffLength(a, e) {
const [aLen, eLen] = [a.length, e.length];
if (aLen === eLen)
return aLen;
return `A: ${red}${aLen}${reset}\nE: ${green}${eLen}${reset}`;
}
function diffValue(a, e) {
const [aV, eV] = [a, e].map(fmtValue);
if (aV === eV)
return aV;
return `A: ${red}${aV}${reset}\nE: ${green}${eV}${reset}`;
}
function diff(coder, actual, expected, skipSame = true) {
// @ts-ignore
console.log('==== DIFF ====');
const [_actual, _expected] = [actual, expected].map((i) => getMap(coder, i));
const len = Math.max(_actual.length, _expected.length);
const data = [];
const DEF = { data: P.EMPTY, path: '' };
for (let i = 0; i < len; i++) {
const [a, e] = [_actual[i] || DEF, _expected[i] || DEF];
if (P.equalBytes(a.data, e.data) && skipSame)
continue;
const [adata, edata] = diffData(a.data, e.data);
data.push({
'Data (A)': adata,
'Data (E)': edata,
Len: diffLength(a.data, e.data),
Path: diffPath(a.path, e.path),
Value: diffValue(a.value, e.value),
});
}
table(data);
// @ts-ignore
console.log('==== /DIFF ====');
}
exports.diff = diff;
+262
View File
@@ -0,0 +1,262 @@
import { base64, hex } from '@scure/base';
import * as P from './index.js';
const UNKNOWN = '(???)';
const bold = '\x1b[1m';
const gray = '\x1b[90m';
const reset = '\x1b[0m';
const red = '\x1b[31m';
const green = '\x1b[32m';
const yellow = '\x1b[33m';
class DebugReader extends P.Reader {
constructor() {
super(...arguments);
this.debugLst = [];
}
get lastElm() {
if (this.debugLst.length)
return this.debugLst[this.debugLst.length - 1];
return { start: 0, end: 0, path: '' };
}
fieldPathPush(s) {
const last = this.lastElm;
if (last.end === undefined)
last.end = this.pos;
else if (last.end !== this.pos) {
this.debugLst.push({
path: [...this.fieldPath, UNKNOWN].join('/'),
start: last.end,
end: this.pos,
});
}
this.cur = { path: [...this.fieldPath, s].join('/'), start: this.pos };
super.fieldPathPush(s);
}
fieldPathPop() {
// happens if pop after pop (exit from nested structure)
if (!this.cur) {
const last = this.lastElm;
if (last.end === undefined)
last.end = this.pos;
else if (last.end !== this.pos) {
this.debugLst.push({ start: last.end, end: this.pos, path: last.path + `/${UNKNOWN}` });
}
}
else {
this.cur.end = this.pos;
const lastItem = this.path[this.path.length - 1];
const lastField = this.fieldPath[this.fieldPath.length - 1];
if (lastItem && lastField !== undefined)
this.cur.value = lastItem[lastField];
this.debugLst.push(this.cur);
this.cur = undefined;
}
super.fieldPathPop();
}
finishDebug() {
const end = this.data.length;
if (this.cur)
this.debugLst.push({ end, ...this.cur });
const last = this.lastElm;
if (!last || last.end !== end)
this.debugLst.push({ start: this.pos, end, path: UNKNOWN });
}
}
function toBytes(data) {
if (P.isBytes(data))
return data;
if (typeof data !== 'string')
throw new Error('PD: data should be string or Uint8Array');
try {
return base64.decode(data);
}
catch (e) { }
try {
return hex.decode(data);
}
catch (e) { }
throw new Error(`PD: data has unknown string format: ${data}`);
}
function mapData(lst, data) {
let end = 0;
const res = [];
for (const elm of lst) {
if (elm.start !== end)
throw new Error(`PD: elm start=${elm.start} after prev elm end=${end}`);
if (elm.end === undefined)
throw new Error(`PD: elm.end is undefined=${elm}`);
res.push({ path: elm.path, data: data.slice(elm.start, elm.end), value: elm.value });
end = elm.end;
}
if (end !== data.length)
throw new Error('PD: not all data mapped');
return res;
}
function chrWidth(s) {
/*
It is almost impossible to find out real characters width in terminal since it depends on terminal itself, current unicode version and moon's phase.
So, we just stripping ANSI, tabs and unicode supplimental characters. Emoji support requires big tables (and have no guarantee to work), so we ignore it for now.
Also, no support for full width unicode characters for now.
*/
return s
.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g, '')
.replace('\t', ' ')
.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ' ').length;
}
function wrap(s, padding = 0) {
// @ts-ignore
const limit = process.stdout.columns - 3 - padding;
if (chrWidth(s) <= limit)
return s;
while (chrWidth(s) > limit)
s = s.slice(0, -1);
return `${s}${reset}...`;
}
export function table(data) {
let res = [];
const str = (v) => (v === undefined ? '' : '' + v);
const pad = (s, width) => `${s}${''.padEnd(Math.max(0, width - chrWidth(s)), ' ')}`;
let widths = {};
for (let elm of data) {
for (let k in elm) {
widths[k] = Math.max(widths[k] || 0, chrWidth(str(k)), str(elm[k])
.split('\n')
.reduce((a, b) => Math.max(a, chrWidth(b)), 0));
}
}
const columns = Object.keys(widths);
if (!data.length || !columns.length)
throw new Error('No data');
const padding = ` ${reset}${gray}${reset} `;
res.push(wrap(` ${columns.map((c) => `${bold}${pad(c, widths[c])}`).join(padding)}${reset}`, 3));
for (let idx = 0; idx < data.length; idx++) {
const elm = data[idx];
const row = columns.map((i) => str(elm[i]).split('\n'));
let message = [...Array(Math.max(...row.map((i) => i.length))).keys()]
.map((line) => row.map((c, i) => pad(str(c[line]), widths[columns[i]])))
.map((line, _) => wrap(` ${line.join(padding)} `, 1))
.join('\n');
res.push(message);
}
for (let i = 0; i < res.length; i++) {
const border = columns
.map((c) => ''.padEnd(widths[c], '─'))
.join(`${i === res.length - 1 ? '┴' : '┼'}`);
res[i] += wrap(`\n${reset}${gray}${border}${reset}`);
}
// @ts-ignore
console.log(res.join('\n'));
}
function fmtData(data, perLine = 8) {
const res = [];
for (let i = 0; i < data.length; i += perLine) {
res.push(hex.encode(data.slice(i, i + perLine)));
}
return res.map((i) => `${bold}${i}${reset}`).join('\n');
}
function fmtValue(value) {
if (P.isBytes(value))
return `b(${green}${hex.encode(value)}${reset} len=${value.length})`;
if (typeof value === 'string')
return `s(${green}"${value}"${reset} len=${value.length})`;
if (typeof value === 'number' || typeof value === 'bigint')
return `n(${value})`;
// console.log('fmt', value);
// if (Object.prototype.toString.call(value) === '[object Object]') return inspect(value);
return '' + value;
}
export function decode(coder, data, forcePrint = false) {
data = toBytes(data);
const r = new DebugReader(data);
let res, e;
try {
res = coder.decodeStream(r);
r.finish();
}
catch (_e) {
e = _e;
}
r.finishDebug();
if (e || forcePrint) {
// @ts-ignore
console.log('==== DECODED BEFORE ERROR ====');
table(mapData(r.debugLst, data).map((elm) => ({
Data: fmtData(elm.data),
Len: elm.data.length,
Path: `${green}${elm.path}${reset}`,
Value: fmtValue(elm.value),
})));
// @ts-ignore
console.log('==== /DECODED BEFORE ERROR ====');
}
if (e)
throw e;
return res;
}
function getMap(coder, data) {
data = toBytes(data);
const r = new DebugReader(data);
coder.decodeStream(r);
r.finish();
r.finishDebug();
return mapData(r.debugLst, data);
}
function diffData(a, e) {
const len = Math.max(a.length, e.length);
let outA = '', outE = '';
const charHex = (n) => n.toString(16).padStart(2, '0');
for (let i = 0; i < len; i++) {
const [aI, eI] = [a[i], e[i]];
if (i && !(i % 8)) {
if (aI !== undefined)
outA += '\n';
if (eI !== undefined)
outE += '\n';
}
if (aI !== undefined)
outA += aI === eI ? charHex(aI) : `${yellow}${charHex(aI)}${reset}`;
if (eI !== undefined)
outE += aI === eI ? charHex(eI) : `${yellow}${charHex(eI)}${reset}`;
}
return [outA, outE];
}
function diffPath(a, e) {
if (a === e)
return a;
return `A: ${red}${a}${reset}\nE: ${green}${e}${reset}`;
}
function diffLength(a, e) {
const [aLen, eLen] = [a.length, e.length];
if (aLen === eLen)
return aLen;
return `A: ${red}${aLen}${reset}\nE: ${green}${eLen}${reset}`;
}
function diffValue(a, e) {
const [aV, eV] = [a, e].map(fmtValue);
if (aV === eV)
return aV;
return `A: ${red}${aV}${reset}\nE: ${green}${eV}${reset}`;
}
export function diff(coder, actual, expected, skipSame = true) {
// @ts-ignore
console.log('==== DIFF ====');
const [_actual, _expected] = [actual, expected].map((i) => getMap(coder, i));
const len = Math.max(_actual.length, _expected.length);
const data = [];
const DEF = { data: P.EMPTY, path: '' };
for (let i = 0; i < len; i++) {
const [a, e] = [_actual[i] || DEF, _expected[i] || DEF];
if (P.equalBytes(a.data, e.data) && skipSame)
continue;
const [adata, edata] = diffData(a.data, e.data);
data.push({
'Data (A)': adata,
'Data (E)': edata,
Len: diffLength(a.data, e.data),
Path: diffPath(a.path, e.path),
Value: diffValue(a.value, e.value),
});
}
table(data);
// @ts-ignore
console.log('==== /DIFF ====');
}
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
{
"type": "module",
"sideEffects": false,
"browser": {
"node:crypto": false
},
"node": {
"./crypto": "./esm/cryptoNode.js"
}
}
+257
View File
@@ -0,0 +1,257 @@
import type { Coder as BaseCoder } from '@scure/base';
/**
* TODO:
* - Holes, simplify pointers. Hole is some sized element which is skipped at encoding,
* but later other elements can write to it by path
* - Composite / tuple keys for dict
* - Web UI for easier debugging. We can wrap every coder to something that would write
* start & end positions to; and we can colorize specific bytes used by specific coder
*/
export declare const EMPTY: Uint8Array;
export declare const NULL: Uint8Array;
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
export declare function isBytes(a: unknown): a is Bytes;
/**
* Copies several Uint8Arrays into one.
*/
export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
export type Bytes = Uint8Array;
export type Option<T> = T | undefined;
export interface Coder<F, T> {
encode(from: F): T;
decode(to: T): F;
}
export interface BytesCoder<T> extends Coder<T, Bytes> {
size?: number;
encode: (data: T) => Bytes;
decode: (data: Bytes) => T;
}
export interface BytesCoderStream<T> {
size?: number;
encodeStream: (w: Writer, value: T) => void;
decodeStream: (r: Reader) => T;
}
export type CoderType<T> = BytesCoderStream<T> & BytesCoder<T>;
export type Sized<T> = CoderType<T> & {
size: number;
};
export type UnwrapCoder<T> = T extends CoderType<infer U> ? U : T;
export type Length = CoderType<number> | CoderType<bigint> | number | Bytes | string | null;
type ArrLike<T> = Array<T> | ReadonlyArray<T>;
export type TypedArray = Uint8Array | Int8Array | Uint8ClampedArray | Uint16Array | Int16Array | Uint32Array | Int32Array;
export type Writable<T> = T extends {} ? T extends TypedArray ? T : {
-readonly [P in keyof T]: Writable<T[P]>;
} : T;
export type Values<T> = T[keyof T];
export type NonUndefinedKey<T, K extends keyof T> = T[K] extends undefined ? never : K;
export type NullableKey<T, K extends keyof T> = T[K] extends NonNullable<T[K]> ? never : K;
export type OptKey<T, K extends keyof T> = NullableKey<T, K> & NonUndefinedKey<T, K>;
export type ReqKey<T, K extends keyof T> = T[K] extends NonNullable<T[K]> ? K : never;
export type OptKeys<T> = Pick<T, {
[K in keyof T]: OptKey<T, K>;
}[keyof T]>;
export type ReqKeys<T> = Pick<T, {
[K in keyof T]: ReqKey<T, K>;
}[keyof T]>;
export type StructInput<T extends Record<string, any>> = {
[P in keyof ReqKeys<T>]: T[P];
} & {
[P in keyof OptKeys<T>]?: T[P];
};
export type StructRecord<T extends Record<string, any>> = {
[P in keyof T]: CoderType<T[P]>;
};
export type StructOut = Record<string, any>;
export type PadFn = (i: number) => number;
export type ReaderOpts = {
allowUnreadBytes?: boolean;
allowMultipleReads?: boolean;
};
export declare class Reader {
readonly data: Bytes;
readonly opts: ReaderOpts;
path: StructOut[];
fieldPath: string[];
private parent;
parentOffset: number;
pos: number;
bitBuf: number;
bitPos: number;
private bs;
constructor(data: Bytes, opts?: ReaderOpts, path?: StructOut[], fieldPath?: string[], parent?: Reader | undefined, parentOffset?: number);
enablePtr(): void;
private markBytesBS;
private markBytes;
err(msg: string): Error;
absBytes(n: number): Uint8Array;
offsetReader(n: number): Reader;
bytes(n: number, peek?: boolean): Uint8Array;
byte(peek?: boolean): number;
get leftBytes(): number;
isEnd(): boolean;
length(len: Length): number;
bits(bits: number): number;
find(needle: Bytes, pos?: number): number | undefined;
finish(): void;
fieldPathPush(s: string): void;
fieldPathPop(): void;
}
export declare class Writer {
path: StructOut[];
fieldPath: string[];
private buffers;
pos: number;
ptrs: {
pos: number;
ptr: CoderType<number>;
buffer: Bytes;
}[];
bitBuf: number;
bitPos: number;
constructor(path?: StructOut[], fieldPath?: string[]);
err(msg: string): Error;
bytes(b: Bytes): void;
byte(b: number): void;
get buffer(): Bytes;
length(len: Length, value: number): void;
bits(value: number, bits: number): void;
fieldPathPush(s: string): void;
fieldPathPop(): void;
}
export declare function checkBounds(p: Writer | Reader, value: bigint, bits: bigint, signed: boolean): void;
export declare function wrap<T>(inner: BytesCoderStream<T>): BytesCoderStream<T> & BytesCoder<T>;
export declare function isCoder<T>(elm: any): elm is CoderType<T>;
declare function dict<T>(): BaseCoder<[string, T][], Record<string, T>>;
type Enum = {
[k: string]: number | string;
} & {
[k: number]: string;
};
type EnumKeys<T extends Enum> = keyof T;
declare function tsEnum<T extends Enum>(e: T): BaseCoder<number, EnumKeys<T>>;
declare function decimal(precision: number): {
encode: (from: bigint) => string;
decode: (to: string) => bigint;
};
type BaseInput<F> = F extends BaseCoder<infer T, any> ? T : never;
type BaseOutput<F> = F extends BaseCoder<any, infer T> ? T : never;
/**
* Allows to split big conditional coders into a small one; also sort of parser combinator:
*
* `encode = [Ae, Be]; decode = [Ad, Bd]`
* ->
* `match([{encode: Ae, decode: Ad}, {encode: Be; decode: Bd}])`
*
* 1. It is easier to reason: encode/decode of specific part are closer to each other
* 2. Allows composable coders and ability to add conditions on runtime
* @param lst
* @returns
*/
declare function match<L extends BaseCoder<unknown | undefined, unknown | undefined>[], I = {
[K in keyof L]: NonNullable<BaseInput<L[K]>>;
}[number], O = {
[K in keyof L]: NonNullable<BaseOutput<L[K]>>;
}[number]>(lst: L): BaseCoder<I, O>;
export declare const coders: {
dict: typeof dict;
number: BaseCoder<bigint, number>;
tsEnum: typeof tsEnum;
decimal: typeof decimal;
match: typeof match;
reverse: <F, T>(coder: Coder<F, T>) => Coder<T, F>;
};
export declare const bits: (len: number) => CoderType<number>;
export declare const bigint: (size: number, le?: boolean, signed?: boolean, sized?: boolean) => CoderType<bigint>;
export declare const U256LE: CoderType<bigint>;
export declare const U256BE: CoderType<bigint>;
export declare const I256LE: CoderType<bigint>;
export declare const I256BE: CoderType<bigint>;
export declare const U128LE: CoderType<bigint>;
export declare const U128BE: CoderType<bigint>;
export declare const I128LE: CoderType<bigint>;
export declare const I128BE: CoderType<bigint>;
export declare const U64LE: CoderType<bigint>;
export declare const U64BE: CoderType<bigint>;
export declare const I64LE: CoderType<bigint>;
export declare const I64BE: CoderType<bigint>;
export declare const int: (size: number, le?: boolean, signed?: boolean, sized?: boolean) => CoderType<number>;
export declare const U32LE: CoderType<number>;
export declare const U32BE: CoderType<number>;
export declare const I32LE: CoderType<number>;
export declare const I32BE: CoderType<number>;
export declare const U16LE: CoderType<number>;
export declare const U16BE: CoderType<number>;
export declare const I16LE: CoderType<number>;
export declare const I16BE: CoderType<number>;
export declare const U8: CoderType<number>;
export declare const I8: CoderType<number>;
export declare const bool: CoderType<boolean>;
export declare const bytes: (len: Length, le?: boolean) => CoderType<Bytes>;
export declare const string: (len: Length, le?: boolean) => CoderType<string>;
export declare const cstring: CoderType<string>;
export declare const hex: (len: Length, le?: boolean, withZero?: boolean) => CoderType<string>;
export declare function apply<T, F>(inner: CoderType<T>, b: BaseCoder<T, F>): CoderType<F>;
export declare function validate<T>(inner: CoderType<T>, fn: (elm: T) => T): CoderType<T>;
export declare function lazy<T>(fn: () => CoderType<T>): CoderType<T>;
type baseFmt = 'utf8' | 'hex' | 'base16' | 'base32' | 'base64' | 'base64url' | 'base58' | 'base58xmr';
export declare const bytesFormatted: (len: Length, fmt: baseFmt, le?: boolean) => BytesCoderStream<string> & BytesCoder<string>;
export declare const flag: (flagValue: Bytes, xor?: boolean) => CoderType<boolean>;
export declare function flagged<T>(path: string | BytesCoderStream<boolean>, inner: BytesCoderStream<T>, def?: T): CoderType<Option<T>>;
export declare function optional<T>(flag: BytesCoderStream<boolean>, inner: BytesCoderStream<T>, def?: T): CoderType<Option<T>>;
export declare function magic<T>(inner: CoderType<T>, constant: T, check?: boolean): CoderType<undefined>;
export declare const magicBytes: (constant: Bytes | string) => CoderType<undefined>;
export declare function constant<T>(c: T): CoderType<T>;
export declare function struct<T extends Record<string, any>>(fields: StructRecord<T>): CoderType<StructInput<T>>;
export declare function tuple<T extends ArrLike<CoderType<any>>, O = Writable<{
[K in keyof T]: UnwrapCoder<T[K]>;
}>>(fields: T): CoderType<O>;
type PrefixLength = string | number | CoderType<number> | CoderType<bigint>;
export declare function prefix<T>(len: PrefixLength, inner: CoderType<T>): CoderType<T>;
export declare function array<T>(len: Length, inner: CoderType<T>): CoderType<T[]>;
export declare function map<T>(inner: CoderType<T>, variants: Record<string, T>): CoderType<string>;
export declare function tag<T extends Values<{
[P in keyof Variants]: {
TAG: P;
data: UnwrapCoder<Variants[P]>;
};
}>, TagValue extends string | number, Variants extends Record<TagValue, CoderType<any>>>(tag: CoderType<TagValue>, variants: Variants): CoderType<T>;
export declare function mappedTag<T extends Values<{
[P in keyof Variants]: {
TAG: P;
data: UnwrapCoder<Variants[P][1]>;
};
}>, TagValue extends string | number, Variants extends Record<string, [TagValue, CoderType<any>]>>(tagCoder: CoderType<TagValue>, variants: Variants): CoderType<T>;
export declare function bitset<Names extends readonly string[]>(names: Names, pad?: boolean): CoderType<Record<Names[number], boolean>>;
export declare const ZeroPad: PadFn;
export declare function padLeft<T>(blockSize: number, inner: CoderType<T>, padFn: Option<PadFn>): CoderType<T>;
export declare function padRight<T>(blockSize: number, inner: CoderType<T>, padFn: Option<PadFn>): CoderType<T>;
export declare function pointer<T>(ptr: CoderType<number>, inner: CoderType<T>, sized?: boolean): CoderType<T>;
export declare function base64armor<T>(name: string, lineLen: number, inner: Coder<T, Bytes>, checksum?: (data: Bytes) => Bytes): Coder<T, string>;
export declare const nothing: CoderType<undefined>;
export declare function debug<T>(inner: CoderType<T>): CoderType<T>;
export declare const _TEST: {
_bitset: {
BITS: number;
FULL_MASK: number;
len: (len: number) => number;
create: (len: number) => Uint32Array;
clean: (bs: Uint32Array) => Uint32Array;
debug: (bs: Uint32Array) => string[];
checkLen: (bs: Uint32Array, len: number) => void;
chunkLen: (bsLen: number, pos: number, len: number) => void;
set: (bs: Uint32Array, chunk: number, value: number, allowRewrite?: boolean) => boolean;
pos: (pos: number, i: number) => {
chunk: number;
mask: number;
};
indices: (bs: Uint32Array, len: number, invert?: boolean) => number[];
range: (arr: number[]) => {
pos: number;
length: number;
}[];
rangeDebug: (bs: Uint32Array, len: number, invert?: boolean) => string;
setRange: (bs: Uint32Array, bsLen: number, pos: number, len: number, allowRewrite?: boolean) => boolean;
};
};
export {};
//# sourceMappingURL=index.d.ts.map
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff