bitcoincash-oauth-client 0.2.0 → 0.2.2
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/dist/index.browser.min.js +1 -1
- package/dist/index.cjs +28 -13
- package/dist/index.mjs +28 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -258,7 +258,7 @@ function getFetch(userProvidedFetch = null) {
|
|
|
258
258
|
* @typedef {Object} Keypair
|
|
259
259
|
* @property {string} privateKey - Hex-encoded private key
|
|
260
260
|
* @property {string} publicKey - Hex-encoded compressed public key
|
|
261
|
-
* @property {string}
|
|
261
|
+
* @property {string} bitcoincash_address - Bitcoin Cash address
|
|
262
262
|
*/
|
|
263
263
|
|
|
264
264
|
/**
|
|
@@ -372,14 +372,14 @@ class BitcoinCashOAuthClient {
|
|
|
372
372
|
const publicKeyBytes = this.secp256k1.derivePublicKeyCompressed(privateKeyBytes);
|
|
373
373
|
|
|
374
374
|
// Convert to address
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
this._log('Generated new keypair', {
|
|
375
|
+
const bitcoincash_address = await this.publicKeyToCashAddress(publicKeyBytes);
|
|
376
|
+
|
|
377
|
+
this._log('Generated new keypair', { bitcoincash_address });
|
|
378
378
|
|
|
379
379
|
return {
|
|
380
380
|
privateKey: this.bytesToHex(privateKeyBytes),
|
|
381
381
|
publicKey: this.bytesToHex(publicKeyBytes),
|
|
382
|
-
|
|
382
|
+
bitcoincash_address,
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -433,40 +433,55 @@ class BitcoinCashOAuthClient {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
/**
|
|
436
|
-
* Register a new user with the server
|
|
437
|
-
* @param {string}
|
|
438
|
-
* @param {string}
|
|
436
|
+
* Register a new user with the server (signature required)
|
|
437
|
+
* @param {string} bitcoincash_address - Bitcoin Cash address
|
|
438
|
+
* @param {string} privateKeyHex - Private key for signing (hex-encoded)
|
|
439
|
+
* @param {string} publicKeyHex - Public key for signature verification (hex-encoded)
|
|
440
|
+
* @param {string} userId - User-provided ID (required)
|
|
441
|
+
* @param {number} [timestamp] - Optional Unix timestamp (defaults to now)
|
|
442
|
+
* @param {string} [domain] - Optional domain for message binding
|
|
439
443
|
* @returns {Promise<Object>} Registration result with assigned userId
|
|
440
444
|
* @throws {NetworkError} If network request fails
|
|
441
445
|
* @throws {AuthenticationError} If registration fails
|
|
442
446
|
*/
|
|
443
|
-
async register(
|
|
447
|
+
async register(bitcoincash_address, privateKeyHex, publicKeyHex, userId, timestamp = null, domain = null) {
|
|
444
448
|
try {
|
|
449
|
+
const ts = timestamp || Math.floor(Date.now() / 1000);
|
|
450
|
+
const host = domain || this._getDefaultDomain();
|
|
451
|
+
const message = this.createAuthMessage(userId, ts, host);
|
|
452
|
+
const signature = await this.signAuthMessage(message, privateKeyHex);
|
|
453
|
+
|
|
454
|
+
this._log('Registering user', { bitcoincash_address, userId, domain: host });
|
|
455
|
+
|
|
445
456
|
const response = await this.fetchImpl(`${this.serverUrl}/auth/register`, {
|
|
446
457
|
method: "POST",
|
|
447
458
|
headers: {
|
|
448
459
|
"Content-Type": "application/json",
|
|
449
460
|
},
|
|
450
461
|
body: JSON.stringify({
|
|
451
|
-
|
|
462
|
+
bitcoincash_address,
|
|
452
463
|
user_id: userId,
|
|
464
|
+
timestamp: ts,
|
|
465
|
+
domain: host,
|
|
466
|
+
public_key: publicKeyHex,
|
|
467
|
+
signature: signature,
|
|
453
468
|
}),
|
|
454
469
|
});
|
|
455
470
|
|
|
456
471
|
if (!response.ok) {
|
|
457
472
|
const errorData = await response.json().catch(() => ({}));
|
|
458
|
-
|
|
473
|
+
|
|
459
474
|
if (response.status === 404) {
|
|
460
475
|
throw new UserNotFoundError(errorData.detail || 'User not found');
|
|
461
476
|
}
|
|
462
|
-
|
|
477
|
+
|
|
463
478
|
throw new AuthenticationError(
|
|
464
479
|
errorData.detail || `Registration failed: ${response.statusText}`,
|
|
465
480
|
response.status
|
|
466
481
|
);
|
|
467
482
|
}
|
|
468
483
|
|
|
469
|
-
this._log('User registered successfully', {
|
|
484
|
+
this._log('User registered successfully', { bitcoincash_address, userId });
|
|
470
485
|
return await response.json();
|
|
471
486
|
} catch (error) {
|
|
472
487
|
if (error instanceof OAuthError) {
|
package/dist/index.mjs
CHANGED
|
@@ -254,7 +254,7 @@ function getFetch(userProvidedFetch = null) {
|
|
|
254
254
|
* @typedef {Object} Keypair
|
|
255
255
|
* @property {string} privateKey - Hex-encoded private key
|
|
256
256
|
* @property {string} publicKey - Hex-encoded compressed public key
|
|
257
|
-
* @property {string}
|
|
257
|
+
* @property {string} bitcoincash_address - Bitcoin Cash address
|
|
258
258
|
*/
|
|
259
259
|
|
|
260
260
|
/**
|
|
@@ -368,14 +368,14 @@ class BitcoinCashOAuthClient {
|
|
|
368
368
|
const publicKeyBytes = this.secp256k1.derivePublicKeyCompressed(privateKeyBytes);
|
|
369
369
|
|
|
370
370
|
// Convert to address
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
this._log('Generated new keypair', {
|
|
371
|
+
const bitcoincash_address = await this.publicKeyToCashAddress(publicKeyBytes);
|
|
372
|
+
|
|
373
|
+
this._log('Generated new keypair', { bitcoincash_address });
|
|
374
374
|
|
|
375
375
|
return {
|
|
376
376
|
privateKey: this.bytesToHex(privateKeyBytes),
|
|
377
377
|
publicKey: this.bytesToHex(publicKeyBytes),
|
|
378
|
-
|
|
378
|
+
bitcoincash_address,
|
|
379
379
|
};
|
|
380
380
|
}
|
|
381
381
|
|
|
@@ -429,40 +429,55 @@ class BitcoinCashOAuthClient {
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
/**
|
|
432
|
-
* Register a new user with the server
|
|
433
|
-
* @param {string}
|
|
434
|
-
* @param {string}
|
|
432
|
+
* Register a new user with the server (signature required)
|
|
433
|
+
* @param {string} bitcoincash_address - Bitcoin Cash address
|
|
434
|
+
* @param {string} privateKeyHex - Private key for signing (hex-encoded)
|
|
435
|
+
* @param {string} publicKeyHex - Public key for signature verification (hex-encoded)
|
|
436
|
+
* @param {string} userId - User-provided ID (required)
|
|
437
|
+
* @param {number} [timestamp] - Optional Unix timestamp (defaults to now)
|
|
438
|
+
* @param {string} [domain] - Optional domain for message binding
|
|
435
439
|
* @returns {Promise<Object>} Registration result with assigned userId
|
|
436
440
|
* @throws {NetworkError} If network request fails
|
|
437
441
|
* @throws {AuthenticationError} If registration fails
|
|
438
442
|
*/
|
|
439
|
-
async register(
|
|
443
|
+
async register(bitcoincash_address, privateKeyHex, publicKeyHex, userId, timestamp = null, domain = null) {
|
|
440
444
|
try {
|
|
445
|
+
const ts = timestamp || Math.floor(Date.now() / 1000);
|
|
446
|
+
const host = domain || this._getDefaultDomain();
|
|
447
|
+
const message = this.createAuthMessage(userId, ts, host);
|
|
448
|
+
const signature = await this.signAuthMessage(message, privateKeyHex);
|
|
449
|
+
|
|
450
|
+
this._log('Registering user', { bitcoincash_address, userId, domain: host });
|
|
451
|
+
|
|
441
452
|
const response = await this.fetchImpl(`${this.serverUrl}/auth/register`, {
|
|
442
453
|
method: "POST",
|
|
443
454
|
headers: {
|
|
444
455
|
"Content-Type": "application/json",
|
|
445
456
|
},
|
|
446
457
|
body: JSON.stringify({
|
|
447
|
-
|
|
458
|
+
bitcoincash_address,
|
|
448
459
|
user_id: userId,
|
|
460
|
+
timestamp: ts,
|
|
461
|
+
domain: host,
|
|
462
|
+
public_key: publicKeyHex,
|
|
463
|
+
signature: signature,
|
|
449
464
|
}),
|
|
450
465
|
});
|
|
451
466
|
|
|
452
467
|
if (!response.ok) {
|
|
453
468
|
const errorData = await response.json().catch(() => ({}));
|
|
454
|
-
|
|
469
|
+
|
|
455
470
|
if (response.status === 404) {
|
|
456
471
|
throw new UserNotFoundError(errorData.detail || 'User not found');
|
|
457
472
|
}
|
|
458
|
-
|
|
473
|
+
|
|
459
474
|
throw new AuthenticationError(
|
|
460
475
|
errorData.detail || `Registration failed: ${response.statusText}`,
|
|
461
476
|
response.status
|
|
462
477
|
);
|
|
463
478
|
}
|
|
464
479
|
|
|
465
|
-
this._log('User registered successfully', {
|
|
480
|
+
this._log('User registered successfully', { bitcoincash_address, userId });
|
|
466
481
|
return await response.json();
|
|
467
482
|
} catch (error) {
|
|
468
483
|
if (error instanceof OAuthError) {
|