functionalscript 0.8.1 → 0.9.1

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.
Files changed (68) hide show
  1. package/README.md +4 -4
  2. package/bnf/data/module.f.d.ts +10 -1
  3. package/bnf/data/module.f.js +58 -19
  4. package/bnf/data/test.f.d.ts +2 -0
  5. package/bnf/data/test.f.js +244 -3
  6. package/cas/module.f.d.ts +17 -0
  7. package/cas/module.f.js +77 -0
  8. package/cas/test.f.d.ts +2 -0
  9. package/cas/test.f.js +1 -0
  10. package/ci/module.f.js +8 -6
  11. package/crypto/secp/module.f.d.ts +10 -7
  12. package/crypto/secp/module.f.js +32 -12
  13. package/crypto/secp/test.f.js +4 -5
  14. package/crypto/sha2/module.f.js +0 -1
  15. package/crypto/sign/module.f.d.ts +17 -4
  16. package/crypto/sign/module.f.js +141 -47
  17. package/crypto/sign/test.f.d.ts +11 -1
  18. package/crypto/sign/test.f.js +631 -1
  19. package/dev/module.f.js +3 -2
  20. package/dev/version/module.f.d.ts +2 -2
  21. package/dev/version/module.f.js +4 -3
  22. package/dev/version/test.f.js +3 -2
  23. package/djs/module.f.d.ts +1 -1
  24. package/djs/module.f.js +4 -4
  25. package/djs/transpiler/module.f.js +3 -2
  26. package/djs/transpiler/test.f.js +12 -11
  27. package/fjs/module.f.d.ts +2 -0
  28. package/fjs/module.f.js +24 -0
  29. package/{dev/tf → fjs}/module.js +1 -1
  30. package/io/module.f.d.ts +4 -9
  31. package/io/virtual/module.f.d.ts +1 -1
  32. package/io/virtual/module.f.js +3 -3
  33. package/js/tokenizer/module.f.d.ts +1 -1
  34. package/js/tokenizer/module.f.js +0 -1
  35. package/nanvm-lib/tests/test.f.d.ts +1 -1
  36. package/nanvm-lib/tests/test.f.js +114 -104
  37. package/nanvm-lib/tests/vm/test.f.js +1 -1
  38. package/package.json +5 -7
  39. package/path/module.f.d.ts +3 -2
  40. package/types/btree/find/module.f.d.ts +7 -8
  41. package/types/btree/set/module.f.js +21 -0
  42. package/types/cbase32/module.f.d.ts +6 -0
  43. package/types/cbase32/module.f.js +71 -0
  44. package/types/cbase32/test.f.d.ts +7 -0
  45. package/types/cbase32/test.f.js +74 -0
  46. package/types/list/module.f.d.ts +1 -0
  47. package/types/list/module.f.js +2 -2
  48. package/types/nullable/module.f.d.ts +2 -0
  49. package/types/nullable/module.f.js +1 -0
  50. package/types/nullable/test.f.d.ts +1 -1
  51. package/types/nullable/test.f.js +23 -11
  52. package/types/option/module.f.d.ts +9 -0
  53. package/types/option/module.f.js +6 -0
  54. package/{crypto → types}/prime_field/module.f.d.ts +1 -1
  55. package/{crypto → types}/prime_field/module.f.js +1 -1
  56. package/types/uint8array/module.f.d.ts +11 -0
  57. package/types/uint8array/module.f.js +21 -0
  58. package/types/uint8array/test.f.d.ts +12 -0
  59. package/types/uint8array/test.f.js +58 -0
  60. package/crypto/rfc6979/module.f.d.ts +0 -15
  61. package/crypto/rfc6979/module.f.js +0 -98
  62. package/crypto/rfc6979/test.f.d.ts +0 -10
  63. package/crypto/rfc6979/test.f.js +0 -490
  64. package/fsc/module.d.ts +0 -2
  65. package/fsc/module.js +0 -4
  66. /package/{dev/tf → fjs}/module.d.ts +0 -0
  67. /package/{crypto → types}/prime_field/test.f.d.ts +0 -0
  68. /package/{crypto → types}/prime_field/test.f.js +0 -0
