@statewalker/webrun-biscuit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +262 -0
- package/dist/authorizer.d.ts +112 -0
- package/dist/authorizer.d.ts.map +1 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/builder.d.ts +52 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/crypto.d.ts +22 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/datalog.d.ts +203 -0
- package/dist/datalog.d.ts.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3130 -0
- package/dist/parser.d.ts +80 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/print.d.ts +12 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/proto.d.ts +132 -0
- package/dist/proto.d.ts.map +1 -0
- package/dist/version.d.ts +42 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +58 -0
- package/src/authorizer.ts +581 -0
- package/src/base64.ts +42 -0
- package/src/builder.ts +360 -0
- package/src/crypto.ts +208 -0
- package/src/datalog.ts +722 -0
- package/src/index.ts +93 -0
- package/src/parser.ts +606 -0
- package/src/print.ts +147 -0
- package/src/proto.ts +770 -0
- package/src/version.ts +158 -0
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the Biscuit Datalog text syntax (SPECIFICATIONS.md grammar).
|
|
3
|
+
* Hand-written recursive descent + precedence climbing; expressions are
|
|
4
|
+
* compiled straight to the opcode form the VM executes.
|
|
5
|
+
*/
|
|
6
|
+
import { type Check, type Fact, type Op, type Predicate, type Rule, type Scope, type Term } from "./datalog.js";
|
|
7
|
+
export declare class ParseError extends Error {
|
|
8
|
+
}
|
|
9
|
+
export type Statement = {
|
|
10
|
+
k: "fact";
|
|
11
|
+
fact: Fact;
|
|
12
|
+
} | {
|
|
13
|
+
k: "rule";
|
|
14
|
+
rule: Rule;
|
|
15
|
+
} | {
|
|
16
|
+
k: "check";
|
|
17
|
+
check: Check;
|
|
18
|
+
} | {
|
|
19
|
+
k: "policy";
|
|
20
|
+
kind: "allow" | "deny";
|
|
21
|
+
queries: Rule[];
|
|
22
|
+
} | {
|
|
23
|
+
k: "blockScope";
|
|
24
|
+
scopes: Scope[];
|
|
25
|
+
};
|
|
26
|
+
export declare class Parser {
|
|
27
|
+
private readonly src;
|
|
28
|
+
private i;
|
|
29
|
+
private readonly vars;
|
|
30
|
+
constructor(src: string, vars?: Map<string, number>);
|
|
31
|
+
/** id -> name, for printing rules back out */
|
|
32
|
+
variableNames(): Map<number, string>;
|
|
33
|
+
varId(name: string): number;
|
|
34
|
+
private ws;
|
|
35
|
+
private get eof();
|
|
36
|
+
private peek;
|
|
37
|
+
private eat;
|
|
38
|
+
private expect;
|
|
39
|
+
/** keyword: matches only if not followed by a name character */
|
|
40
|
+
private keyword;
|
|
41
|
+
/** variable names, unlike predicate names, may start with a digit ($0) */
|
|
42
|
+
private variableName;
|
|
43
|
+
private name;
|
|
44
|
+
private string;
|
|
45
|
+
private tryDate;
|
|
46
|
+
/** a term that may be a variable (rule/check context) */
|
|
47
|
+
term(allowVariables?: boolean): Term;
|
|
48
|
+
private array;
|
|
49
|
+
private setOrMap;
|
|
50
|
+
private asMapKey;
|
|
51
|
+
predicate(allowVariables?: boolean): Predicate;
|
|
52
|
+
/** precedence climbing; each level returns opcodes in postfix order */
|
|
53
|
+
expression(): Op[];
|
|
54
|
+
private orExpr;
|
|
55
|
+
private andExpr;
|
|
56
|
+
private comparison;
|
|
57
|
+
/** avoids matching "==" when the source really has "===" */
|
|
58
|
+
private peekOperator;
|
|
59
|
+
private bitXor;
|
|
60
|
+
private bitOr;
|
|
61
|
+
private bitAnd;
|
|
62
|
+
private additive;
|
|
63
|
+
/** `-` starts a negative literal only when it is not an infix position */
|
|
64
|
+
private peekSign;
|
|
65
|
+
private multiplicative;
|
|
66
|
+
private unary;
|
|
67
|
+
private primary;
|
|
68
|
+
private methods;
|
|
69
|
+
private closure;
|
|
70
|
+
private scopes;
|
|
71
|
+
/** body of a rule / check / policy: predicates, expressions, trusting */
|
|
72
|
+
private ruleBody;
|
|
73
|
+
/** a predicate is only a predicate if nothing operator-like follows it */
|
|
74
|
+
private tryPredicate;
|
|
75
|
+
private queries;
|
|
76
|
+
statement(): Statement;
|
|
77
|
+
parse(): Statement[];
|
|
78
|
+
}
|
|
79
|
+
export declare const parse: (src: string) => Statement[];
|
|
80
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,IAAI,EAGT,KAAK,EAAE,EACP,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,IAAI,EAEV,MAAM,cAAc,CAAC;AAEtB,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAExC,MAAM,MAAM,SAAS,GACjB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACzB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACzB;IAAE,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC5B;IAAE,CAAC,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,IAAI,EAAE,CAAA;CAAE,GACxD;IAAE,CAAC,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,KAAK,EAAE,CAAA;CAAE,CAAC;AAKzC,qBAAa,MAAM;IAIf,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHtB,OAAO,CAAC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AO,CAAC,QAAQ;IA0BhB,0EAA0E;IAC1E,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,OAAO;IASf,SAAS,IAAI,SAAS,CAgCrB;IAED,KAAK,IAAI,SAAS,EAAE,CAQnB;CACF;AAED,eAAO,MAAM,KAAK,QAAS,MAAM,KAAG,SAAS,EAA6B,CAAC"}
|
package/dist/print.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Datalog pretty-printer (used for error messages and world snapshots). */
|
|
2
|
+
import { type Check, type Op, type Predicate, type Rule, type Scope, type Term } from "./datalog.js";
|
|
3
|
+
export declare function printTerm(t: Term, varName: (id: number) => string): string;
|
|
4
|
+
export declare const printPredicate: (p: Predicate, varName: (id: number) => string) => string;
|
|
5
|
+
export declare function printExpression(ops: Op[], varName: (id: number) => string): string;
|
|
6
|
+
export declare function printScopes(scopes: Scope[]): string;
|
|
7
|
+
/** the body of a rule, check or policy: predicates, then expressions */
|
|
8
|
+
export declare function printQuery(r: Rule, varName: (id: number) => string): string;
|
|
9
|
+
export declare function printCheck(c: Check, varName: (id: number) => string): string;
|
|
10
|
+
export declare function printPolicy(kind: "allow" | "deny", queries: Rule[], varName: (id: number) => string): string;
|
|
11
|
+
export declare function printRule(r: Rule, varName: (id: number) => string): string;
|
|
12
|
+
//# sourceMappingURL=print.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../src/print.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,EAAE,EACP,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,IAAI,EAEV,MAAM,cAAc,CAAC;AAStB,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAyB1E;AAED,eAAO,MAAM,cAAc,MAAO,SAAS,WAAW,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,KAAG,MACT,CAAC;AAwCvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAoBlF;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAMnD;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,OAAO,GAAG,MAAM,EACtB,OAAO,EAAE,IAAI,EAAE,EACf,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAC9B,MAAM,CAER;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAM1E"}
|
package/dist/proto.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict proto2 codec for the Biscuit schema.
|
|
3
|
+
*
|
|
4
|
+
* Written against src/schema.proto. Unlike a generated codec it: decodes
|
|
5
|
+
* int64/uint64 as BigInt, tracks proto2 `optional` presence, validates UTF-8
|
|
6
|
+
* strictly, and rejects unknown fields, wrong wire types and missing
|
|
7
|
+
* `required` fields.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProtoError extends Error {
|
|
10
|
+
}
|
|
11
|
+
export type Algorithm = 0 | 1;
|
|
12
|
+
export interface PublicKeyMsg {
|
|
13
|
+
algorithm: Algorithm;
|
|
14
|
+
key: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
export interface ExternalSignature {
|
|
17
|
+
signature: Uint8Array;
|
|
18
|
+
publicKey: PublicKeyMsg;
|
|
19
|
+
}
|
|
20
|
+
export interface SignedBlock {
|
|
21
|
+
block: Uint8Array;
|
|
22
|
+
nextKey: PublicKeyMsg;
|
|
23
|
+
signature: Uint8Array;
|
|
24
|
+
externalSignature?: ExternalSignature;
|
|
25
|
+
version?: number;
|
|
26
|
+
}
|
|
27
|
+
export type Proof = {
|
|
28
|
+
kind: "nextSecret";
|
|
29
|
+
value: Uint8Array;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "finalSignature";
|
|
32
|
+
value: Uint8Array;
|
|
33
|
+
};
|
|
34
|
+
export interface BiscuitMsg {
|
|
35
|
+
rootKeyId?: number;
|
|
36
|
+
authority: SignedBlock;
|
|
37
|
+
blocks: SignedBlock[];
|
|
38
|
+
proof: Proof;
|
|
39
|
+
}
|
|
40
|
+
export type TermMsg = {
|
|
41
|
+
kind: "variable";
|
|
42
|
+
value: number;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "integer";
|
|
45
|
+
value: bigint;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "string";
|
|
48
|
+
value: number;
|
|
49
|
+
} | {
|
|
50
|
+
kind: "date";
|
|
51
|
+
value: bigint;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "bytes";
|
|
54
|
+
value: Uint8Array;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "bool";
|
|
57
|
+
value: boolean;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "set";
|
|
60
|
+
value: TermMsg[];
|
|
61
|
+
} | {
|
|
62
|
+
kind: "null";
|
|
63
|
+
} | {
|
|
64
|
+
kind: "array";
|
|
65
|
+
value: TermMsg[];
|
|
66
|
+
} | {
|
|
67
|
+
kind: "map";
|
|
68
|
+
value: MapEntryMsg[];
|
|
69
|
+
};
|
|
70
|
+
export type MapKeyMsg = {
|
|
71
|
+
kind: "integer";
|
|
72
|
+
value: bigint;
|
|
73
|
+
} | {
|
|
74
|
+
kind: "string";
|
|
75
|
+
value: number;
|
|
76
|
+
};
|
|
77
|
+
export interface MapEntryMsg {
|
|
78
|
+
key: MapKeyMsg;
|
|
79
|
+
value: TermMsg;
|
|
80
|
+
}
|
|
81
|
+
export type OpMsg = {
|
|
82
|
+
kind: "value";
|
|
83
|
+
value: TermMsg;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "unary";
|
|
86
|
+
op: number;
|
|
87
|
+
ffiName?: number;
|
|
88
|
+
} | {
|
|
89
|
+
kind: "binary";
|
|
90
|
+
op: number;
|
|
91
|
+
ffiName?: number;
|
|
92
|
+
} | {
|
|
93
|
+
kind: "closure";
|
|
94
|
+
params: number[];
|
|
95
|
+
ops: OpMsg[];
|
|
96
|
+
};
|
|
97
|
+
export interface PredicateMsg {
|
|
98
|
+
name: number;
|
|
99
|
+
terms: TermMsg[];
|
|
100
|
+
}
|
|
101
|
+
export type ScopeMsg = {
|
|
102
|
+
kind: "type";
|
|
103
|
+
value: 0 | 1;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "publicKey";
|
|
106
|
+
value: number;
|
|
107
|
+
};
|
|
108
|
+
export interface RuleMsg {
|
|
109
|
+
head: PredicateMsg;
|
|
110
|
+
body: PredicateMsg[];
|
|
111
|
+
expressions: OpMsg[][];
|
|
112
|
+
scope: ScopeMsg[];
|
|
113
|
+
}
|
|
114
|
+
export interface CheckMsg {
|
|
115
|
+
queries: RuleMsg[];
|
|
116
|
+
kind?: 0 | 1 | 2;
|
|
117
|
+
}
|
|
118
|
+
export interface BlockMsg {
|
|
119
|
+
symbols: string[];
|
|
120
|
+
context?: string;
|
|
121
|
+
version?: number;
|
|
122
|
+
facts: PredicateMsg[];
|
|
123
|
+
rules: RuleMsg[];
|
|
124
|
+
checks: CheckMsg[];
|
|
125
|
+
scope: ScopeMsg[];
|
|
126
|
+
publicKeys: PublicKeyMsg[];
|
|
127
|
+
}
|
|
128
|
+
export declare function decodeBiscuit(buf: Uint8Array): BiscuitMsg;
|
|
129
|
+
export declare function decodeBlock(buf: Uint8Array): BlockMsg;
|
|
130
|
+
export declare function encodeBiscuit(v: BiscuitMsg): Uint8Array;
|
|
131
|
+
export declare function encodeBlock(b: BlockMsg): Uint8Array;
|
|
132
|
+
//# sourceMappingURL=proto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../src/proto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAqIxC,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;AAE9B,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,GAAG,EAAE,UAAU,CAAC;CACjB;AACD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,YAAY,CAAC;CACzB;AACD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAElD,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,WAAW,CAAC;IACvB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CA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wHD,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,UAAU,CAoBnD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Datalog block versioning.
|
|
3
|
+
*
|
|
4
|
+
* Every block declares the Datalog version it was generated at. An
|
|
5
|
+
* implementation must reject versions outside the supported window, and must
|
|
6
|
+
* reject a block that uses a feature newer than the version it declares —
|
|
7
|
+
* otherwise a token could smuggle newer semantics past an older verifier.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `get_schema_version` / `check_compatibility` in the reference
|
|
10
|
+
* implementation (biscuit-auth `src/datalog/mod.rs`).
|
|
11
|
+
*/
|
|
12
|
+
import { type Check, type Fact, type Rule, type Scope } from "./datalog.js";
|
|
13
|
+
import type { CheckMsg } from "./proto.js";
|
|
14
|
+
export declare const MIN_SCHEMA_VERSION = 3;
|
|
15
|
+
export declare const MAX_SCHEMA_VERSION = 6;
|
|
16
|
+
export declare const DATALOG_3_1 = 4;
|
|
17
|
+
export declare const DATALOG_3_2 = 5;
|
|
18
|
+
export declare const DATALOG_3_3 = 6;
|
|
19
|
+
export declare class VersionError extends Error {
|
|
20
|
+
}
|
|
21
|
+
export interface BlockContentLike {
|
|
22
|
+
facts: Fact[];
|
|
23
|
+
rules: Rule[];
|
|
24
|
+
checks: Check[];
|
|
25
|
+
scopes: Scope[];
|
|
26
|
+
}
|
|
27
|
+
export interface BlockFeatures {
|
|
28
|
+
scopes: boolean;
|
|
29
|
+
v31: boolean;
|
|
30
|
+
checkAll: boolean;
|
|
31
|
+
v33: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare function blockFeatures(c: BlockContentLike): BlockFeatures;
|
|
34
|
+
/** the lowest version that can legally carry this block's content */
|
|
35
|
+
export declare function requiredVersion(c: BlockContentLike): number;
|
|
36
|
+
/**
|
|
37
|
+
* Rejects a block whose declared version is out of range, or which uses a
|
|
38
|
+
* feature newer than that version. `rawChecks` is needed because the gate on
|
|
39
|
+
* check kinds distinguishes an absent kind from an explicit `One`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateBlockVersion(declared: number | undefined, rawChecks: CheckMsg[], hasExternalKey: boolean, content: BlockContentLike): void;
|
|
42
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,IAAI,EAGT,KAAK,IAAI,EACT,KAAK,KAAK,EAGX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAyCD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;CACd;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,gBAAgB,GAAG,aAAa,CAsBhE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAK3D;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,SAAS,EAAE,QAAQ,EAAE,EACrB,cAAc,EAAE,OAAO,EACvB,OAAO,EAAE,gBAAgB,GACxB,IAAI,CA4BN"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@statewalker/webrun-biscuit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Biscuit authorization tokens in pure TypeScript: proto2 codec, Ed25519 and secp256r1 signature chain, Datalog engine, parser, authorizer and builder. No WASM, no Node built-ins — runs in Node, browsers, Workers and Durable Objects.",
|
|
7
|
+
"homepage": "https://github.com/statewalker/webrun-wire",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Mikhail Kotelnikov",
|
|
10
|
+
"email": "mikhail.kotelnikov@gmail.com"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git@github.com:statewalker/webrun-wire.git",
|
|
16
|
+
"directory": "packages/webrun-biscuit"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@noble/curves": "^2.4.0",
|
|
30
|
+
"@noble/hashes": "^2.4.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@biscuit-auth/biscuit-wasm": "^0.6.0",
|
|
34
|
+
"rimraf": "^6.1.3",
|
|
35
|
+
"rolldown": "^1.2.4",
|
|
36
|
+
"typescript": "^7.0.2",
|
|
37
|
+
"vitest": "^4.1.10"
|
|
38
|
+
},
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"samples": "node scripts/fetch-samples.mjs",
|
|
46
|
+
"build": "rimraf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
|
|
47
|
+
"test": "pnpm run samples && vitest run",
|
|
48
|
+
"test:watch": "pnpm run samples && vitest",
|
|
49
|
+
"test:cross": "vitest run --config vitest.cross.config.ts",
|
|
50
|
+
"test:all": "pnpm run test && pnpm run test:cross",
|
|
51
|
+
"mutate": "pnpm run samples && node scripts/mutate.mjs",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"typecheck:tests": "tsc -p tsconfig.tests.json",
|
|
54
|
+
"clean": "rimraf dist",
|
|
55
|
+
"lint": "biome check src tests",
|
|
56
|
+
"format": "biome format --write ."
|
|
57
|
+
}
|
|
58
|
+
}
|