@liveauth-labs/sdk 0.1.2 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pow.worker.ts"],"sourcesContent":["self.onmessage = async e => {\n const { projectPublicKey, challengeHex, targetHex } = e.data;\n\n let nonce = 0;\n\n while (true) {\n const input = `${projectPublicKey}:${challengeHex}:${nonce}`;\n const hash = await sha256Hex(input);\n\n if (hash <= targetHex) {\n postMessage({ nonce, hashHex: hash });\n return;\n }\n\n nonce++;\n }\n};\n\nasync function sha256Hex(input: string): Promise<string> {\n const buf = await crypto.subtle.digest(\n 'SHA-256',\n new TextEncoder().encode(input)\n );\n\n return [...new Uint8Array(buf)]\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"mappings":";;;AAAA,KAAK,YAAY,OAAM,MAAK;AACxB,QAAM,EAAE,kBAAkB,cAAc,UAAU,IAAI,EAAE;AAExD,MAAI,QAAQ;AAEZ,SAAO,MAAM;AACT,UAAM,QAAQ,GAAG,gBAAgB,IAAI,YAAY,IAAI,KAAK;AAC1D,UAAM,OAAO,MAAM,UAAU,KAAK;AAElC,QAAI,QAAQ,WAAW;AACnB,kBAAY,EAAE,OAAO,SAAS,KAAK,CAAC;AACpC;AAAA,IACJ;AAEA;AAAA,EACJ;AACJ;AAEA,eAAe,UAAU,OAAgC;AACrD,QAAM,MAAM,MAAM,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EAClC;AAEA,SAAO,CAAC,GAAG,IAAI,WAAW,GAAG,CAAC,EACzB,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAChB;","names":[]}
1
+ {"version":3,"sources":["../src/pow.worker.ts"],"sourcesContent":["export interface PowWorkerMessage {\n projectPublicKey: string;\n challengeHex: string;\n targetHex: string;\n maxIterations?: number;\n progressInterval?: number;\n}\n\nexport interface PowWorkerResult {\n type: 'solution' | 'progress' | 'timeout';\n nonce?: number;\n hashHex?: string;\n iterations?: number;\n hashesPerSec?: number;\n}\n\nself.onmessage = async (e: MessageEvent<PowWorkerMessage>) => {\n const { \n projectPublicKey, \n challengeHex, \n targetHex, \n maxIterations = 50_000_000,\n progressInterval = 10_000\n } = e.data;\n\n let nonce = 0;\n const startTime = performance.now();\n let lastProgressTime = startTime;\n\n while (nonce < maxIterations) {\n const input = `${projectPublicKey}:${challengeHex}:${nonce}`;\n const hash = await sha256Hex(input);\n\n if (hash <= targetHex) {\n const elapsed = performance.now() - startTime;\n postMessage({ \n type: 'solution', \n nonce, \n hashHex: hash,\n iterations: nonce + 1,\n hashesPerSec: Math.round((nonce + 1) / (elapsed / 1000))\n } satisfies PowWorkerResult);\n return;\n }\n\n nonce++;\n\n // Send progress updates periodically\n if (nonce % progressInterval === 0) {\n const now = performance.now();\n const elapsed = now - startTime;\n const recentElapsed = now - lastProgressTime;\n \n postMessage({ \n type: 'progress', \n iterations: nonce,\n hashesPerSec: Math.round(progressInterval / (recentElapsed / 1000))\n } satisfies PowWorkerResult);\n \n lastProgressTime = now;\n }\n }\n\n // Hit max iterations without solution\n postMessage({ \n type: 'timeout', \n iterations: nonce \n } satisfies PowWorkerResult);\n};\n\nasync function sha256Hex(input: string): Promise<string> {\n const buf = await crypto.subtle.digest(\n 'SHA-256',\n new TextEncoder().encode(input)\n );\n\n return [...new Uint8Array(buf)]\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;AAgBA,KAAK,YAAY,OAAO,MAAsC;AAC1D,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,EACvB,IAAI,EAAE;AAEN,MAAI,QAAQ;AACZ,QAAM,YAAY,YAAY,IAAI;AAClC,MAAI,mBAAmB;AAEvB,SAAO,QAAQ,eAAe;AAC1B,UAAM,QAAQ,GAAG,gBAAgB,IAAI,YAAY,IAAI,KAAK;AAC1D,UAAM,OAAO,MAAM,UAAU,KAAK;AAElC,QAAI,QAAQ,WAAW;AACnB,YAAM,UAAU,YAAY,IAAI,IAAI;AACpC,kBAAY;AAAA,QACR,MAAM;AAAA,QACN;AAAA,QACA,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,QACpB,cAAc,KAAK,OAAO,QAAQ,MAAM,UAAU,IAAK;AAAA,MAC3D,CAA2B;AAC3B;AAAA,IACJ;AAEA;AAGA,QAAI,QAAQ,qBAAqB,GAAG;AAChC,YAAM,MAAM,YAAY,IAAI;AAC5B,YAAM,UAAU,MAAM;AACtB,YAAM,gBAAgB,MAAM;AAE5B,kBAAY;AAAA,QACR,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,cAAc,KAAK,MAAM,oBAAoB,gBAAgB,IAAK;AAAA,MACtE,CAA2B;AAE3B,yBAAmB;AAAA,IACvB;AAAA,EACJ;AAGA,cAAY;AAAA,IACR,MAAM;AAAA,IACN,YAAY;AAAA,EAChB,CAA2B;AAC/B;AAEA,eAAe,UAAU,OAAgC;AACrD,QAAM,MAAM,MAAM,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EAClC;AAEA,SAAO,CAAC,GAAG,IAAI,WAAW,GAAG,CAAC,EACzB,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAChB;","names":[]}
@@ -1,2 +1,16 @@
1
+ interface PowWorkerMessage {
2
+ projectPublicKey: string;
3
+ challengeHex: string;
4
+ targetHex: string;
5
+ maxIterations?: number;
6
+ progressInterval?: number;
7
+ }
8
+ interface PowWorkerResult {
9
+ type: 'solution' | 'progress' | 'timeout';
10
+ nonce?: number;
11
+ hashHex?: string;
12
+ iterations?: number;
13
+ hashesPerSec?: number;
14
+ }
1
15
 
2
- export { }
16
+ export type { PowWorkerMessage, PowWorkerResult };
@@ -1,2 +1,16 @@
1
+ interface PowWorkerMessage {
2
+ projectPublicKey: string;
3
+ challengeHex: string;
4
+ targetHex: string;
5
+ maxIterations?: number;
6
+ progressInterval?: number;
7
+ }
8
+ interface PowWorkerResult {
9
+ type: 'solution' | 'progress' | 'timeout';
10
+ nonce?: number;
11
+ hashHex?: string;
12
+ iterations?: number;
13
+ hashesPerSec?: number;
14
+ }
1
15
 
2
- export { }
16
+ export type { PowWorkerMessage, PowWorkerResult };
@@ -1,16 +1,46 @@
1
1
  // src/pow.worker.ts
2
2
  self.onmessage = async (e) => {
3
- const { projectPublicKey, challengeHex, targetHex } = e.data;
3
+ const {
4
+ projectPublicKey,
5
+ challengeHex,
6
+ targetHex,
7
+ maxIterations = 5e7,
8
+ progressInterval = 1e4
9
+ } = e.data;
4
10
  let nonce = 0;
5
- while (true) {
11
+ const startTime = performance.now();
12
+ let lastProgressTime = startTime;
13
+ while (nonce < maxIterations) {
6
14
  const input = `${projectPublicKey}:${challengeHex}:${nonce}`;
7
15
  const hash = await sha256Hex(input);
8
16
  if (hash <= targetHex) {
9
- postMessage({ nonce, hashHex: hash });
17
+ const elapsed = performance.now() - startTime;
18
+ postMessage({
19
+ type: "solution",
20
+ nonce,
21
+ hashHex: hash,
22
+ iterations: nonce + 1,
23
+ hashesPerSec: Math.round((nonce + 1) / (elapsed / 1e3))
24
+ });
10
25
  return;
11
26
  }
12
27
  nonce++;
28
+ if (nonce % progressInterval === 0) {
29
+ const now = performance.now();
30
+ const elapsed = now - startTime;
31
+ const recentElapsed = now - lastProgressTime;
32
+ postMessage({
33
+ type: "progress",
34
+ iterations: nonce,
35
+ hashesPerSec: Math.round(progressInterval / (recentElapsed / 1e3))
36
+ });
37
+ lastProgressTime = now;
38
+ }
13
39
  }
40
+ postMessage({
41
+ type: "timeout",
42
+ iterations: nonce
43
+ });
14
44
  };
15
45
  async function sha256Hex(input) {
16
46
  const buf = await crypto.subtle.digest(
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pow.worker.ts"],"sourcesContent":["self.onmessage = async e => {\n const { projectPublicKey, challengeHex, targetHex } = e.data;\n\n let nonce = 0;\n\n while (true) {\n const input = `${projectPublicKey}:${challengeHex}:${nonce}`;\n const hash = await sha256Hex(input);\n\n if (hash <= targetHex) {\n postMessage({ nonce, hashHex: hash });\n return;\n }\n\n nonce++;\n }\n};\n\nasync function sha256Hex(input: string): Promise<string> {\n const buf = await crypto.subtle.digest(\n 'SHA-256',\n new TextEncoder().encode(input)\n );\n\n return [...new Uint8Array(buf)]\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"mappings":";AAAA,KAAK,YAAY,OAAM,MAAK;AACxB,QAAM,EAAE,kBAAkB,cAAc,UAAU,IAAI,EAAE;AAExD,MAAI,QAAQ;AAEZ,SAAO,MAAM;AACT,UAAM,QAAQ,GAAG,gBAAgB,IAAI,YAAY,IAAI,KAAK;AAC1D,UAAM,OAAO,MAAM,UAAU,KAAK;AAElC,QAAI,QAAQ,WAAW;AACnB,kBAAY,EAAE,OAAO,SAAS,KAAK,CAAC;AACpC;AAAA,IACJ;AAEA;AAAA,EACJ;AACJ;AAEA,eAAe,UAAU,OAAgC;AACrD,QAAM,MAAM,MAAM,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EAClC;AAEA,SAAO,CAAC,GAAG,IAAI,WAAW,GAAG,CAAC,EACzB,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAChB;","names":[]}
1
+ {"version":3,"sources":["../src/pow.worker.ts"],"sourcesContent":["export interface PowWorkerMessage {\n projectPublicKey: string;\n challengeHex: string;\n targetHex: string;\n maxIterations?: number;\n progressInterval?: number;\n}\n\nexport interface PowWorkerResult {\n type: 'solution' | 'progress' | 'timeout';\n nonce?: number;\n hashHex?: string;\n iterations?: number;\n hashesPerSec?: number;\n}\n\nself.onmessage = async (e: MessageEvent<PowWorkerMessage>) => {\n const { \n projectPublicKey, \n challengeHex, \n targetHex, \n maxIterations = 50_000_000,\n progressInterval = 10_000\n } = e.data;\n\n let nonce = 0;\n const startTime = performance.now();\n let lastProgressTime = startTime;\n\n while (nonce < maxIterations) {\n const input = `${projectPublicKey}:${challengeHex}:${nonce}`;\n const hash = await sha256Hex(input);\n\n if (hash <= targetHex) {\n const elapsed = performance.now() - startTime;\n postMessage({ \n type: 'solution', \n nonce, \n hashHex: hash,\n iterations: nonce + 1,\n hashesPerSec: Math.round((nonce + 1) / (elapsed / 1000))\n } satisfies PowWorkerResult);\n return;\n }\n\n nonce++;\n\n // Send progress updates periodically\n if (nonce % progressInterval === 0) {\n const now = performance.now();\n const elapsed = now - startTime;\n const recentElapsed = now - lastProgressTime;\n \n postMessage({ \n type: 'progress', \n iterations: nonce,\n hashesPerSec: Math.round(progressInterval / (recentElapsed / 1000))\n } satisfies PowWorkerResult);\n \n lastProgressTime = now;\n }\n }\n\n // Hit max iterations without solution\n postMessage({ \n type: 'timeout', \n iterations: nonce \n } satisfies PowWorkerResult);\n};\n\nasync function sha256Hex(input: string): Promise<string> {\n const buf = await crypto.subtle.digest(\n 'SHA-256',\n new TextEncoder().encode(input)\n );\n\n return [...new Uint8Array(buf)]\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"mappings":";AAgBA,KAAK,YAAY,OAAO,MAAsC;AAC1D,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,EACvB,IAAI,EAAE;AAEN,MAAI,QAAQ;AACZ,QAAM,YAAY,YAAY,IAAI;AAClC,MAAI,mBAAmB;AAEvB,SAAO,QAAQ,eAAe;AAC1B,UAAM,QAAQ,GAAG,gBAAgB,IAAI,YAAY,IAAI,KAAK;AAC1D,UAAM,OAAO,MAAM,UAAU,KAAK;AAElC,QAAI,QAAQ,WAAW;AACnB,YAAM,UAAU,YAAY,IAAI,IAAI;AACpC,kBAAY;AAAA,QACR,MAAM;AAAA,QACN;AAAA,QACA,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,QACpB,cAAc,KAAK,OAAO,QAAQ,MAAM,UAAU,IAAK;AAAA,MAC3D,CAA2B;AAC3B;AAAA,IACJ;AAEA;AAGA,QAAI,QAAQ,qBAAqB,GAAG;AAChC,YAAM,MAAM,YAAY,IAAI;AAC5B,YAAM,UAAU,MAAM;AACtB,YAAM,gBAAgB,MAAM;AAE5B,kBAAY;AAAA,QACR,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,cAAc,KAAK,MAAM,oBAAoB,gBAAgB,IAAK;AAAA,MACtE,CAA2B;AAE3B,yBAAmB;AAAA,IACvB;AAAA,EACJ;AAGA,cAAY;AAAA,IACR,MAAM;AAAA,IACN,YAAY;AAAA,EAChB,CAA2B;AAC/B;AAEA,eAAe,UAAU,OAAgC;AACrD,QAAM,MAAM,MAAM,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EAClC;AAEA,SAAO,CAAC,GAAG,IAAI,WAAW,GAAG,CAAC,EACzB,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAChB;","names":[]}
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@liveauth-labs/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "LiveAuth browser SDK (PoW + Lightning human verification)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
+ "sideEffects": false,
9
10
  "exports": {
10
11
  ".": {
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
13
15
  }
14
16
  },
15
17
  "files": [
@@ -25,6 +27,16 @@
25
27
  "lightning",
26
28
  "bitcoin",
27
29
  "bot-protection",
28
- "auth"
29
- ]
30
+ "auth",
31
+ "verification"
32
+ ],
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/dulzuradev/liveauth-js"
36
+ },
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "tsup": "^8.0.0",
40
+ "typescript": "^5.3.0"
41
+ }
30
42
  }