@1sat/connect 0.0.22 → 0.0.24

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/auth.d.ts CHANGED
@@ -1,19 +1,20 @@
1
1
  /**
2
- * BRC-77 request signing using WalletInterface directly.
2
+ * BRC-77 request signing using WalletInterface.
3
3
  *
4
- * Same logic as getAuthToken action but without OneSatContext
5
- * takes a WalletInterface so any connected wallet can sign.
4
+ * Produces a proper BRC-77 message envelope (version + sender pubkey +
5
+ * recipient indicator + keyID + DER signature) that go-bitcoin-auth and
6
+ * @bsv/sdk SignedMessage.verify can both verify.
6
7
  */
7
8
  import type { WalletInterface } from '@bsv/sdk';
8
9
  /**
9
10
  * Sign an HTTP request with BRC-77 auth, returning the auth token string.
10
11
  *
11
- * The token format is: `pubkey|scheme|timestamp|requestPath|signature`
12
+ * The token format is: `pubkey|brc77|timestamp|requestPath|signature`
13
+ * where signature is a base64-encoded BRC-77 message envelope.
12
14
  *
13
15
  * @param wallet - Any BRC-100 WalletInterface (Sigma CWI, OneSat, extension, etc.)
14
16
  * @param requestPath - API endpoint path including query params
15
17
  * @param body - Optional request body to include in signature
16
- * @param scheme - Signature scheme: 'brc77' (default) or 'bsm'
17
18
  */
18
- export declare function signRequest(wallet: WalletInterface, requestPath: string, body?: string, scheme?: 'brc77' | 'bsm'): Promise<string>;
19
+ export declare function signRequest(wallet: WalletInterface, requestPath: string, body?: string): Promise<string>;
19
20
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAkB/C;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAChC,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,GAAE,OAAO,GAAG,KAAe,GAC/B,OAAO,CAAC,MAAM,CAAC,CA0BjB"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAO/C;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAChC,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAsCjB"}
package/dist/index.js CHANGED
@@ -34768,39 +34768,6 @@ class Transaction {
34768
34768
  });
34769
34769
  }
34770
34770
  }
34771
- // ../../node_modules/.bun/@bsv+sdk@2.0.13/node_modules/@bsv/sdk/dist/esm/src/compat/BSM.js
34772
- var exports_BSM = {};
34773
- __export(exports_BSM, {
34774
- verify: () => verify2,
34775
- sign: () => sign2,
34776
- magicHash: () => magicHash
34777
- });
34778
- var prefix = `Bitcoin Signed Message:
34779
- `;
34780
- var magicHash = (messageBuf) => {
34781
- const bw = new Writer;
34782
- bw.writeVarIntNum(prefix.length);
34783
- bw.write(toArray2(prefix, "utf8"));
34784
- bw.writeVarIntNum(messageBuf.length);
34785
- bw.write(messageBuf);
34786
- const buf = bw.toArray();
34787
- const hashBuf = hash256(buf);
34788
- return hashBuf;
34789
- };
34790
- var sign2 = (message, privateKey, mode = "base64") => {
34791
- const hashBuf = magicHash(message);
34792
- const sig = sign(new BigNumber(hashBuf), privateKey, true);
34793
- if (mode === "raw") {
34794
- return sig;
34795
- }
34796
- const h = new BigNumber(hashBuf);
34797
- const r2 = sig.CalculateRecoveryFactor(privateKey.toPublicKey(), h);
34798
- return sig.toCompact(r2, true, "base64");
34799
- };
34800
- var verify2 = (message, sig, pubKey) => {
34801
- const hashBuf = magicHash(message);
34802
- return verify(new BigNumber(hashBuf), sig, pubKey);
34803
- };
34804
34771
  // ../../node_modules/.bun/@bsv+sdk@2.0.13/node_modules/@bsv/sdk/dist/esm/src/compat/HD.js