@@ -30,7 +30,20 @@ const reduceOp = ([i, x]) => a => {
30
30
  };
31
31
  const reduceBranch = fold(reduceOp);
32
32
  const nodeSet = (c) => (g) => (node) => {
33
+ // export type Result<T> = {
34
+ // readonly first: First<T>,
35
+ // readonly tail: Path<T>
36
+ //}
33
37
  const { first, tail } = find(c)(node);
38
+ // export type Index2 = 0 | 1
39
+ // export type Index3 = Index2 | 2 // 0 | 1 | 2
40
+ // export type Index4 = Index3 | 3 // 0 | 1 | 2 | 3
41
+ // export type Index5 = Index4 | 4 // 0 | 1 | 2 | 3 | 4
42
+ // type FirstLeaf1<T> = readonly[Index3, Leaf1<T>]
43
+ // type FirstBranch3<T> = readonly[1, Branch3<T>]
44
+ // type FirstLeaf2<T> = readonly[Index5, Leaf2<T>]
45
+ // type FirstBranch5<T> = readonly[1|3, Branch5<T>]
46
+ // export type First<T> = FirstLeaf1<T> | FirstBranch3<T> | FirstLeaf2<T> | FirstBranch5<T>
34
47
  const [i, x] = first;
35
48
  const f = () => {
36
49
  switch (i) {
@@ -66,6 +79,8 @@ const nodeSet = (c) => (g) => (node) => {
66
79
  case 2: {
67
80
  // insert
68
81
  const value = g(null);
82
+ // TODO: remove after TSGO fix the regression.
83
+ const _xl = x.length;
69
84
  switch (x.length) {
70
85
  case 1: {
71
86
  return [[x[0], value]];
@@ -74,9 +89,13 @@ const nodeSet = (c) => (g) => (node) => {
74
89
  return [[x[0]], value, [x[1]]];
75
90
  }
76
91
  }
92
+ // TODO: remove after TSGO fix the regression.
93
+ throw 'unreachable';
77
94
  }
78
95
  case 3: {
79
96
  // replace
97
+ // TODO: remove after TSGO fix the regression.
98
+ const _xl = x.length;
80
99
  switch (x.length) {
81
100
  case 2: {
82
101
  return [[x[0], g(x[1])]];
@@ -85,6 +104,8 @@ const nodeSet = (c) => (g) => (node) => {
85
104
  return [[x[0], x[1], x[2], g(x[3]), x[4]]];
86
105
  }
87
106
  }
107
+ // TODO: remove after TSGO fix the regression.
108
+ throw 'unreachable';
88
109
  }
89
110
  case 4: {
90
111
  // insert
@@ -0,0 +1,6 @@
1
+ import { type Vec } from "../bit_vec/module.f.ts";
2
+ import type { Nullable } from "../nullable/module.f.ts";
3
+ export declare const vec5xToCBase32: (v: Vec) => string;
4
+ export declare const vecToCBase32: (v: Vec) => string;
5
+ export declare const cBase32ToVec5x: (s: string) => Nullable<Vec>;
6
+ export declare const cBase32ToVec: (s: string) => Nullable<Vec>;
@@ -0,0 +1,71 @@
1
+ import { msb, lsb, length, vec, empty } from "../bit_vec/module.f.js";
2
+ // 0123456789abcdef
3
+ const m = '0123456789abcdefghjkmnpqrstvwxyz';
4
+ const { popFront, concat } = msb;
5
+ const popBack1 = lsb.popFront(1n);
6
+ const popFront5 = popFront(5n);
7
+ export const vec5xToCBase32 = (v) => {
8
+ let result = '';
9
+ while (true) {
10
+ const len = length(v);
11
+ if (len === 0n) {
12
+ break;
13
+ }
14
+ const [r, rest] = popFront5(v);
15
+ result += m[Number(r)];
16
+ v = rest;
17
+ }
18
+ return result;
19
+ };
20
+ export const vecToCBase32 = (v) => {
21
+ const len = length(v);
22
+ const extraLen = 5n - len % 5n;
23
+ const last = 1n << (extraLen - 1n);
24
+ const padded = concat(v)(vec(extraLen)(last));
25
+ return vec5xToCBase32(padded);
26
+ };
27
+ const vec5 = vec(5n);
28
+ const normalizeChar = (c) => {
29
+ const lower = c.toLowerCase();
30
+ switch (lower) {
31
+ case 'i': {
32
+ return '1';
33
+ }
34
+ case 'l': {
35
+ return '1';
36
+ }
37
+ case 'o': {
38
+ return '0';
39
+ }
40
+ default: {
41
+ return lower;
42
+ }
43
+ }
44
+ };
45
+ const toCrockfordIndex = (c) => m.indexOf(normalizeChar(c));
46
+ export const cBase32ToVec5x = (s) => {
47
+ let result = empty;
48
+ for (const c of s) {
49
+ const index = toCrockfordIndex(c);
50
+ if (index < 0) {
51
+ return null;
52
+ }
53
+ const v = vec5(BigInt(index));
54
+ result = concat(result)(v);
55
+ }
56
+ return result;
57
+ };
58
+ export const cBase32ToVec = (s) => {
59
+ let v = cBase32ToVec5x(s);
60
+ if (v === null || v === empty) {
61
+ return null;
62
+ }
63
+ // TODO: replace with a function that computes trailing zeros.
64
+ while (true) {
65
+ const [last, v0] = popBack1(v);
66
+ v = v0;
67
+ if (last === 1n) {
68
+ return v;
69
+ }
70
+ }
71
+ };
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ roundtrip5x: () => void;
3
+ roundtrip: () => void;
4
+ unalignedBits: () => void;
5
+ caseInsensitive: () => void;
6
+ };
7
+ export default _default;
@@ -0,0 +1,74 @@
1
+ import { empty, vec } from "../bit_vec/module.f.js";
2
+ import { cBase32ToVec, cBase32ToVec5x, vec5xToCBase32, vecToCBase32 } from "./module.f.js";
3
+ const check5x = (s, v) => {
4
+ const sr = vec5xToCBase32(v);
5
+ if (sr !== s) {
6
+ throw [sr, s];
7
+ }
8
+ const vr = cBase32ToVec5x(s);
9
+ if (vr !== v) {
10
+ throw [vr, v];
11
+ }
12
+ //
13
+ check(`${s}g`, v);
14
+ };
15
+ const check = (s, v) => {
16
+ const sr = vecToCBase32(v);
17
+ if (sr !== s) {
18
+ throw [sr, s];
19
+ }
20
+ const vr = cBase32ToVec(s);
21
+ if (vr !== v) {
22
+ throw [vr, v];
23
+ }
24
+ };
25
+ export default {
26
+ roundtrip5x: () => {
27
+ check5x("", empty);
28
+ check5x("0", vec(5n)(0n));
29
+ check5x("1", vec(5n)(1n));
30
+ check5x("7", vec(5n)(7n));
31
+ check5x("a", vec(5n)(10n));
32
+ check5x("b", vec(5n)(11n));
33
+ check5x("f", vec(5n)(15n));
34
+ check5x("gh", vec(10n)(529n));
35
+ check5x("jk", vec(10n)(595n));
36
+ check5x("mnpq", vec(20n)(677591n));
37
+ check5x("rstvwxyz", vec(40n)(852378941407n));
38
+ },
39
+ roundtrip: () => {
40
+ check("g", empty);
41
+ check("8", vec(1n)(0n));
42
+ check("r", vec(1n)(1n));
43
+ check("4", vec(2n)(0n));
44
+ check("c", vec(2n)(1n));
45
+ check("2", vec(3n)(0n));
46
+ check("1", vec(4n)(0n));
47
+ check("2g", vec(5n)(2n));
48
+ check("01", vec(9n)(0n));
49
+ },
50
+ unalignedBits: () => {
51
+ const v = vec(1n)(1n);
52
+ const cr = vec5xToCBase32(v);
53
+ if (cr !== "g") {
54
+ throw ['g', cr];
55
+ }
56
+ },
57
+ caseInsensitive: () => {
58
+ if (cBase32ToVec5x("A") !== cBase32ToVec5x("a")) {
59
+ throw 'case-insensitive expected';
60
+ }
61
+ if (cBase32ToVec5x("I") !== cBase32ToVec5x("1")) {
62
+ throw 'i maps to 1';
63
+ }
64
+ if (cBase32ToVec5x("l") !== cBase32ToVec5x("1")) {
65
+ throw 'l maps to 1';
66
+ }
67
+ if (cBase32ToVec5x("o") !== cBase32ToVec5x("0")) {
68
+ throw 'o maps to 0';
69
+ }
70
+ if (cBase32ToVec5x("u") !== null) {
71
+ throw 'should error on invalid character';
72
+ }
73
+ }
74
+ };
@@ -12,6 +12,7 @@ type Concat<T> = {
12
12
  readonly head: List<T>;
13
13
  readonly tail: List<T>;
14
14
  };
15
+ export declare const fromArrayLike: <T>(array: ArrayLike<T>) => Result<T>;
15
16
  export declare const concat: <T>(head: List<T>) => (tail: List<T>) => List<T>;
16
17
  export declare const next: <T>(head: List<T>) => Result<T>;
17
18
  export declare const iterable: <T>(list: List<T>) => Iterable<T>;
@@ -1,6 +1,6 @@
1
1
  import { identity, fn, compose } from "../function/module.f.js";
2
2
  import { addition, logicalNot, strictEqual, stateScanToScan, foldToScan, reduceToScan, } from "../function/operator/module.f.js";
3
- const fromArray = (array) => {
3
+ export const fromArrayLike = (array) => {
4
4
  const at = (i) => i < array.length ? { first: array[i], tail: () => at(i + 1) } : null;
5
5
  return at(0);
6
6
  };
@@ -16,7 +16,7 @@ export const next = (head) => {
16
16
  while (true) {
17
17
  head = trampoline(head);
18
18
  if (head instanceof Array) {
19
- head = fromArray(head);
19
+ head = fromArrayLike(head);
20
20
  }
21
21
  else if (head !== null && 'head' in head) {
22
22
  [head, tail] = [head.head, concat(head.tail)(tail)];
@@ -1,3 +1,5 @@
1
+ import type { Option } from '../option/module.f.ts';
1
2
  export type Nullable<T> = T | null;
2
3
  export declare const map: <T, R>(f: (value: T) => R) => (value: Nullable<T>) => Nullable<R>;
3
4
  export declare const match: <T, R>(f: (_: T) => R) => (none: () => R) => (_: Nullable<T>) => Nullable<R>;
5
+ export declare const toOption: <T>(value: Nullable<T>) => Option<T>;
@@ -1,2 +1,3 @@
1
1
  export const map = f => value => value === null ? null : f(value);
2
2
  export const match = f => none => value => value === null ? none() : f(value);
3
+ export const toOption = (value) => value === null ? [] : [value];
@@ -1,2 +1,2 @@
1
- declare const _default: () => void;
1
+ declare const _default: (() => void)[];
2
2
  export default _default;
@@ -1,12 +1,24 @@
1
- import { map } from "./module.f.js";
2
- export default () => {
3
- const optionSq = map((v) => v * v);
4
- const sq3 = optionSq(3);
5
- if (sq3 !== 9) {
6
- throw sq3;
1
+ import { map, toOption } from "./module.f.js";
2
+ export default [
3
+ () => {
4
+ const optionSq = map((v) => v * v);
5
+ const sq3 = optionSq(3);
6
+ if (sq3 !== 9) {
7
+ throw sq3;
8
+ }
9
+ const sqNull = optionSq(null);
10
+ if (sqNull !== null) {
11
+ throw sqNull;
12
+ }
13
+ },
14
+ () => {
15
+ const opt1 = toOption(5);
16
+ if (opt1.length !== 1 || opt1[0] !== 5) {
17
+ throw opt1;
18
+ }
19
+ const opt2 = toOption(null);
20
+ if (opt2.length !== 0) {
21
+ throw opt2;
22
+ }
7
23
  }
8
- const sqNull = optionSq(null);
9
- if (sqNull !== null) {
10
- throw sqNull;
11
- }
12
- };
24
+ ];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Optional tuple-based value representation.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Represents an optional value as an empty tuple or a tuple with one value.
8
+ */
9
+ export type Option<T> = readonly [T] | readonly [];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Optional tuple-based value representation.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
@@ -1,4 +1,4 @@
1
- import type { Unary, Reduce } from '../../types/bigint/module.f.ts';
1
+ import type { Unary, Reduce } from '../bigint/module.f.ts';
2
2
  /**
3
3
  * A type representing a prime field and its associated operations.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { repeat } from "../../types/monoid/module.f.js";
1
+ import { repeat } from "../monoid/module.f.js";
2
2
  /**
3
3
  * Creates a prime field with the specified prime modulus and associated operations.
4
4
  *
@@ -0,0 +1,11 @@
1
+ import { type Vec } from "../bit_vec/module.f.ts";
2
+ /**
3
+ * Converts a Uint8Array into an MSB-first bit vector.
4
+ */
5
+ export declare const toVec: (input: Uint8Array) => Vec;
6
+ /**
7
+ * Converts an MSB-first bit vector into a Uint8Array.
8
+ */
9
+ export declare const fromVec: (input: Vec) => Uint8Array;
10
+ export declare const decodeUtf8: (input: Uint8Array) => string;
11
+ export declare const encodeUtf8: (input: string) => Uint8Array;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Conversions between Uint8Array values and bit vectors.
3
+ *
4
+ * @module
5
+ */
6
+ import { utf8, utf8ToString } from "../../text/module.f.js";
7
+ import { msb, u8List, u8ListToVec } from "../bit_vec/module.f.js";
8
+ import { compose } from "../function/module.f.js";
9
+ import { fromArrayLike, iterable } from "../list/module.f.js";
10
+ const u8ListToVecMsb = u8ListToVec(msb);
11
+ const u8ListMsb = u8List(msb);
12
+ /**
13
+ * Converts a Uint8Array into an MSB-first bit vector.
14
+ */
15
+ export const toVec = (input) => u8ListToVecMsb(fromArrayLike(input));
16
+ /**
17
+ * Converts an MSB-first bit vector into a Uint8Array.
18
+ */
19
+ export const fromVec = (input) => Uint8Array.from(iterable(u8ListMsb(input)));
20
+ export const decodeUtf8 = compose(toVec)(utf8ToString);
21
+ export const encodeUtf8 = compose(utf8)(fromVec);
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ empty: () => void;
3
+ roundTrip: () => void;
4
+ unalignedLength: () => void;
5
+ encodeUtf8Empty: () => void;
6
+ encodeUtf8Ascii: () => void;
7
+ encodeUtf8Multibyte: () => void;
8
+ decodeUtf8Ascii: () => void;
9
+ decodeUtf8Multibyte: () => void;
10
+ utf8RoundTrip: () => void;
11
+ };
12
+ export default _default;
@@ -0,0 +1,58 @@
1
+ import { vec } from "../bit_vec/module.f.js";
2
+ import { toVec, fromVec, decodeUtf8, encodeUtf8 } from "./module.f.js";
3
+ import { strictEqual } from "../function/operator/module.f.js";
4
+ import { equal, fromArrayLike } from "../list/module.f.js";
5
+ const assertEq = (a, b) => {
6
+ if (a !== b) {
7
+ throw [a, b];
8
+ }
9
+ };
10
+ const assertArrayEq = (a, b) => {
11
+ if (!equal(strictEqual)(fromArrayLike(a))(fromArrayLike(b))) {
12
+ throw [a, b];
13
+ }
14
+ };
15
+ export default {
16
+ empty: () => {
17
+ const input = new Uint8Array();
18
+ const vec = toVec(input);
19
+ const output = fromVec(vec);
20
+ assertArrayEq(output, input);
21
+ },
22
+ roundTrip: () => {
23
+ const input = Uint8Array.from([0, 1, 2, 3, 255]);
24
+ const vec = toVec(input);
25
+ const output = fromVec(vec);
26
+ assertArrayEq(output, input);
27
+ },
28
+ unalignedLength: () => {
29
+ const input = vec(4n)(0xfn);
30
+ const output = fromVec(input);
31
+ assertArrayEq(output, Uint8Array.from([0xF0]));
32
+ },
33
+ encodeUtf8Empty: () => {
34
+ const output = encodeUtf8('');
35
+ assertArrayEq(output, new Uint8Array());
36
+ },
37
+ encodeUtf8Ascii: () => {
38
+ const output = encodeUtf8('Hi!');
39
+ assertArrayEq(output, Uint8Array.from([72, 105, 33]));
40
+ },
41
+ encodeUtf8Multibyte: () => {
42
+ const output = encodeUtf8('✓');
43
+ assertArrayEq(output, Uint8Array.from([0xE2, 0x9C, 0x93]));
44
+ },
45
+ decodeUtf8Ascii: () => {
46
+ const output = decodeUtf8(Uint8Array.from([102, 115]));
47
+ assertEq(output, 'fs');
48
+ },
49
+ decodeUtf8Multibyte: () => {
50
+ const output = decodeUtf8(Uint8Array.from([0xE2, 0x9C, 0x93]));
51
+ assertEq(output, '✓');
52
+ },
53
+ utf8RoundTrip: () => {
54
+ const input = 'FunctionalScript 🐝';
55
+ const output = decodeUtf8(encodeUtf8(input));
56
+ assertEq(output, input);
57
+ }
58
+ };
@@ -1,15 +0,0 @@
1
- import { type Vec } from '../../types/bit_vec/module.f.ts';
2
- import type { Curve } from '../secp/module.f.ts';
3
- import { type Sha2 } from '../sha2/module.f.ts';
4
- export type All = {
5
- readonly q: bigint;
6
- readonly qlen: bigint;
7
- readonly bits2int: (b: Vec) => bigint;
8
- readonly int2octets: (x: bigint) => Vec;
9
- readonly bits2octets: (b: Vec) => Vec;
10
- };
11
- export declare const all: (q: bigint) => All;
12
- export declare const fromCurve: (c: Curve) => All;
13
- export declare const concat: (...x: readonly Vec[]) => Vec;
14
- export declare const computeK: ({ q, bits2int, qlen, int2octets, bits2octets }: All) => (hf: Sha2) => (x: bigint) => (m: Vec) => bigint;
15
- export declare const sign: (a: All) => (hf: Sha2) => (x: bigint) => (m: Vec) => bigint;
@@ -1,98 +0,0 @@
1
- import { todo } from "../../dev/module.f.js";
2
- import { bitLength, divUp, roundUp } from "../../types/bigint/module.f.js";
3
- import { empty, length, listToVec, msb, repeat, unpack, vec, vec8 } from "../../types/bit_vec/module.f.js";
4
- import { hmac } from "../hmac/module.f.js";
5
- import { computeSync } from "../sha2/module.f.js";
6
- // qlen to rlen
7
- const roundUp8 = roundUp(8n);
8
- const divUp8 = divUp(8n);
9
- export const all = (q) => {
10
- const qlen = bitLength(q);
11
- const bits2int = (b) => {
12
- const { length, uint } = unpack(b);
13
- const diff = length - qlen;
14
- return diff > 0n ? uint >> diff : uint;
15
- };
16
- const int2octets = vec(roundUp8(qlen));
17
- return {
18
- q,
19
- qlen,
20
- bits2int,
21
- int2octets,
22
- // since z2 < 2*q, we can use simple mod with `z1 < q ? z1 : z1 - q`
23
- bits2octets: b => int2octets(bits2int(b) % q),
24
- };
25
- };
26
- export const fromCurve = (c) => all(c.nf.p);
27
- const v0 = vec8(0x01n);
28
- const k0 = vec8(0x00n);
29
- const ltov = listToVec(msb);
30
- export const concat = (...x) => ltov(x);
31
- export const computeK = ({ q, bits2int, qlen, int2octets, bits2octets }) => (hf) => (x) => (m) => {
32
- const hmacf = hmac(hf);
33
- // a. Process m through the hash function H, yielding:
34
- // h1 = H(m)
35
- // (h1 is a sequence of hlen bits).
36
- const h1 = computeSync(hf)([m]);
37
- // b. Set:
38
- // V = 0x01 0x01 0x01 ... 0x01
39
- // such that the length of V, in bits, is equal to 8*ceil(hlen/8).
40
- // For instance, on an octet-based system, if H is SHA-256, then V
41
- // is set to a sequence of 32 octets of value 1. Note that in this
42
- // step and all subsequent steps, we use the same H function as the
43
- // one used in step 'a' to process the input message; this choice
44
- // will be discussed in more detail in Section 3.6.
45
- const rep = repeat(divUp8(hf.hashLength));
46
- let v = rep(v0);
47
- // c. Set:
48
- // K = 0x00 0x00 0x00 ... 0x00
49
- // such that the length of K, in bits, is equal to 8*ceil(hlen/8).
50
- let k = rep(k0);
51
- // d. Set:
52
- // K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1))
53
- // where '||' denotes concatenation.
54
- const xh1 = concat(int2octets(x), bits2octets(h1));
55
- k = hmacf(k)(concat(v, k0, xh1));
56
- // e. Set:
57
- // V = HMAC_K(V)
58
- v = hmacf(k)(v);
59
- // f. Set:
60
- // K = HMAC_K(V || 0x01 || int2octets(x) || bits2octets(h1))
61
- k = hmacf(k)(concat(v, v0, xh1));
62
- // g. Set:
63
- // V = HMAC_K(V)
64
- v = hmacf(k)(v);
65
- // h. Apply the following algorithm until a proper value is for `k`:
66
- while (true) {
67
- // h. Apply the following algorithm until a proper value is for `k`:
68
- // 1. Set `T` to the empty sequence, so `tlen = 0`.
69
- let t = empty;
70
- // 2. while `tlen < qlen` do:
71
- // - `V = HMAC_K(V)`
72
- // - `T = T || V`
73
- // Possible optimizations:
74
- // - precompute number of iterations
75
- // - `qlen` can't be 0, so we can avoid the first check and
76
- // first concatenation.
77
- while (length(t) < qlen) {
78
- v = hmacf(k)(v);
79
- t = concat(t, v);
80
- }
81
- // 3. Compute `k = bits2int(T)`. If `k` is not in `[1, q-1]` or `kG = 0` then
82
- // - `K = HMAC_K(V || 0x00)`
83
- // - `V = HMAC_K(V)`
84
- // and loop (try to generate a new `T`, and so on). Return to step `1`.
85
- const result = bits2int(t);
86
- if (0n < result && result < q) {
87
- return result;
88
- }
89
- k = hmacf(k)(concat(v, k0));
90
- v = hmacf(k)(v);
91
- }
92
- };
93
- export const sign = (a) => (hf) => (x) => (m) => {
94
- const hm = computeSync(hf)([m]);
95
- const h = a.bits2int(hm) % a.q;
96
- ///
97
- return todo();
98
- };
@@ -1,10 +0,0 @@
1
- declare const _default: {
2
- bits2int: () => void;
3
- int2octets: () => void;
4
- bit2octets: () => void;
5
- k: () => void;
6
- computeK: () => void;
7
- investigate: () => void;
8
- a2: () => void;
9
- };
10
- export default _default;