@caict/bop-typescript-sdk 1.0.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +112 -0
  5. package/package.json +90 -0
  6. package/src/bop/bop-base/README.md +5 -0
  7. package/src/bop/bop-base/base.ts +366 -0
  8. package/src/bop/bop-base/index.ts +83 -0
  9. package/src/bop/bop-base/permit.ts +116 -0
  10. package/src/bop/bop-base/test/base.test.ts +867 -0
  11. package/src/bop/bop-base/test/index.test.ts +69 -0
  12. package/src/bop/bop-base/test/permit.test.ts +125 -0
  13. package/src/bop/bop-base/tsconfig.json +8 -0
  14. package/src/bop/bop-proto/README.md +2 -0
  15. package/src/bop/bop-proto/bop-ws.proto +266 -0
  16. package/src/bop/bop-proto/bop-ws.ts +4447 -0
  17. package/src/bop/bop-proto/bop.proto +898 -0
  18. package/src/bop/bop-proto/bop.ts +12890 -0
  19. package/src/bop/bop-proto/tsconfig.json +8 -0
  20. package/src/bop/bop-ws/index.ts +315 -0
  21. package/src/bop/bop-ws/sample/sample.ts +107 -0
  22. package/src/bop/bop-ws/tsconfig.json +8 -0
  23. package/src/bop/index.ts +14 -0
  24. package/src/bop-sdk/index.ts +22 -0
  25. package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
  26. package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
  27. package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
  28. package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
  29. package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
  30. package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
  31. package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
  32. package/src/bop-sdk/interface/provider-ws.ts +10 -0
  33. package/src/bop-sdk/interface/provider.ts +22 -0
  34. package/src/bop-sdk/interface/service/3rd.ts +54 -0
  35. package/src/bop-sdk/interface/service/account.ts +86 -0
  36. package/src/bop-sdk/interface/service/chain.ts +27 -0
  37. package/src/bop-sdk/interface/service/contract.ts +51 -0
  38. package/src/bop-sdk/interface/service/helper.ts +426 -0
  39. package/src/bop-sdk/interface/service/ledger.ts +75 -0
  40. package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
  41. package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
  42. package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
  43. package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
  44. package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
  45. package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
  46. package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
  47. package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
  48. package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
  49. package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
  50. package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
  51. package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
  52. package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
  53. package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
  54. package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
  55. package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
  56. package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
  57. package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
  58. package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
  59. package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
  60. package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
  61. package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
  62. package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
  63. package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
  64. package/src/bop-sdk/interface/service/transaction.ts +731 -0
  65. package/src/bop-sdk/interface/signer.ts +46 -0
  66. package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
  67. package/src/bop-sdk/interface/test/account.test.ts +284 -0
  68. package/src/bop-sdk/interface/test/chain.test.ts +45 -0
  69. package/src/bop-sdk/interface/test/contract.test.ts +283 -0
  70. package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
  71. package/src/bop-sdk/interface/test/provider.test.ts +407 -0
  72. package/src/bop-sdk/interface/test/signer.test.ts +105 -0
  73. package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
  74. package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
  75. package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
  76. package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
  77. package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
  78. package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
  79. package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
  80. package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
  81. package/src/bop-sdk/utils/abi/address.ts +109 -0
  82. package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
  83. package/src/bop-sdk/utils/abi/bytes.ts +565 -0
  84. package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
  85. package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
  86. package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
  87. package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
  88. package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
  89. package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
  90. package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
  91. package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
  92. package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
  93. package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
  94. package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
  95. package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
  96. package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
  97. package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
  98. package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
  99. package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
  100. package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
  101. package/src/bop-sdk/utils/abi/id.ts +6 -0
  102. package/src/bop-sdk/utils/abi/index.ts +46 -0
  103. package/src/bop-sdk/utils/abi/interface.ts +921 -0
  104. package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
  105. package/src/bop-sdk/utils/abi/properties.ts +172 -0
  106. package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
  107. package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
  108. package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
  109. package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
  110. package/src/bop-sdk/utils/encryption-address.ts +501 -0
  111. package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
  112. package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
  113. package/src/bop-sdk/utils/index.ts +27 -0
  114. package/src/bop-sdk/utils/logger.ts +480 -0
  115. package/src/index.ts +35 -0
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ import sha3 from "js-sha3";
4
+
5
+ import { arrayify, BytesLike } from "./bytes";
6
+
7
+ export function keccak256(data: BytesLike): string {
8
+ return "0x" + sha3.keccak_256(arrayify(data));
9
+ }
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ import { Logger } from "../logger";
4
+ const version = "properties/5.7.0";
5
+ const logger = new Logger(version);
6
+
7
+ export function defineReadOnly<T, K extends keyof T>(
8
+ object: T,
9
+ name: K,
10
+ value: T[K],
11
+ ): void {
12
+ Object.defineProperty(object, name, {
13
+ enumerable: true,
14
+ value: value,
15
+ writable: false,
16
+ });
17
+ }
18
+
19
+ // Crawl up the constructor chain to find a static method
20
+ export function getStatic<T>(ctor: any, key: string): T {
21
+ for (let i = 0; i < 32; i++) {
22
+ if (ctor[key]) {
23
+ return ctor[key];
24
+ }
25
+ if (!ctor.prototype || typeof ctor.prototype !== "object") {
26
+ break;
27
+ }
28
+ ctor = Object.getPrototypeOf(ctor.prototype).constructor;
29
+ }
30
+ return null;
31
+ }
32
+
33
+ export type Deferrable<T> = {
34
+ [K in keyof T]: T[K] | Promise<T[K]>;
35
+ };
36
+
37
+ type Result = { key: string; value: any };
38
+
39
+ export async function resolveProperties<T>(
40
+ object: Readonly<Deferrable<T>>,
41
+ ): Promise<T> {
42
+ const promises: Array<Promise<Result>> = Object.keys(object).map((key) => {
43
+ const value = object[<keyof Deferrable<T>>key];
44
+ return Promise.resolve(value).then((v) => ({ key: key, value: v }));
45
+ });
46
+
47
+ const results = await Promise.all(promises);
48
+
49
+ return results.reduce(
50
+ (accum, result) => {
51
+ accum[<keyof T>result.key] = result.value;
52
+ return accum;
53
+ },
54
+ <T>{},
55
+ );
56
+ }
57
+
58
+ export function checkProperties(
59
+ object: any,
60
+ properties: { [name: string]: boolean },
61
+ ): void {
62
+ if (!object || typeof object !== "object") {
63
+ logger.throwArgumentError("invalid object", "object", object);
64
+ }
65
+
66
+ Object.keys(object).forEach((key) => {
67
+ if (!properties[key]) {
68
+ logger.throwArgumentError(
69
+ "invalid object key - " + key,
70
+ "transaction:" + key,
71
+ object,
72
+ );
73
+ }
74
+ });
75
+ }
76
+
77
+ export function shallowCopy<T>(object: T): T {
78
+ const result: any = {};
79
+ for (const key in object) {
80
+ result[key] = object[key];
81
+ }
82
+ return result;
83
+ }
84
+
85
+ const opaque: { [key: string]: boolean } = {
86
+ bigint: true,
87
+ boolean: true,
88
+ function: true,
89
+ number: true,
90
+ string: true,
91
+ };
92
+
93
+ function _isFrozen(object: any): boolean {
94
+ // Opaque objects are not mutable, so safe to copy by assignment
95
+ if (object === undefined || object === null || opaque[typeof object]) {
96
+ return true;
97
+ }
98
+
99
+ if (Array.isArray(object) || typeof object === "object") {
100
+ if (!Object.isFrozen(object)) {
101
+ return false;
102
+ }
103
+
104
+ const keys = Object.keys(object);
105
+ for (let i = 0; i < keys.length; i++) {
106
+ let value: any = null;
107
+ try {
108
+ value = object[keys[i]];
109
+ } catch (error) {
110
+ // If accessing a value triggers an error, it is a getter
111
+ // designed to do so (e.g. Result) and is therefore "frozen"
112
+ continue;
113
+ }
114
+
115
+ if (!_isFrozen(value)) {
116
+ return false;
117
+ }
118
+ }
119
+
120
+ return true;
121
+ }
122
+
123
+ return logger.throwArgumentError(
124
+ `Cannot deepCopy ${typeof object}`,
125
+ "object",
126
+ object,
127
+ );
128
+ }
129
+
130
+ // Returns a new copy of object, such that no properties may be replaced.
131
+ // New properties may be added only to objects.
132
+ function _deepCopy(object: any): any {
133
+ if (_isFrozen(object)) {
134
+ return object;
135
+ }
136
+
137
+ // Arrays are mutable, so we need to create a copy
138
+ if (Array.isArray(object)) {
139
+ return Object.freeze(object.map((item) => deepCopy(item)));
140
+ }
141
+
142
+ if (typeof object === "object") {
143
+ const result: { [key: string]: any } = {};
144
+ for (const key in object) {
145
+ const value = object[key];
146
+ if (value === undefined) {
147
+ continue;
148
+ }
149
+ defineReadOnly(result, key, deepCopy(value));
150
+ }
151
+
152
+ return result;
153
+ }
154
+
155
+ return logger.throwArgumentError(
156
+ `Cannot deepCopy ${typeof object}`,
157
+ "object",
158
+ object,
159
+ );
160
+ }
161
+
162
+ export function deepCopy<T>(object: T): T {
163
+ return _deepCopy(object);
164
+ }
165
+
166
+ export class Description<T = any> {
167
+ constructor(info: { [K in keyof T]: T[K] }) {
168
+ for (const key in info) {
169
+ (<any>this)[key] = deepCopy(info[key]);
170
+ }
171
+ }
172
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ import { HashZero } from "../constants";
4
+ import { arrayify, BytesLike, concat, hexlify } from "../bytes";
5
+
6
+ import { toUtf8Bytes, toUtf8String } from "./utf8";
7
+
8
+ export function formatBytes32String(text: string): string {
9
+ // Get the bytes
10
+ const bytes = toUtf8Bytes(text);
11
+
12
+ // Check we have room for null-termination
13
+ if (bytes.length > 31) {
14
+ throw new Error("bytes32 string must be less than 32 bytes");
15
+ }
16
+
17
+ // Zero-pad (implicitly null-terminates)
18
+ return hexlify(concat([bytes, HashZero]).slice(0, 32));
19
+ }
20
+
21
+ export function parseBytes32String(bytes: BytesLike): string {
22
+ const data = arrayify(bytes);
23
+
24
+ // Must be 32 bytes with a null-termination
25
+ if (data.length !== 32) {
26
+ throw new Error("invalid bytes32 - not 32 bytes long");
27
+ }
28
+ if (data[31] !== 0) {
29
+ throw new Error("invalid bytes32 string - no null terminator");
30
+ }
31
+
32
+ // Find the null termination
33
+ let length = 31;
34
+ while (data[length - 1] === 0) {
35
+ length--;
36
+ }
37
+
38
+ // Determine the string value
39
+ return toUtf8String(data.slice(0, length));
40
+ }
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+
3
+ import {
4
+ toUtf8CodePoints,
5
+ _toUtf8String,
6
+ UnicodeNormalizationForm,
7
+ } from "./utf8";
8
+
9
+ type Ranged = {
10
+ l: number; // Lo value
11
+ h: number; // High value (less the lo)
12
+ d?: number; // Delta/stride (default: 1)
13
+ s?: number; // Shift (default: 1)
14
+ e?: Array<number>; // Exceptions to skip
15
+ };
16
+
17
+ type Table = { [src: number]: Array<number> };
18
+
19
+ function bytes2(data: string): Array<number> {
20
+ if (data.length % 4 !== 0) {
21
+ throw new Error("bad data");
22
+ }
23
+ let result = [];
24
+ for (let i = 0; i < data.length; i += 4) {
25
+ result.push(parseInt(data.substring(i, i + 4), 16));
26
+ }
27
+ return result;
28
+ }
29
+
30
+ function createTable(
31
+ data: string,
32
+ func?: (value: string) => Array<number>,
33
+ ): Table {
34
+ if (!func) {
35
+ func = function (value: string) {
36
+ return [parseInt(value, 16)];
37
+ };
38
+ }
39
+
40
+ let lo = 0;
41
+
42
+ let result: Table = {};
43
+ data.split(",").forEach((pair) => {
44
+ let comps = pair.split(":");
45
+ lo += parseInt(comps[0], 16);
46
+ result[lo] = func(comps[1]);
47
+ });
48
+
49
+ return result;
50
+ }
51
+
52
+ function createRangeTable(data: string): Array<Ranged> {
53
+ let hi = 0;
54
+ return data.split(",").map((v) => {
55
+ let comps = v.split("-");
56
+ if (comps.length === 1) {
57
+ comps[1] = "0";
58
+ } else if (comps[1] === "") {
59
+ comps[1] = "1";
60
+ }
61
+
62
+ let lo = hi + parseInt(comps[0], 16);
63
+ hi = parseInt(comps[1], 16);
64
+ return { l: lo, h: hi };
65
+ });
66
+ }
67
+
68
+ function matchMap(value: number, ranges: Array<Ranged>): Ranged {
69
+ let lo = 0;
70
+ for (let i = 0; i < ranges.length; i++) {
71
+ let range = ranges[i];
72
+ lo += range.l;
73
+ if (
74
+ value >= lo &&
75
+ value <= lo + range.h &&
76
+ (value - lo) % (range.d || 1) === 0
77
+ ) {
78
+ if (range.e && range.e.indexOf(value - lo) !== -1) {
79
+ continue;
80
+ }
81
+ return range;
82
+ }
83
+ }
84
+ return null;
85
+ }
86
+
87
+ const Table_A_1_ranges = createRangeTable(
88
+ "221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d",
89
+ );
90
+
91
+ // @TODO: Make this relative...
92
+ const Table_B_1_flags = "ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff"
93
+ .split(",")
94
+ .map((v) => parseInt(v, 16));
95
+
96
+ const Table_B_2_ranges: Array<Ranged> = [
97
+ { h: 25, s: 32, l: 65 },
98
+ { h: 30, s: 32, e: [23], l: 127 },
99
+ { h: 54, s: 1, e: [48], l: 64, d: 2 },
100
+ { h: 14, s: 1, l: 57, d: 2 },
101
+ { h: 44, s: 1, l: 17, d: 2 },
102
+ { h: 10, s: 1, e: [2, 6, 8], l: 61, d: 2 },
103
+ { h: 16, s: 1, l: 68, d: 2 },
104
+ { h: 84, s: 1, e: [18, 24, 66], l: 19, d: 2 },
105
+ { h: 26, s: 32, e: [17], l: 435 },
106
+ { h: 22, s: 1, l: 71, d: 2 },
107
+ { h: 15, s: 80, l: 40 },
108
+ { h: 31, s: 32, l: 16 },
109
+ { h: 32, s: 1, l: 80, d: 2 },
110
+ { h: 52, s: 1, l: 42, d: 2 },
111
+ { h: 12, s: 1, l: 55, d: 2 },
112
+ { h: 40, s: 1, e: [38], l: 15, d: 2 },
113
+ { h: 14, s: 1, l: 48, d: 2 },
114
+ { h: 37, s: 48, l: 49 },
115
+ { h: 148, s: 1, l: 6351, d: 2 },
116
+ { h: 88, s: 1, l: 160, d: 2 },
117
+ { h: 15, s: 16, l: 704 },
118
+ { h: 25, s: 26, l: 854 },
119
+ { h: 25, s: 32, l: 55915 },
120
+ { h: 37, s: 40, l: 1247 },
121
+ { h: 25, s: -119711, l: 53248 },
122
+ { h: 25, s: -119763, l: 52 },
123
+ { h: 25, s: -119815, l: 52 },
124
+ { h: 25, s: -119867, e: [1, 4, 5, 7, 8, 11, 12, 17], l: 52 },
125
+ { h: 25, s: -119919, l: 52 },
126
+ { h: 24, s: -119971, e: [2, 7, 8, 17], l: 52 },
127
+ { h: 24, s: -120023, e: [2, 7, 13, 15, 16, 17], l: 52 },
128
+ { h: 25, s: -120075, l: 52 },
129
+ { h: 25, s: -120127, l: 52 },
130
+ { h: 25, s: -120179, l: 52 },
131
+ { h: 25, s: -120231, l: 52 },
132
+ { h: 25, s: -120283, l: 52 },
133
+ { h: 25, s: -120335, l: 52 },
134
+ { h: 24, s: -119543, e: [17], l: 56 },
135
+ { h: 24, s: -119601, e: [17], l: 58 },
136
+ { h: 24, s: -119659, e: [17], l: 58 },
137
+ { h: 24, s: -119717, e: [17], l: 58 },
138
+ { h: 24, s: -119775, e: [17], l: 58 },
139
+ ];
140
+ const Table_B_2_lut_abs = createTable(
141
+ "b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3",
142
+ );
143
+ const Table_B_2_lut_rel = createTable(
144
+ "179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7",
145
+ );
146
+ const Table_B_2_complex = createTable(
147
+ "df:00730073,51:00690307,19:02BC006E,a7:006A030C,18a:002003B9,16:03B903080301,20:03C503080301,1d7:05650582,190f:00680331,1:00740308,1:0077030A,1:0079030A,1:006102BE,b6:03C50313,2:03C503130300,2:03C503130301,2:03C503130342,2a:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,3:1F7003B9,1:03B103B9,1:03AC03B9,2:03B10342,1:03B1034203B9,5:03B103B9,6:1F7403B9,1:03B703B9,1:03AE03B9,2:03B70342,1:03B7034203B9,5:03B703B9,6:03B903080300,1:03B903080301,3:03B90342,1:03B903080342,b:03C503080300,1:03C503080301,1:03C10313,2:03C50342,1:03C503080342,b:1F7C03B9,1:03C903B9,1:03CE03B9,2:03C90342,1:03C9034203B9,5:03C903B9,ac:00720073,5b:00B00063,6:00B00066,d:006E006F,a:0073006D,1:00740065006C,1:0074006D,124f:006800700061,2:00610075,2:006F0076,b:00700061,1:006E0061,1:03BC0061,1:006D0061,1:006B0061,1:006B0062,1:006D0062,1:00670062,3:00700066,1:006E0066,1:03BC0066,4:0068007A,1:006B0068007A,1:006D0068007A,1:00670068007A,1:00740068007A,15:00700061,1:006B00700061,1:006D00700061,1:006700700061,8:00700076,1:006E0076,1:03BC0076,1:006D0076,1:006B0076,1:006D0076,1:00700077,1:006E0077,1:03BC0077,1:006D0077,1:006B0077,1:006D0077,1:006B03C9,1:006D03C9,2:00620071,3:00632215006B0067,1:0063006F002E,1:00640062,1:00670079,2:00680070,2:006B006B,1:006B006D,9:00700068,2:00700070006D,1:00700072,2:00730076,1:00770062,c723:00660066,1:00660069,1:0066006C,1:006600660069,1:00660066006C,1:00730074,1:00730074,d:05740576,1:05740565,1:0574056B,1:057E0576,1:0574056D",
148
+ bytes2,
149
+ );
150
+
151
+ const Table_C_ranges = createRangeTable(
152
+ "80-20,2a0-,39c,32,f71,18e,7f2-f,19-7,30-4,7-5,f81-b,5,a800-20ff,4d1-1f,110,fa-6,d174-7,2e84-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,2,1f-5f,ff7f-20001",
153
+ );
154
+
155
+ function flatten(values: Array<Array<number>>): Array<number> {
156
+ return values.reduce((accum, value) => {
157
+ value.forEach((value) => {
158
+ accum.push(value);
159
+ });
160
+ return accum;
161
+ }, []);
162
+ }
163
+
164
+ export function _nameprepTableA1(codepoint: number): boolean {
165
+ return !!matchMap(codepoint, Table_A_1_ranges);
166
+ }
167
+
168
+ export function _nameprepTableB2(codepoint: number): Array<number> {
169
+ let range = matchMap(codepoint, Table_B_2_ranges);
170
+ if (range) {
171
+ return [codepoint + range.s];
172
+ }
173
+
174
+ let codes = Table_B_2_lut_abs[codepoint];
175
+ if (codes) {
176
+ return codes;
177
+ }
178
+
179
+ let shift = Table_B_2_lut_rel[codepoint];
180
+ if (shift) {
181
+ return [codepoint + shift[0]];
182
+ }
183
+
184
+ let complex = Table_B_2_complex[codepoint];
185
+ if (complex) {
186
+ return complex;
187
+ }
188
+
189
+ return null;
190
+ }
191
+
192
+ export function _nameprepTableC(codepoint: number): boolean {
193
+ return !!matchMap(codepoint, Table_C_ranges);
194
+ }
195
+
196
+ export function nameprep(value: string): string {
197
+ // This allows platforms with incomplete normalize to bypass
198
+ // it for very basic names which the built-in toLowerCase
199
+ // will certainly handle correctly
200
+ if (value.match(/^[a-z0-9-]*$/i) && value.length <= 59) {
201
+ return value.toLowerCase();
202
+ }
203
+
204
+ // Get the code points (keeping the current normalization)
205
+ let codes = toUtf8CodePoints(value);
206
+
207
+ codes = flatten(
208
+ codes.map((code) => {
209
+ // Substitute Table B.1 (Maps to Nothing)
210
+ if (Table_B_1_flags.indexOf(code) >= 0) {
211
+ return [];
212
+ }
213
+ if (code >= 0xfe00 && code <= 0xfe0f) {
214
+ return [];
215
+ }
216
+
217
+ // Substitute Table B.2 (Case Folding)
218
+ let codesTableB2 = _nameprepTableB2(code);
219
+ if (codesTableB2) {
220
+ return codesTableB2;
221
+ }
222
+
223
+ // No Substitution
224
+ return [code];
225
+ }),
226
+ );
227
+
228
+ // Normalize using form KC
229
+ codes = toUtf8CodePoints(_toUtf8String(codes), UnicodeNormalizationForm.NFKC);
230
+
231
+ // Prohibit Tables C.1.2, C.2.2, C.3, C.4, C.5, C.6, C.7, C.8, C.9
232
+ codes.forEach((code) => {
233
+ if (_nameprepTableC(code)) {
234
+ throw new Error("STRINGPREP_CONTAINS_PROHIBITED");
235
+ }
236
+ });
237
+
238
+ // Prohibit Unassigned Code Points (Table A.1)
239
+ codes.forEach((code) => {
240
+ if (_nameprepTableA1(code)) {
241
+ throw new Error("STRINGPREP_CONTAINS_UNASSIGNED");
242
+ }
243
+ });
244
+
245
+ // IDNA extras
246
+ let name = _toUtf8String(codes);
247
+
248
+ // IDNA: 4.2.3.1
249
+ if (
250
+ name.substring(0, 1) === "-" ||
251
+ name.substring(2, 4) === "--" ||
252
+ name.substring(name.length - 1) === "-"
253
+ ) {
254
+ throw new Error("invalid hyphen");
255
+ }
256
+
257
+ return name;
258
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ import { formatBytes32String, parseBytes32String } from "./bytes32";
4
+ import { nameprep } from "./idna";
5
+ import {
6
+ _toEscapedUtf8String,
7
+ toUtf8Bytes,
8
+ toUtf8CodePoints,
9
+ toUtf8String,
10
+ UnicodeNormalizationForm,
11
+ Utf8ErrorFunc,
12
+ Utf8ErrorFuncs,
13
+ Utf8ErrorReason,
14
+ } from "./utf8";
15
+
16
+ export {
17
+ _toEscapedUtf8String,
18
+ toUtf8Bytes,
19
+ toUtf8CodePoints,
20
+ toUtf8String,
21
+ Utf8ErrorFunc,
22
+ Utf8ErrorFuncs,
23
+ Utf8ErrorReason,
24
+ UnicodeNormalizationForm,
25
+ formatBytes32String,
26
+ parseBytes32String,
27
+ nameprep,
28
+ };