signify-ts 0.2.0 → 0.3.0-dev.e31e78d
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/README.md +104 -34
- package/dist/exports.d.ts +40 -40
- package/dist/exports.js +40 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -8
- package/dist/keri/app/aiding.d.ts +54 -18
- package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
- package/dist/keri/app/clienting.d.ts +59 -22
- package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
- package/dist/keri/app/contacting.d.ts +30 -23
- package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
- package/dist/keri/app/controller.d.ts +49 -6
- package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
- package/dist/keri/app/coring.d.ts +134 -25
- package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
- package/dist/keri/app/credentialing.d.ts +191 -67
- package/dist/keri/app/credentialing.js +540 -0
- package/dist/keri/app/delegating.d.ts +18 -0
- package/dist/keri/app/delegating.js +24 -0
- package/dist/keri/app/escrowing.d.ts +5 -3
- package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
- package/dist/keri/app/exchanging.d.ts +243 -11
- package/dist/keri/app/exchanging.js +242 -0
- package/dist/keri/app/grouping.d.ts +11 -9
- package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
- package/dist/keri/app/habery.d.ts +2 -2
- package/dist/keri/app/habery.js +117 -0
- package/dist/keri/app/notifying.d.ts +2 -2
- package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
- package/dist/keri/core/authing.d.ts +2 -2
- package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
- package/dist/keri/core/base64.d.ts +2 -0
- package/dist/keri/core/base64.js +16 -0
- package/dist/keri/core/bexter.d.ts +1 -1
- package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
- package/dist/keri/core/cigar.d.ts +2 -2
- package/dist/keri/core/cigar.js +13 -0
- package/dist/keri/core/cipher.d.ts +1 -1
- package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
- package/dist/keri/core/core.d.ts +117 -9
- package/dist/keri/core/core.js +385 -0
- package/dist/keri/core/counter.d.ts +2 -2
- package/dist/keri/core/counter.js +221 -0
- package/dist/keri/core/decrypter.d.ts +4 -4
- package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
- package/dist/keri/core/diger.d.ts +3 -3
- package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
- package/dist/keri/core/encrypter.d.ts +2 -2
- package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
- package/dist/keri/core/eventing.d.ts +6 -6
- package/dist/keri/core/eventing.js +383 -0
- package/dist/keri/core/httping.d.ts +11 -4
- package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
- package/dist/keri/core/indexer.d.ts +1 -1
- package/dist/keri/core/indexer.js +407 -0
- package/dist/keri/core/keeping.d.ts +113 -46
- package/dist/keri/core/keeping.js +347 -0
- package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
- package/dist/keri/core/keyState.d.ts +98 -0
- package/dist/keri/core/manager.d.ts +147 -12
- package/dist/keri/core/manager.js +880 -0
- package/dist/keri/core/matter.d.ts +1 -1
- package/dist/keri/core/matter.js +460 -0
- package/dist/keri/core/number.d.ts +2 -2
- package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
- package/dist/keri/core/pather.d.ts +2 -2
- package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
- package/dist/keri/core/prefixer.d.ts +10 -10
- package/dist/keri/core/prefixer.js +182 -0
- package/dist/keri/core/saider.d.ts +2 -12
- package/dist/keri/core/saider.js +107 -0
- package/dist/keri/core/salter.d.ts +44 -9
- package/dist/keri/core/salter.js +110 -0
- package/dist/keri/core/seqner.d.ts +1 -1
- package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
- package/dist/keri/core/serder.d.ts +25 -12
- package/dist/keri/core/serder.js +133 -0
- package/dist/keri/core/siger.d.ts +2 -2
- package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
- package/dist/keri/core/signer.d.ts +4 -4
- package/dist/keri/core/signer.js +84 -0
- package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
- package/dist/keri/core/utils.d.ts +1 -1
- package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
- package/dist/keri/core/vdring.d.ts +2 -2
- package/dist/keri/core/vdring.js +61 -0
- package/dist/keri/core/verfer.d.ts +2 -6
- package/dist/keri/core/verfer.js +37 -0
- package/dist/keri/end/ending.d.ts +10 -8
- package/dist/keri/end/ending.js +136 -0
- package/{src/ready.ts → dist/ready.js} +1 -2
- package/dist/types/keria-api-schema.d.ts +1158 -0
- package/dist/types/keria-api-schema.js +34 -0
- package/package.json +53 -52
- package/dist/math.d.ts +0 -1
- package/dist/signify-ts.cjs +0 -7835
- package/dist/signify-ts.cjs.development.js +0 -9501
- package/dist/signify-ts.cjs.development.js.map +0 -1
- package/dist/signify-ts.cjs.map +0 -7
- package/dist/signify-ts.cjs.production.min.js +0 -2
- package/dist/signify-ts.cjs.production.min.js.map +0 -1
- package/dist/signify-ts.esm.js +0 -9345
- package/dist/signify-ts.esm.js.map +0 -1
- package/dist/signify-ts.mjs +0 -7811
- package/dist/signify-ts.mjs.map +0 -7
- package/src/buffer-polyfill.ts +0 -5
- package/src/exports.ts +0 -44
- package/src/index.ts +0 -4
- package/src/keri/app/credentialing.ts +0 -820
- package/src/keri/app/exchanging.ts +0 -220
- package/src/keri/app/habery.ts +0 -185
- package/src/keri/core/cigar.ts +0 -18
- package/src/keri/core/core.ts +0 -326
- package/src/keri/core/counter.ts +0 -273
- package/src/keri/core/eventing.ts +0 -581
- package/src/keri/core/indexer.ts +0 -509
- package/src/keri/core/keeping.ts +0 -684
- package/src/keri/core/manager.ts +0 -1183
- package/src/keri/core/matter.ts +0 -521
- package/src/keri/core/prefixer.ts +0 -233
- package/src/keri/core/saider.ts +0 -186
- package/src/keri/core/salter.ts +0 -120
- package/src/keri/core/serder.ts +0 -163
- package/src/keri/core/signer.ts +0 -133
- package/src/keri/core/vdring.ts +0 -94
- package/src/keri/core/verfer.ts +0 -47
- package/src/keri/end/ending.ts +0 -170
- package/src/math.ts +0 -3
- /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { MtrDex } from "./matter.js";
|
|
2
|
+
import { deversify, Protocols, Serials, versify, Vrsn_1_0, } from "./core.js";
|
|
3
|
+
import { Verfer } from "./verfer.js";
|
|
4
|
+
import { Diger } from "./diger.js";
|
|
5
|
+
import { CesrNumber } from "./number.js";
|
|
6
|
+
export class Serder {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Serder object from a self-addressing data dictionary.
|
|
9
|
+
* @param sad self-addressing data dictionary.
|
|
10
|
+
* @param kind serialization type to produce
|
|
11
|
+
* @param code derivation code for the prefix
|
|
12
|
+
*/
|
|
13
|
+
constructor(sad, kind = Serials.JSON, code = MtrDex.Blake3_256) {
|
|
14
|
+
this._raw = '';
|
|
15
|
+
this._sad = {};
|
|
16
|
+
this._proto = Protocols.KERI;
|
|
17
|
+
this._size = 0;
|
|
18
|
+
this._version = Vrsn_1_0;
|
|
19
|
+
const [raw, proto, eKind, eSad, version] = this._exhale(sad, kind);
|
|
20
|
+
this._raw = raw;
|
|
21
|
+
this._sad = eSad;
|
|
22
|
+
this._proto = proto;
|
|
23
|
+
this._version = version;
|
|
24
|
+
this._code = code;
|
|
25
|
+
this._kind = eKind;
|
|
26
|
+
this._size = raw.length;
|
|
27
|
+
}
|
|
28
|
+
get sad() {
|
|
29
|
+
return this._sad;
|
|
30
|
+
}
|
|
31
|
+
get pre() {
|
|
32
|
+
return this._sad['i'];
|
|
33
|
+
}
|
|
34
|
+
get code() {
|
|
35
|
+
return this._code;
|
|
36
|
+
}
|
|
37
|
+
get raw() {
|
|
38
|
+
return this._raw;
|
|
39
|
+
}
|
|
40
|
+
get said() {
|
|
41
|
+
return this._sad['d'];
|
|
42
|
+
}
|
|
43
|
+
get sner() {
|
|
44
|
+
return new CesrNumber({}, this.sad['s']);
|
|
45
|
+
}
|
|
46
|
+
get sn() {
|
|
47
|
+
return this.sner.num;
|
|
48
|
+
}
|
|
49
|
+
get kind() {
|
|
50
|
+
return this._kind;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serializes a self-addressing data dictionary from the dictionary passed in
|
|
54
|
+
* using the specified serialization type.
|
|
55
|
+
* @param sad self-addressing data dictionary.
|
|
56
|
+
* @param kind serialization type to produce
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
_exhale(sad, kind) {
|
|
60
|
+
return sizeify(sad, kind);
|
|
61
|
+
}
|
|
62
|
+
get proto() {
|
|
63
|
+
return this._proto;
|
|
64
|
+
}
|
|
65
|
+
get size() {
|
|
66
|
+
return this._size;
|
|
67
|
+
}
|
|
68
|
+
get version() {
|
|
69
|
+
return this._version;
|
|
70
|
+
}
|
|
71
|
+
get verfers() {
|
|
72
|
+
let keys = [];
|
|
73
|
+
if ('k' in this._sad) {
|
|
74
|
+
// establishment event
|
|
75
|
+
keys = this._sad['k'];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// non-establishment event
|
|
79
|
+
keys = [];
|
|
80
|
+
}
|
|
81
|
+
// create a new Verfer for each key
|
|
82
|
+
const verfers = [];
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
verfers.push(new Verfer({ qb64: key }));
|
|
85
|
+
}
|
|
86
|
+
return verfers;
|
|
87
|
+
}
|
|
88
|
+
get digers() {
|
|
89
|
+
let keys = [];
|
|
90
|
+
if ('n' in this._sad) {
|
|
91
|
+
// establishment event
|
|
92
|
+
keys = this._sad['n'];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// non-establishment event
|
|
96
|
+
keys = [];
|
|
97
|
+
}
|
|
98
|
+
// create a new Verfer for each key
|
|
99
|
+
const digers = [];
|
|
100
|
+
for (const key of keys) {
|
|
101
|
+
digers.push(new Diger({ qb64: key }));
|
|
102
|
+
}
|
|
103
|
+
return digers;
|
|
104
|
+
}
|
|
105
|
+
pretty() {
|
|
106
|
+
return JSON.stringify(this._sad, undefined, 2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function dumps(sad, kind) {
|
|
110
|
+
if (kind == Serials.JSON) {
|
|
111
|
+
return JSON.stringify(sad);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw new Error('unsupported event encoding');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export function sizeify(ked, kind) {
|
|
118
|
+
if (!('v' in ked)) {
|
|
119
|
+
throw new Error('Missing or empty version string');
|
|
120
|
+
}
|
|
121
|
+
const [proto, knd, version] = deversify(ked['v']);
|
|
122
|
+
if (version != Vrsn_1_0) {
|
|
123
|
+
throw new Error(`unsupported version ${version.toString()}`);
|
|
124
|
+
}
|
|
125
|
+
if (kind == undefined) {
|
|
126
|
+
kind = knd;
|
|
127
|
+
}
|
|
128
|
+
let raw = dumps(ked, kind);
|
|
129
|
+
const size = new TextEncoder().encode(raw).length;
|
|
130
|
+
ked['v'] = versify(proto, version, kind, size);
|
|
131
|
+
raw = dumps(ked, kind);
|
|
132
|
+
return [raw, proto, kind, ked, version];
|
|
133
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Indexer, IndexerArgs } from './indexer';
|
|
2
|
-
import { Verfer } from './verfer';
|
|
1
|
+
import { Indexer, IndexerArgs } from './indexer.ts';
|
|
2
|
+
import { Verfer } from './verfer.ts';
|
|
3
3
|
/**
|
|
4
4
|
Siger is subclass of Indexer, indexed signature material,
|
|
5
5
|
Adds .verfer property which is instance of Verfer that provides
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { IdxSigDex, Indexer
|
|
2
|
-
import { Verfer } from './verfer';
|
|
3
|
-
|
|
1
|
+
import { IdxSigDex, Indexer } from "./indexer.js";
|
|
4
2
|
/**
|
|
5
3
|
Siger is subclass of Indexer, indexed signature material,
|
|
6
4
|
Adds .verfer property which is instance of Verfer that provides
|
|
@@ -15,26 +13,18 @@ import { Verfer } from './verfer';
|
|
|
15
13
|
|
|
16
14
|
Methods:
|
|
17
15
|
**/
|
|
18
|
-
|
|
19
16
|
export class Siger extends Indexer {
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
{ raw, code, index, ondex, qb64, qb64b, qb2 }: IndexerArgs,
|
|
23
|
-
verfer?: Verfer
|
|
24
|
-
) {
|
|
17
|
+
constructor({ raw, code, index, ondex, qb64, qb64b, qb2 }, verfer) {
|
|
25
18
|
super({ raw, code, index, ondex, qb64, qb64b, qb2 });
|
|
26
|
-
|
|
27
19
|
if (!IdxSigDex.has(this.code)) {
|
|
28
20
|
throw new Error(`Invalid code = ${this.code} for Siger.`);
|
|
29
21
|
}
|
|
30
22
|
this._verfer = verfer;
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
get verfer(): Verfer | undefined {
|
|
24
|
+
get verfer() {
|
|
34
25
|
return this._verfer;
|
|
35
26
|
}
|
|
36
|
-
|
|
37
|
-
set verfer(verfer: Verfer | undefined) {
|
|
27
|
+
set verfer(verfer) {
|
|
38
28
|
this._verfer = verfer;
|
|
39
29
|
}
|
|
40
30
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
import { Matter } from './matter';
|
|
3
|
-
import { Verfer } from './verfer';
|
|
4
|
-
import { Cigar } from './cigar';
|
|
5
|
-
import { Siger } from './siger';
|
|
2
|
+
import { Matter } from './matter.ts';
|
|
3
|
+
import { Verfer } from './verfer.ts';
|
|
4
|
+
import { Cigar } from './cigar.ts';
|
|
5
|
+
import { Siger } from './siger.ts';
|
|
6
6
|
/**
|
|
7
7
|
* @description Signer is Matter subclass with method to create signature of serialization
|
|
8
8
|
* It will use .raw as signing (private) key seed
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { EmptyMaterialError } from "./kering.js";
|
|
2
|
+
import libsodium from 'libsodium-wrappers-sumo';
|
|
3
|
+
import { Matter } from "./matter.js";
|
|
4
|
+
import { MtrDex } from "./matter.js";
|
|
5
|
+
import { Verfer } from "./verfer.js";
|
|
6
|
+
import { Cigar } from "./cigar.js";
|
|
7
|
+
import { Siger } from "./siger.js";
|
|
8
|
+
import { IdrDex } from "./indexer.js";
|
|
9
|
+
import { concat } from "./core.js";
|
|
10
|
+
export class Signer extends Matter {
|
|
11
|
+
constructor({ raw, code = MtrDex.Ed25519_Seed, qb64, qb64b, qb2, transferable = true, }) {
|
|
12
|
+
try {
|
|
13
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
if (e instanceof EmptyMaterialError) {
|
|
17
|
+
if (code == MtrDex.Ed25519_Seed) {
|
|
18
|
+
const raw = libsodium.randombytes_buf(libsodium.crypto_sign_SEEDBYTES);
|
|
19
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new Error(`Unsupported signer code = ${code}.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let verfer;
|
|
30
|
+
if (this.code == MtrDex.Ed25519_Seed) {
|
|
31
|
+
this._sign = this._ed25519;
|
|
32
|
+
const keypair = libsodium.crypto_sign_seed_keypair(this.raw);
|
|
33
|
+
verfer = new Verfer({
|
|
34
|
+
raw: keypair.publicKey,
|
|
35
|
+
code: transferable ? MtrDex.Ed25519 : MtrDex.Ed25519N,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error(`Unsupported signer code = ${this.code}.`);
|
|
40
|
+
}
|
|
41
|
+
this._verfer = verfer;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @description Property verfer:
|
|
45
|
+
Returns Verfer instance
|
|
46
|
+
Assumes ._verfer is correctly assigned
|
|
47
|
+
*/
|
|
48
|
+
get verfer() {
|
|
49
|
+
return this._verfer;
|
|
50
|
+
}
|
|
51
|
+
sign(ser, index = null, only = false, ondex = undefined) {
|
|
52
|
+
return this._sign(ser, this.raw, this.verfer, index, only, ondex);
|
|
53
|
+
}
|
|
54
|
+
_ed25519(ser, seed, verfer, index, only = false, ondex) {
|
|
55
|
+
const sig = libsodium.crypto_sign_detached(ser, concat(seed, verfer.raw));
|
|
56
|
+
if (index == null) {
|
|
57
|
+
return new Cigar({ raw: sig, code: MtrDex.Ed25519_Sig }, verfer);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
let code;
|
|
61
|
+
if (only) {
|
|
62
|
+
ondex = undefined;
|
|
63
|
+
if (index <= 63) {
|
|
64
|
+
code = IdrDex.Ed25519_Crt_Sig;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
code = IdrDex.Ed25519_Big_Crt_Sig;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (ondex == undefined) {
|
|
72
|
+
ondex = index;
|
|
73
|
+
}
|
|
74
|
+
if (ondex == index && index <= 63)
|
|
75
|
+
// both same and small
|
|
76
|
+
code = IdrDex.Ed25519_Sig; // use small both same
|
|
77
|
+
// otherwise big or both not same so use big both
|
|
78
|
+
else
|
|
79
|
+
code = IdrDex.Ed25519_Big_Sig; // use use big both
|
|
80
|
+
}
|
|
81
|
+
return new Siger({ raw: sig, code: code, index: index, ondex: ondex }, verfer);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -1,83 +1,76 @@
|
|
|
1
|
-
import { BexDex, Matter, NumDex } from
|
|
2
|
-
import { CesrNumber } from
|
|
3
|
-
import {
|
|
4
|
-
import { math } from '../../index';
|
|
5
|
-
|
|
1
|
+
import { BexDex, Matter, NumDex } from "./matter.js";
|
|
2
|
+
import { CesrNumber } from "./number.js";
|
|
3
|
+
import { format, sum, fraction } from 'mathjs';
|
|
6
4
|
export class Tholder {
|
|
7
|
-
private _weighted: boolean = false;
|
|
8
|
-
private _thold: any = undefined;
|
|
9
|
-
private _size: number = 0;
|
|
10
|
-
private _number: CesrNumber | undefined = undefined;
|
|
11
|
-
private _satisfy: any = undefined;
|
|
12
|
-
|
|
13
5
|
// private _bexter: any
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
constructor(kargs) {
|
|
7
|
+
this._weighted = false;
|
|
8
|
+
this._thold = undefined;
|
|
9
|
+
this._size = 0;
|
|
10
|
+
this._number = undefined;
|
|
11
|
+
this._satisfy = undefined;
|
|
16
12
|
if (kargs.thold !== undefined) {
|
|
17
13
|
this._processThold(kargs.thold);
|
|
18
|
-
}
|
|
14
|
+
}
|
|
15
|
+
else if (kargs.limen != undefined) {
|
|
19
16
|
this._processLimen(kargs.limen);
|
|
20
|
-
}
|
|
17
|
+
}
|
|
18
|
+
else if (kargs.sith !== undefined) {
|
|
21
19
|
this._processSith(kargs.sith);
|
|
22
|
-
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
23
22
|
throw new Error('Missing threshold expression');
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
get weighted(): boolean {
|
|
25
|
+
get weighted() {
|
|
28
26
|
return this._weighted;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
get thold(): any {
|
|
28
|
+
get thold() {
|
|
32
29
|
return this._thold;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
get size(): number {
|
|
31
|
+
get size() {
|
|
36
32
|
return this._size;
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return this._number
|
|
34
|
+
get limen() {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = this._number) === null || _a === void 0 ? void 0 : _a.qb64b;
|
|
41
37
|
}
|
|
42
|
-
|
|
43
|
-
get sith(): string {
|
|
38
|
+
get sith() {
|
|
44
39
|
if (this.weighted) {
|
|
45
|
-
let sith = this.thold.map((clause
|
|
40
|
+
let sith = this.thold.map((clause) => {
|
|
46
41
|
return clause.map((c) => {
|
|
47
42
|
if (0 < Number(c) && Number(c) < 1) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
43
|
+
return format(c, { fraction: 'ratio' });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return format(c, { fraction: 'decimal' });
|
|
51
47
|
}
|
|
52
48
|
});
|
|
53
49
|
});
|
|
54
50
|
if (sith.length == 1) {
|
|
55
51
|
sith = sith[0];
|
|
56
52
|
}
|
|
57
|
-
|
|
58
53
|
return sith;
|
|
59
|
-
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
60
56
|
return this.thold.toString(16);
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
get json(): string {
|
|
59
|
+
get json() {
|
|
65
60
|
return JSON.stringify(this.sith);
|
|
66
61
|
}
|
|
67
|
-
|
|
68
|
-
get num(): number | undefined {
|
|
62
|
+
get num() {
|
|
69
63
|
return this._weighted ? undefined : this._thold;
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
private _processThold(thold: number | Array<Array<Fraction>>) {
|
|
65
|
+
_processThold(thold) {
|
|
73
66
|
if (typeof thold === 'number') {
|
|
74
67
|
this._processUnweighted(thold);
|
|
75
|
-
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
76
70
|
this._processWeighted(thold);
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
|
-
|
|
80
|
-
private _processLimen(limen: string) {
|
|
73
|
+
_processLimen(limen) {
|
|
81
74
|
const matter = new Matter({ qb64: limen });
|
|
82
75
|
if (NumDex.has(matter.code)) {
|
|
83
76
|
const number = new CesrNumber({
|
|
@@ -85,67 +78,59 @@ export class Tholder {
|
|
|
85
78
|
code: matter.code,
|
|
86
79
|
});
|
|
87
80
|
this._processUnweighted(number.num);
|
|
88
|
-
}
|
|
81
|
+
}
|
|
82
|
+
else if (BexDex.has(matter.code)) {
|
|
89
83
|
// TODO: Implement Bexter
|
|
90
|
-
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
91
86
|
throw new Error('Invalid code for limen=' + matter.code);
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
|
-
|
|
95
|
-
private _processSith(sith: string | number | Array<string>) {
|
|
89
|
+
_processSith(sith) {
|
|
96
90
|
if (typeof sith == 'number') {
|
|
97
91
|
this._processUnweighted(sith);
|
|
98
|
-
}
|
|
92
|
+
}
|
|
93
|
+
else if (typeof sith == 'string' && sith.indexOf('[') == -1) {
|
|
99
94
|
this._processUnweighted(parseInt(sith, 16));
|
|
100
|
-
}
|
|
101
|
-
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
let _sith = sith;
|
|
102
98
|
if (typeof sith == 'string') {
|
|
103
99
|
_sith = JSON.parse(sith);
|
|
104
100
|
}
|
|
105
|
-
|
|
106
101
|
if (_sith.length == 0) {
|
|
107
102
|
throw new Error('Empty weight list');
|
|
108
103
|
}
|
|
109
|
-
|
|
110
|
-
const mask = _sith.map((x: any) => {
|
|
104
|
+
const mask = _sith.map((x) => {
|
|
111
105
|
return typeof x !== 'string';
|
|
112
106
|
});
|
|
113
|
-
|
|
114
|
-
if (mask.length > 0 && !mask.every((x: boolean) => x)) {
|
|
107
|
+
if (mask.length > 0 && !mask.every((x) => x)) {
|
|
115
108
|
_sith = [_sith];
|
|
116
109
|
}
|
|
117
|
-
|
|
118
110
|
for (const c of _sith) {
|
|
119
|
-
const mask = c.map((x
|
|
111
|
+
const mask = c.map((x) => {
|
|
120
112
|
return typeof x === 'string';
|
|
121
113
|
});
|
|
122
|
-
if (mask.length > 0 && !mask.every((x
|
|
123
|
-
throw new Error(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
' are non string'
|
|
127
|
-
);
|
|
114
|
+
if (mask.length > 0 && !mask.every((x) => x)) {
|
|
115
|
+
throw new Error('Invalid sith, some weights in clause ' +
|
|
116
|
+
mask +
|
|
117
|
+
' are non string');
|
|
128
118
|
}
|
|
129
119
|
}
|
|
130
|
-
|
|
131
120
|
const thold = this._processClauses(_sith);
|
|
132
121
|
this._processWeighted(thold);
|
|
133
122
|
}
|
|
134
123
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const thold = new Array<Array<Fraction>>();
|
|
124
|
+
_processClauses(sith) {
|
|
125
|
+
const thold = new Array();
|
|
138
126
|
sith.forEach((clause) => {
|
|
139
|
-
thold.push(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
})
|
|
143
|
-
);
|
|
127
|
+
thold.push(clause.map((w) => {
|
|
128
|
+
return this.weight(w);
|
|
129
|
+
}));
|
|
144
130
|
});
|
|
145
131
|
return thold;
|
|
146
132
|
}
|
|
147
|
-
|
|
148
|
-
private _processUnweighted(thold: number) {
|
|
133
|
+
_processUnweighted(thold) {
|
|
149
134
|
if (thold < 0) {
|
|
150
135
|
throw new Error('Non-positive int threshold = {thold}.');
|
|
151
136
|
}
|
|
@@ -156,18 +141,14 @@ export class Tholder {
|
|
|
156
141
|
this._number = new CesrNumber({}, thold);
|
|
157
142
|
// this._bexter = undefined
|
|
158
143
|
}
|
|
159
|
-
|
|
160
|
-
private _processWeighted(thold: Array<Array<Fraction>>) {
|
|
144
|
+
_processWeighted(thold) {
|
|
161
145
|
for (const clause of thold) {
|
|
162
|
-
if (Number(
|
|
163
|
-
throw new Error(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
'all clause weight sums must be >= 1'
|
|
167
|
-
);
|
|
146
|
+
if (Number(sum(clause)) < 1) {
|
|
147
|
+
throw new Error('Invalid sith clause: ' +
|
|
148
|
+
thold +
|
|
149
|
+
'all clause weight sums must be >= 1');
|
|
168
150
|
}
|
|
169
151
|
}
|
|
170
|
-
|
|
171
152
|
this._thold = thold;
|
|
172
153
|
this._weighted = true;
|
|
173
154
|
this._size = thold.reduce((acc, currentValue) => {
|
|
@@ -176,21 +157,17 @@ export class Tholder {
|
|
|
176
157
|
this._satisfy = this._satisfy_weighted;
|
|
177
158
|
//TODO: created Bexter if needed
|
|
178
159
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return math.fraction(w);
|
|
160
|
+
weight(w) {
|
|
161
|
+
return fraction(w);
|
|
182
162
|
}
|
|
183
|
-
|
|
184
|
-
private _satisfy_numeric(indices: any[]) {
|
|
163
|
+
_satisfy_numeric(indices) {
|
|
185
164
|
return this.thold > 0 && indices.length >= this.thold; // at least one
|
|
186
165
|
}
|
|
187
|
-
|
|
188
|
-
private _satisfy_weighted(indices: any) {
|
|
166
|
+
_satisfy_weighted(indices) {
|
|
189
167
|
if (indices.length === 0) {
|
|
190
168
|
return false;
|
|
191
169
|
}
|
|
192
|
-
|
|
193
|
-
const indexes: Set<number> = new Set(indices.sort());
|
|
170
|
+
const indexes = new Set(indices.sort());
|
|
194
171
|
const sats = new Array(indices.length).fill(false);
|
|
195
172
|
for (const idx of indexes) {
|
|
196
173
|
sats[idx] = true;
|
|
@@ -208,11 +185,9 @@ export class Tholder {
|
|
|
208
185
|
return false;
|
|
209
186
|
}
|
|
210
187
|
}
|
|
211
|
-
|
|
212
188
|
return true;
|
|
213
189
|
}
|
|
214
|
-
|
|
215
|
-
public satisfy(indices: any): boolean {
|
|
190
|
+
satisfy(indices) {
|
|
216
191
|
return this._satisfy(indices);
|
|
217
192
|
}
|
|
218
193
|
}
|