34805
34772
  class HD {
34806
34773
  versionBytesNum;
@@ -41187,16 +41154,16 @@ class BigNumber2 {
41187
41154
  this.assert(typeof effectiveBase === "number" && effectiveBase === (effectiveBase | 0) && effectiveBase >= 2 && effectiveBase <= 36, "Base must be an integer between 2 and 36");
41188
41155
  const originalNumberStr = number.toString().replace(/\s+/g, "");
41189
41156
  let start = 0;
41190
- let sign3 = 0;
41157
+ let sign2 = 0;
41191
41158
  if (originalNumberStr.startsWith("-")) {
41192
41159
  start++;
41193
- sign3 = 1;
41160
+ sign2 = 1;
41194
41161
  } else if (originalNumberStr.startsWith("+")) {
41195
41162
  start++;
41196
41163
  }
41197
41164
  const numStr = originalNumberStr.substring(start);
41198
41165
  if (numStr.length === 0) {
41199
- this._initializeState(0n, sign3 === 1 && originalNumberStr.startsWith("-") ? 1 : 0);
41166
+ this._initializeState(0n, sign2 === 1 && originalNumberStr.startsWith("-") ? 1 : 0);
41200
41167
  this.normSign();
41201
41168
  return;
41202
41169
  }
@@ -41215,7 +41182,7 @@ class BigNumber2 {
41215
41182
  bytes2.push(byteVal);
41216
41183
  }
41217
41184
  this.initArray(bytes2, "le");
41218
- this._sign = sign3;
41185
+ this._sign = sign2;
41219
41186
  this.normSign();
41220
41187
  return;
41221
41188
  } else {
@@ -41225,12 +41192,12 @@ class BigNumber2 {
41225
41192
  throw new Error("Invalid character in " + numStr);
41226
41193
  }
41227
41194
  }
41228
- this._initializeState(tempMagnitude, sign3);
41195
+ this._initializeState(tempMagnitude, sign2);
41229
41196
  this.normSign();
41230
41197
  } else {
41231
41198
  try {
41232
41199
  this._parseBaseString(numStr, effectiveBase);
41233
- this._sign = sign3;
41200
+ this._sign = sign2;
41234
41201
  this.normSign();
41235
41202
  if (effectiveEndian === "le") {
41236
41203
  const currentSign = this._sign;
@@ -41320,9 +41287,9 @@ class BigNumber2 {
41320
41287
  }
41321
41288
  return r2;
41322
41289
  }
41323
- _initializeState(magnitude, sign3) {
41290
+ _initializeState(magnitude, sign2) {
41324
41291
  this._magnitude = magnitude;
41325
- this._sign = magnitude === 0n ? 0 : sign3;
41292
+ this._sign = magnitude === 0n ? 0 : sign2;
41326
41293
  this._finishInitialization();
41327
41294
  }
41328
41295
  _finishInitialization() {
@@ -42175,9 +42142,9 @@ class BigNumber2 {
42175
42142
  if (endian === "little") {
42176
42143
  beBytes.reverse();
42177
42144
  }
42178
- let sign3 = 0;
42145
+ let sign2 = 0;
42179
42146
  if (beBytes.length > 0 && (beBytes[0] & 128) !== 0) {
42180
- sign3 = 1;
42147
+ sign2 = 1;
42181
42148
  beBytes[0] &= 127;
42182
42149
  }
42183
42150
  let magnitude = 0n;
@@ -42192,7 +42159,7 @@ class BigNumber2 {
42192
42159
  magnitude = hex.length === 0 ? 0n : BigInt("0x" + hex);
42193
42160
  }
42194
42161
  const r2 = new BigNumber2(0n);
42195
- r2._initializeState(magnitude, sign3);
42162
+ r2._initializeState(magnitude, sign2);
42196
42163
  return r2;
42197
42164
  }
42198
42165
  toSm(endian = "big") {
@@ -45109,16 +45076,16 @@ var toBase582 = (bin) => {
45109
45076
  result.reverse();
45110
45077
  return String.fromCharCode(...result);
45111
45078
  };
45112
- var toBase58Check2 = (bin, prefix2 = [0]) => {
45113
- let hash = hash2562([...prefix2, ...bin]);
45114
- hash = [...prefix2, ...bin, ...hash.slice(0, 4)];
45079
+ var toBase58Check2 = (bin, prefix = [0]) => {
45080
+ let hash = hash2562([...prefix, ...bin]);
45081
+ hash = [...prefix, ...bin, ...hash.slice(0, 4)];
45115
45082
  return toBase582(hash);
45116
45083
  };
45117
45084
  var fromBase58Check2 = (str, enc, prefixLength = 1) => {
45118
45085
  const bin = fromBase582(str);
45119
- let prefix2 = bin.slice(0, prefixLength);
45086
+ let prefix = bin.slice(0, prefixLength);
45120
45087
  let data = bin.slice(prefixLength, -4);
45121
- let hash = [...prefix2, ...data];
45088
+ let hash = [...prefix, ...data];
45122
45089
  hash = hash2562(hash);
45123
45090
  bin.slice(-4).forEach((check, index) => {
45124
45091
  if (check !== hash[index]) {
@@ -45126,10 +45093,10 @@ var fromBase58Check2 = (str, enc, prefixLength = 1) => {
45126
45093
  }
45127
45094
  });
45128
45095
  if (enc === "hex") {
45129
- prefix2 = toHex3(prefix2);
45096
+ prefix = toHex3(prefix);
45130
45097
  data = toHex3(data);
45131
45098
  }
45132
- return { prefix: prefix2, data };
45099
+ return { prefix, data };
45133
45100
  };
45134
45101
 
45135
45102
  class Writer2 {
@@ -47435,8 +47402,8 @@ class Curve2 {
47435
47402
  // ../../node_modules/.bun/@bsv+sdk@2.0.12/node_modules/@bsv/sdk/dist/esm/src/primitives/ECDSA.js
47436
47403
  var exports_ECDSA2 = {};
47437
47404
  __export(exports_ECDSA2, {
47438
- verify: () => verify3,
47439
- sign: () => sign3
47405
+ verify: () => verify2,
47406
+ sign: () => sign2
47440
47407
  });
47441
47408
 
47442
47409
  // ../../node_modules/.bun/@bsv+sdk@2.0.12/node_modules/@bsv/sdk/dist/esm/src/primitives/Signature.js
@@ -47515,7 +47482,7 @@ class Signature2 {
47515
47482
  }
47516
47483
  verify(msg, key, enc) {
47517
47484
  const msgHash = new BigNumber2(sha2562(msg, enc), 16);
47518
- return verify3(msgHash, this, key);
47485
+ return verify2(msgHash, this, key);
47519
47486
  }
47520
47487
  toString(enc) {
47521
47488
  return this.toDER(enc);
@@ -47703,7 +47670,7 @@ var curve2 = new Curve2;
47703
47670
  var bytes2 = curve2.n.byteLength();
47704
47671
  var ns12 = curve2.n.subn(1);
47705
47672
  var halfN2 = N_BIGINT2 >> 1n;
47706
- var sign3 = (msg, key, forceLowS = false, customK) => {
47673
+ var sign2 = (msg, key, forceLowS = false, customK) => {
47707
47674
  const nBitLength = curve2.n.bitLength();
47708
47675
  if (msg.bitLength() > nBitLength) {
47709
47676
  throw new Error(`ECDSA message is too large: expected <= ${nBitLength} bits. Callers must hash messages before signing.`);
@@ -47760,7 +47727,7 @@ var sign3 = (msg, key, forceLowS = false, customK) => {
47760
47727
  return new Signature2(r3, s3);
47761
47728
  }
47762
47729
  };
47763
- var verify3 = (msg, sig, key) => {
47730
+ var verify2 = (msg, sig, key) => {
47764
47731
  const nBitLength = curve2.n.bitLength();
47765
47732
  if (msg.bitLength() > nBitLength) {
47766
47733
  return false;
@@ -47834,7 +47801,7 @@ class PublicKey2 extends Point2 {
47834
47801
  }
47835
47802
  verify(msg, sig, enc) {
47836
47803
  const msgHash = new BigNumber2(sha2562(msg, enc), 16);
47837
- return verify3(msgHash, sig, this);
47804
+ return verify2(msgHash, sig, this);
47838
47805
  }
47839
47806
  toDER(enc) {
47840
47807
  if (enc === "hex")
@@ -47848,17 +47815,17 @@ class PublicKey2 extends Point2 {
47848
47815
  }
47849
47816
  return pkh;
47850
47817
  }
47851
- toAddress(prefix2 = [0]) {
47852
- if (typeof prefix2 === "string") {
47853
- if (prefix2 === "testnet" || prefix2 === "test") {
47854
- prefix2 = [111];
47855
- } else if (prefix2 === "mainnet" || prefix2 === "main") {
47856
- prefix2 = [0];
47818
+ toAddress(prefix = [0]) {
47819
+ if (typeof prefix === "string") {
47820
+ if (prefix === "testnet" || prefix === "test") {
47821
+ prefix = [111];
47822
+ } else if (prefix === "mainnet" || prefix === "main") {
47823
+ prefix = [0];
47857
47824
  } else {
47858
- throw new Error(`Invalid prefix ${prefix2}`);
47825
+ throw new Error(`Invalid prefix ${prefix}`);
47859
47826
  }
47860
47827
  }
47861
- return toBase58Check2(this.toHash(), prefix2);
47828
+ return toBase58Check2(this.toHash(), prefix);
47862
47829
  }
47863
47830
  deriveChild(privateKey, invoiceNumber, cacheSharedSecret, retrieveCachedSharedSecret) {
47864
47831
  let sharedSecret;
@@ -48103,25 +48070,25 @@ class PrivateKey2 extends BigNumber2 {
48103
48070
  }
48104
48071
  sign(msg, enc, forceLowS = true, customK) {
48105
48072
  const msgHash = new BigNumber2(sha2562(msg, enc), 16);
48106
- return sign3(msgHash, this, forceLowS, customK);
48073
+ return sign2(msgHash, this, forceLowS, customK);
48107
48074
  }
48108
48075
  verify(msg, sig, enc) {
48109
48076
  const msgHash = new BigNumber2(sha2562(msg, enc), 16);
48110
- return verify3(msgHash, sig, this.toPublicKey());
48077
+ return verify2(msgHash, sig, this.toPublicKey());
48111
48078
  }
48112
48079
  toPublicKey() {
48113
48080
  const c = new Curve2;
48114
48081
  const p = c.g.mulCT(this);
48115
48082
  return new PublicKey2(p.x, p.y);
48116
48083
  }
48117
- toWif(prefix2 = [128]) {
48084
+ toWif(prefix = [128]) {
48118
48085
  if (!this.isValid()) {
48119
48086
  throw new Error("Value is out of field");
48120
48087
  }
48121
- return toBase58Check2([...this.toArray("be", 32), 1], prefix2);
48088
+ return toBase58Check2([...this.toArray("be", 32), 1], prefix);
48122
48089
  }
48123
- toAddress(prefix2 = [0]) {
48124
- return this.toPublicKey().toAddress(prefix2);
48090
+ toAddress(prefix = [0]) {
48091
+ return this.toPublicKey().toAddress(prefix);
48125
48092
  }
48126
48093
  toHex() {
48127
48094
  return super.toHex(32);
@@ -50149,7 +50116,7 @@ class Spend2 {
50149
50116
  cache: this.sigHashCache
50150
50117
  });
50151
50118
  const hash = new BigNumber2(hash2562(preimage));
50152
- return verify3(hash, sig, pubkey);
50119
+ return verify2(hash, sig, pubkey);
50153
50120
  }
50154
50121
  step() {
50155
50122
  if (this.stackMem > this.memoryLimit) {
@@ -52463,10 +52430,10 @@ class Beef3 {
52463
52430
  toUint8ArrayAtomic(txid) {
52464
52431
  const { beef, writer } = this.getBeefForAtomic(txid);
52465
52432
  const beefUint8 = beef.getSerializedBytes();
52466
- const prefix2 = writer.toUint8Array();
52467
- const atomic = new Uint8Array(prefix2.length + beefUint8.length);
52468
- atomic.set(prefix2, 0);
52469
- atomic.set(beefUint8, prefix2.length);
52433
+ const prefix = writer.toUint8Array();
52434
+ const atomic = new Uint8Array(prefix.length + beefUint8.length);
52435
+ atomic.set(prefix, 0);
52436
+ atomic.set(beefUint8, prefix.length);
52470
52437
  return atomic;
52471
52438
  }
52472
52439
  toHex() {
@@ -53372,15 +53339,15 @@ class Transaction2 {
53372
53339
  return writer.toArray();
53373
53340
  }
53374
53341
  toAtomicBEEF(allowPartial) {
53375
- const prefix2 = [1, 1, 1, 1];
53342
+ const prefix = [1, 1, 1, 1];
53376
53343
  const txHash = this.hash();
53377
53344
  const beefData = this.toBEEF(allowPartial);
53378
- return prefix2.concat(txHash, beefData);
53345
+ return prefix.concat(txHash, beefData);
53379
53346
  }
53380
53347
  toAtomicBEEFUint8Array(allowPartial) {
53381
53348
  const writer = new WriterUint8Array2;
53382
- const prefix2 = [1, 1, 1, 1];
53383
- writer.write(prefix2);
53349
+ const prefix = [1, 1, 1, 1];
53350
+ writer.write(prefix);
53384
53351
  const txHash = this.hash();
53385
53352
  writer.write(txHash);
53386
53353
  this.writeSerializedBEEF(writer, allowPartial);
@@ -61442,14 +61409,14 @@ var getAuthHeader = async (options) => {
61442
61409
  }
61443
61410
  headers["authorization"] = `Basic ${btoa(`${username}:${password}`)}`;
61444
61411
  } else if (options.auth.type === "Custom") {
61445
- const [prefix2, value] = await Promise.all([
61412
+ const [prefix, value] = await Promise.all([
61446
61413
  getValue(options.auth.prefix),
61447
61414
  getValue(options.auth.value)
61448
61415
  ]);
61449
61416
  if (!value) {
61450
61417
  return headers;
61451
61418
  }
61452
- headers["authorization"] = `${prefix2 != null ? prefix2 : ""} ${value}`;
61419
+ headers["authorization"] = `${prefix != null ? prefix : ""} ${value}`;
61453
61420
  }
61454
61421
  }
61455
61422
  return headers;
@@ -63701,34 +63668,35 @@ async function connectWallet(config) {
63701
63668
  return null;
63702
63669
  }
63703
63670
  // src/auth.ts
63704
- var { toArray: toArray5, toHex: toHex4 } = exports_utils;
63705
- var AUTH_PROTOCOL_ID = [2, "bitcoin-auth"];
63706
- var AUTH_KEY_ID = "auth-0";
63707
- function compactSign(derSig, msgHash, pubKeyHex) {
63708
- const sig = Signature.fromDER(toHex4(derSig), "hex");
63709
- const pubKey = PublicKey.fromString(pubKeyHex);
63710
- const recovery = sig.CalculateRecoveryFactor(pubKey, new BigNumber(msgHash));
63711
- return sig.toCompact(recovery, true, "base64");
63712
- }
63713
- async function signRequest(wallet3, requestPath, body, scheme = "brc77") {
63671
+ var { toArray: toArray5, toBase64: toBase643, toHex: toHex4 } = exports_utils;
63672
+ var BRC77_VERSION = [66, 66, 51, 1];
63673
+ var BRC77_PROTOCOL_ID = [2, "message signing"];
63674
+ async function signRequest(wallet3, requestPath, body) {
63714
63675
  const timestamp2 = new Date().toISOString();
63715
63676
  const bodyHash = body ? toHex4(exports_Hash.sha256(toArray5(body, "utf8"))) : "";
63716
63677
  const message = `${requestPath}|${timestamp2}|${bodyHash}`;
63717
63678
  const messageBytes = toArray5(message, "utf8");
63718
- const msgHash = scheme === "bsm" ? exports_BSM.magicHash(messageBytes) : exports_Hash.sha256(messageBytes);
63719
- const { publicKey: pubKeyHex } = await wallet3.getPublicKey({
63720
- protocolID: AUTH_PROTOCOL_ID,
63721
- keyID: AUTH_KEY_ID,
63722
- forSelf: true
63679
+ const keyID = Random_default(32);
63680
+ const keyIDBase64 = toBase643(keyID);
63681
+ const { publicKey: senderPubKeyHex } = await wallet3.getPublicKey({
63682
+ identityKey: true
63723
63683
  });
63724
63684
  const { signature: derSig } = await wallet3.createSignature({
63725
- protocolID: AUTH_PROTOCOL_ID,
63726
- keyID: AUTH_KEY_ID,
63727
- counterparty: "self",
63728
- hashToDirectlySign: Array.from(msgHash)
63685
+ protocolID: BRC77_PROTOCOL_ID,
63686
+ keyID: keyIDBase64,
63687
+ counterparty: "anyone",
63688
+ data: Array.from(messageBytes)
63729
63689
  });
63730
- const signature = compactSign(derSig, msgHash, pubKeyHex);
63731
- return `${pubKeyHex}|${scheme}|${timestamp2}|${requestPath}|${signature}`;
63690
+ const senderPubKeyBytes = toArray5(senderPubKeyHex, "hex");
63691
+ const envelope = [
63692
+ ...BRC77_VERSION,
63693
+ ...senderPubKeyBytes,
63694
+ 0,
63695
+ ...keyID,
63696
+ ...derSig
63697
+ ];
63698
+ const signatureBase64 = toBase643(envelope);
63699
+ return `${senderPubKeyHex}|brc77|${timestamp2}|${requestPath}|${signatureBase64}`;
63732
63700
  }
63733
63701
  // src/transport.ts
63734
63702
  var DEFAULT_WALLET_URL2 = "https://1sat.market";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/connect",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Connection layer for 1Sat wallet - popup flow, events, session management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",