@leofcoin/chain 1.7.65 → 1.7.67

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.
@@ -0,0 +1,188 @@
1
+ import { g as getDefaultExportFromCjs } from './node-browser-DewO13hB.js';
2
+ import './index-CM4QYC3g.js';
3
+
4
+ var global;
5
+ var hasRequiredGlobal;
6
+
7
+ function requireGlobal () {
8
+ if (hasRequiredGlobal) return global;
9
+ hasRequiredGlobal = 1;
10
+ var naiveFallback = function () {
11
+ if (typeof self === "object" && self) return self;
12
+ if (typeof window === "object" && window) return window;
13
+ throw new Error("Unable to resolve global `this`");
14
+ };
15
+
16
+ global = (function () {
17
+ if (this) return this;
18
+
19
+ // Unexpected strict mode (may happen if e.g. bundled into ESM module)
20
+
21
+ // Fallback to standard globalThis if available
22
+ if (typeof globalThis === "object" && globalThis) return globalThis;
23
+
24
+ // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
25
+ // In all ES5+ engines global object inherits from Object.prototype
26
+ // (if you approached one that doesn't please report)
27
+ try {
28
+ Object.defineProperty(Object.prototype, "__global__", {
29
+ get: function () { return this; },
30
+ configurable: true
31
+ });
32
+ } catch (error) {
33
+ // Unfortunate case of updates to Object.prototype being restricted
34
+ // via preventExtensions, seal or freeze
35
+ return naiveFallback();
36
+ }
37
+ try {
38
+ // Safari case (window.__global__ works, but __global__ does not)
39
+ if (!__global__) return naiveFallback();
40
+ return __global__;
41
+ } finally {
42
+ delete Object.prototype.__global__;
43
+ }
44
+ })();
45
+ return global;
46
+ }
47
+
48
+ var name = "websocket";
49
+ var description = "Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.";
50
+ var keywords = [
51
+ "websocket",
52
+ "websockets",
53
+ "socket",
54
+ "networking",
55
+ "comet",
56
+ "push",
57
+ "RFC-6455",
58
+ "realtime",
59
+ "server",
60
+ "client"
61
+ ];
62
+ var author = "Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturtle32)";
63
+ var contributors = [
64
+ "Iñaki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"
65
+ ];
66
+ var version$1 = "1.0.35";
67
+ var repository = {
68
+ type: "git",
69
+ url: "https://github.com/theturtle32/WebSocket-Node.git"
70
+ };
71
+ var homepage = "https://github.com/theturtle32/WebSocket-Node";
72
+ var engines = {
73
+ node: ">=4.0.0"
74
+ };
75
+ var dependencies = {
76
+ bufferutil: "^4.0.1",
77
+ debug: "^2.2.0",
78
+ "es5-ext": "^0.10.63",
79
+ "typedarray-to-buffer": "^3.1.5",
80
+ "utf-8-validate": "^5.0.2",
81
+ yaeti: "^0.0.6"
82
+ };
83
+ var devDependencies = {
84
+ "buffer-equal": "^1.0.0",
85
+ gulp: "^4.0.2",
86
+ "gulp-jshint": "^2.0.4",
87
+ "jshint-stylish": "^2.2.1",
88
+ jshint: "^2.0.0",
89
+ tape: "^4.9.1"
90
+ };
91
+ var config = {
92
+ verbose: false
93
+ };
94
+ var scripts = {
95
+ test: "tape test/unit/*.js",
96
+ gulp: "gulp"
97
+ };
98
+ var main = "index";
99
+ var directories = {
100
+ lib: "./lib"
101
+ };
102
+ var browser$3 = "lib/browser.js";
103
+ var license = "Apache-2.0";
104
+ var require$$0 = {
105
+ name: name,
106
+ description: description,
107
+ keywords: keywords,
108
+ author: author,
109
+ contributors: contributors,
110
+ version: version$1,
111
+ repository: repository,
112
+ homepage: homepage,
113
+ engines: engines,
114
+ dependencies: dependencies,
115
+ devDependencies: devDependencies,
116
+ config: config,
117
+ scripts: scripts,
118
+ main: main,
119
+ directories: directories,
120
+ browser: browser$3,
121
+ license: license
122
+ };
123
+
124
+ var version = require$$0.version;
125
+
126
+ var _globalThis;
127
+ if (typeof globalThis === 'object') {
128
+ _globalThis = globalThis;
129
+ } else {
130
+ try {
131
+ _globalThis = requireGlobal();
132
+ } catch (error) {
133
+ } finally {
134
+ if (!_globalThis && typeof window !== 'undefined') { _globalThis = window; }
135
+ if (!_globalThis) { throw new Error('Could not determine global this'); }
136
+ }
137
+ }
138
+
139
+ var NativeWebSocket = _globalThis.WebSocket || _globalThis.MozWebSocket;
140
+ var websocket_version = version;
141
+
142
+
143
+ /**
144
+ * Expose a W3C WebSocket class with just one or two arguments.
145
+ */
146
+ function W3CWebSocket(uri, protocols) {
147
+ var native_instance;
148
+
149
+ if (protocols) {
150
+ native_instance = new NativeWebSocket(uri, protocols);
151
+ }
152
+ else {
153
+ native_instance = new NativeWebSocket(uri);
154
+ }
155
+
156
+ /**
157
+ * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
158
+ * class). Since it is an Object it will be returned as it is when creating an
159
+ * instance of W3CWebSocket via 'new W3CWebSocket()'.
160
+ *
161
+ * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
162
+ */
163
+ return native_instance;
164
+ }
165
+ if (NativeWebSocket) {
166
+ ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function(prop) {
167
+ Object.defineProperty(W3CWebSocket, prop, {
168
+ get: function() { return NativeWebSocket[prop]; }
169
+ });
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Module exports.
175
+ */
176
+ var browser = {
177
+ 'w3cwebsocket' : NativeWebSocket ? W3CWebSocket : null,
178
+ 'version' : websocket_version
179
+ };
180
+
181
+ var browser$1 = /*@__PURE__*/getDefaultExportFromCjs(browser);
182
+
183
+ var browser$2 = /*#__PURE__*/Object.freeze({
184
+ __proto__: null,
185
+ default: browser$1
186
+ });
187
+
188
+ export { browser$2 as b };
@@ -0,0 +1,25 @@
1
+ var browser$1 = {};
2
+
3
+ browser$1.MediaStream = window.MediaStream;
4
+ browser$1.MediaStreamTrack = window.MediaStreamTrack;
5
+ browser$1.RTCDataChannel = window.RTCDataChannel;
6
+ browser$1.RTCDataChannelEvent = window.RTCDataChannelEvent;
7
+ browser$1.RTCDtlsTransport = window.RTCDtlsTransport;
8
+ browser$1.RTCIceCandidate = window.RTCIceCandidate;
9
+ browser$1.RTCIceTransport = window.RTCIceTransport;
10
+ browser$1.RTCPeerConnection = window.RTCPeerConnection;
11
+ browser$1.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
12
+ browser$1.RTCRtpReceiver = window.RTCRtpReceiver;
13
+ browser$1.RTCRtpSender = window.RTCRtpSender;
14
+ browser$1.RTCRtpTransceiver = window.RTCRtpTransceiver;
15
+ browser$1.RTCSctpTransport = window.RTCSctpTransport;
16
+ browser$1.RTCSessionDescription = window.RTCSessionDescription;
17
+ browser$1.getUserMedia = window.getUserMedia;
18
+ browser$1.mediaDevices = navigator.mediaDevices;
19
+
20
+ var browser = /*#__PURE__*/Object.freeze({
21
+ __proto__: null,
22
+ default: browser$1
23
+ });
24
+
25
+ export { browser as b };
@@ -0,0 +1,306 @@
1
+ const encode = (string) => {
2
+ if (typeof string === 'string')
3
+ return new TextEncoder().encode(string);
4
+ throw Error(`expected typeof String instead got ${string}`);
5
+ };
6
+ const decode = (uint8Array) => {
7
+ if (uint8Array instanceof Uint8Array)
8
+ return new TextDecoder().decode(uint8Array);
9
+ throw Error(`expected typeof uint8Array instead got ${uint8Array}`);
10
+ };
11
+
12
+ const pathSepS = '/';
13
+ class KeyPath {
14
+ uint8Array;
15
+ constructor(input) {
16
+ if (typeof input === 'string') {
17
+ this.uint8Array = encode(input);
18
+ }
19
+ else if (input instanceof Uint8Array) {
20
+ this.uint8Array = input;
21
+ }
22
+ else if (input instanceof KeyPath) {
23
+ this.uint8Array = input.uint8Array;
24
+ }
25
+ else {
26
+ throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath');
27
+ }
28
+ }
29
+ isKeyPath() {
30
+ return true;
31
+ }
32
+ toString() {
33
+ return decode(this.uint8Array);
34
+ }
35
+ /**
36
+ * Returns the `list` representation of this path.
37
+ *
38
+ * @example
39
+ * ```js
40
+ * new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
41
+ * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
42
+ * ```
43
+ */
44
+ list() {
45
+ return this.toString().split(pathSepS).slice(1);
46
+ }
47
+ }
48
+
49
+ class KeyValue {
50
+ uint8Array;
51
+ constructor(input) {
52
+ if (typeof input === 'string') {
53
+ this.uint8Array = encode(input);
54
+ }
55
+ else if (input instanceof Uint8Array) {
56
+ this.uint8Array = input;
57
+ }
58
+ else if (input instanceof KeyValue) {
59
+ this.uint8Array = input.uint8Array;
60
+ }
61
+ else {
62
+ throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue');
63
+ }
64
+ }
65
+ isKeyValue() {
66
+ return true;
67
+ }
68
+ toString() {
69
+ return decode(this.uint8Array);
70
+ }
71
+ }
72
+
73
+ if (!globalThis.DEBUG) {
74
+ let DEBUG = [];
75
+ if (globalThis.localStorage) {
76
+ DEBUG = globalThis.localStorage.getItem('DEBUG');
77
+ globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
78
+ }
79
+ }
80
+
81
+ const debug$1 = (target, text) => {
82
+ if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
83
+ if (
84
+ globalThis.DEBUG === 'true' ||
85
+ globalThis.DEBUG === true ||
86
+ globalThis.DEBUG?.indexOf(target) !== -1 ||
87
+ globalThis.DEBUG?.indexOf('*') !== -1 ||
88
+ globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
89
+ )
90
+ if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
91
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
92
+ };
93
+
94
+ if (!globalThis.debug) {
95
+ globalThis.debug = debug$1;
96
+
97
+ globalThis.createDebugger = (target) => (text) => debug$1(target, text);
98
+ }
99
+
100
+ const debug = globalThis.createDebugger('leofcoin/storage');
101
+ const opfsRoot = await navigator.storage.getDirectory();
102
+ class BrowerStore {
103
+ db;
104
+ name;
105
+ root;
106
+ inWorker;
107
+ version;
108
+ busy;
109
+ queue = [];
110
+ async init(name = 'storage', root = '.leofcoin', version = '1', inWorker = false) {
111
+ this.version = version;
112
+ this.name = name;
113
+ this.root = opfsRoot;
114
+ this.inWorker = inWorker;
115
+ let directoryHandle;
116
+ try {
117
+ directoryHandle = await opfsRoot.getDirectoryHandle(this.name, {
118
+ create: true
119
+ });
120
+ if (inWorker) {
121
+ // it's in a worker so that's why typings invalid?
122
+ // @ts-ignore
123
+ directoryHandle = await directoryHandle.createSyncAccessHandle();
124
+ }
125
+ }
126
+ catch (error) {
127
+ console.error(error);
128
+ }
129
+ this.db = directoryHandle;
130
+ }
131
+ toKeyPath(key) {
132
+ if (key instanceof KeyPath)
133
+ key = new KeyPath(key);
134
+ return key.toString();
135
+ }
136
+ toKeyValue(value) {
137
+ if (value instanceof KeyValue)
138
+ value = new KeyValue(value);
139
+ // @ts-ignore
140
+ return value.uint8Array;
141
+ }
142
+ async has(key) {
143
+ debug(`has ${this.toKeyPath(key)}`);
144
+ try {
145
+ await this.db.getFileHandle(this.toKeyPath(key));
146
+ return true;
147
+ }
148
+ catch (error) {
149
+ return false;
150
+ }
151
+ }
152
+ async get(key) {
153
+ let promiseResolve;
154
+ let promiseReject;
155
+ let result = new Promise((resolve, reject) => {
156
+ promiseResolve = resolve;
157
+ promiseReject = reject;
158
+ });
159
+ const promise = () => new Promise(async (resolve, reject) => {
160
+ debug(`get ${this.toKeyPath(key)}`);
161
+ setTimeout(async () => {
162
+ try {
163
+ let handle = await this.db.getFileHandle(this.toKeyPath(key));
164
+ let readBuffer;
165
+ if (this.inWorker) {
166
+ // it's in a worker so that's why typings invalid?
167
+ // @ts-ignore
168
+ handle = await handle.createSyncAccessHandle();
169
+ // @ts-ignore
170
+ const fileSize = handle.getSize();
171
+ // Read file content to a buffer.
172
+ const buffer = new DataView(new ArrayBuffer(fileSize));
173
+ // @ts-ignore
174
+ readBuffer = handle.read(buffer, { at: 0 });
175
+ // @ts-ignore
176
+ handle.close();
177
+ }
178
+ else {
179
+ const file = await handle.getFile();
180
+ readBuffer = await file.arrayBuffer();
181
+ }
182
+ this.runQueue();
183
+ promiseResolve(new Uint8Array(readBuffer));
184
+ resolve(new Uint8Array(readBuffer));
185
+ }
186
+ catch (error) {
187
+ promiseReject(error);
188
+ resolve(false);
189
+ }
190
+ }, 1);
191
+ });
192
+ this.queue.push(promise);
193
+ this.runQueue();
194
+ return result;
195
+ }
196
+ async put(key, value) {
197
+ let promiseResolve;
198
+ let promiseReject;
199
+ let result = new Promise((resolve, reject) => {
200
+ promiseResolve = resolve;
201
+ promiseReject = reject;
202
+ });
203
+ const promise = () => new Promise(async (resolve, reject) => {
204
+ debug(`put ${this.toKeyPath(key)}`);
205
+ setTimeout(async () => {
206
+ try {
207
+ let handle = await this.db.getFileHandle(this.toKeyPath(key), { create: true });
208
+ let writeable;
209
+ if (this.inWorker) {
210
+ // it's in a worker so that's why typings invalid?
211
+ // @ts-ignore
212
+ writeable = await handle.createSyncAccessHandle();
213
+ }
214
+ else {
215
+ writeable = await handle.createWritable();
216
+ }
217
+ ;
218
+ (await writeable).write(this.toKeyValue(value));
219
+ (await writeable).close();
220
+ this.runQueue();
221
+ resolve(true);
222
+ promiseResolve(true);
223
+ }
224
+ catch (error) {
225
+ promiseReject(error);
226
+ resolve(false);
227
+ }
228
+ }, 5);
229
+ });
230
+ this.queue.push(promise);
231
+ this.runQueue();
232
+ return result;
233
+ }
234
+ async runQueue() {
235
+ if (this.queue.length > 0 && !this.busy) {
236
+ this.busy = true;
237
+ const next = this.queue.shift();
238
+ await next();
239
+ this.busy = false;
240
+ return this.runQueue();
241
+ }
242
+ else if (this.queue.length === 0 && this.busy) {
243
+ this.busy = false;
244
+ }
245
+ }
246
+ async delete(key) {
247
+ debug(`delete ${this.toKeyPath(key)}`);
248
+ return new Promise(async (resolve, reject) => {
249
+ try {
250
+ await this.db.getFileHandle(`${this.toKeyPath(key)}.crswap`);
251
+ setTimeout(() => resolve(this.delete(key)), 5);
252
+ }
253
+ catch (error) {
254
+ try {
255
+ await this.db.removeEntry(this.toKeyPath(key));
256
+ resolve(true);
257
+ }
258
+ catch (error) {
259
+ if (error.name === 'NoModificationAllowedError')
260
+ setTimeout(() => resolve(this.delete(key)), 5);
261
+ else
262
+ reject(error);
263
+ }
264
+ }
265
+ });
266
+ }
267
+ async clear() {
268
+ for await (const key of this.db.keys()) {
269
+ debug(`clear ${this.toKeyPath(key)}`);
270
+ await this.delete(key);
271
+ }
272
+ }
273
+ async values() {
274
+ let values = [];
275
+ for await (const cursor of this.db.values()) {
276
+ // huh? Outdated typings?
277
+ // @ts-ignore
278
+ values.push(cursor.getFile());
279
+ }
280
+ values = await Promise.all(values);
281
+ return Promise.all(values.map(async (file) => new Uint8Array(await file.arrayBuffer())));
282
+ }
283
+ async size() {
284
+ let size = 0;
285
+ for await (const cursor of this.db.values()) {
286
+ // huh? Outdated typings?
287
+ // @ts-ignore
288
+ console.log((await cursor.getFile()).size);
289
+
290
+ size += (await cursor.getFile()).size;
291
+ }
292
+ return size;
293
+ }
294
+ async keys() {
295
+ const keys = [];
296
+ for await (const cursor of this.db.keys()) {
297
+ keys.push(cursor);
298
+ }
299
+ return keys;
300
+ }
301
+ async iterate() {
302
+ return this.db.entries();
303
+ }
304
+ }
305
+
306
+ export { BrowerStore as default };