@neuraiproject/neurai-scripts 0.7.0 → 0.7.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.
@@ -1121,43 +1121,43 @@ var NeuraiScriptsBundle = (function (exports) {
1121
1121
  // Makes the utils un-importable in browsers without a bundler.
1122
1122
  // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
1123
1123
  /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
1124
- function isBytes(a) {
1124
+ function isBytes$1(a) {
1125
1125
  return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
1126
1126
  }
1127
1127
  /** Asserts something is Uint8Array. */
1128
- function abytes(b, ...lengths) {
1129
- if (!isBytes(b))
1128
+ function abytes$1(b, ...lengths) {
1129
+ if (!isBytes$1(b))
1130
1130
  throw new Error('Uint8Array expected');
1131
1131
  if (lengths.length > 0 && !lengths.includes(b.length))
1132
1132
  throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
1133
1133
  }
1134
1134
  /** Asserts a hash instance has not been destroyed / finished */
1135
- function aexists(instance, checkFinished = true) {
1135
+ function aexists$1(instance, checkFinished = true) {
1136
1136
  if (instance.destroyed)
1137
1137
  throw new Error('Hash instance has been destroyed');
1138
1138
  if (checkFinished && instance.finished)
1139
1139
  throw new Error('Hash#digest() has already been called');
1140
1140
  }
1141
1141
  /** Asserts output is properly-sized byte array */
1142
- function aoutput(out, instance) {
1143
- abytes(out);
1142
+ function aoutput$1(out, instance) {
1143
+ abytes$1(out);
1144
1144
  const min = instance.outputLen;
1145
1145
  if (out.length < min) {
1146
1146
  throw new Error('digestInto() expects output buffer of length at least ' + min);
1147
1147
  }
1148
1148
  }
1149
1149
  /** Zeroize a byte array. Warning: JS provides no guarantees. */
1150
- function clean(...arrays) {
1150
+ function clean$1(...arrays) {
1151
1151
  for (let i = 0; i < arrays.length; i++) {
1152
1152
  arrays[i].fill(0);
1153
1153
  }
1154
1154
  }
1155
1155
  /** Create DataView of an array for easy byte-level manipulation. */
1156
- function createView(arr) {
1156
+ function createView$1(arr) {
1157
1157
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
1158
1158
  }
1159
1159
  /** The rotate right (circular right shift) operation for uint32 */
1160
- function rotr(word, shift) {
1160
+ function rotr$1(word, shift) {
1161
1161
  return (word << (32 - shift)) | (word >>> shift);
1162
1162
  }
1163
1163
  /**
@@ -1177,14 +1177,14 @@ var NeuraiScriptsBundle = (function (exports) {
1177
1177
  function toBytes(data) {
1178
1178
  if (typeof data === 'string')
1179
1179
  data = utf8ToBytes(data);
1180
- abytes(data);
1180
+ abytes$1(data);
1181
1181
  return data;
1182
1182
  }
1183
1183
  /** For runtime check if class implements interface */
1184
1184
  class Hash {
1185
1185
  }
1186
1186
  /** Wraps hash function, creating an interface on top of it */
1187
- function createHasher(hashCons) {
1187
+ function createHasher$1(hashCons) {
1188
1188
  const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
1189
1189
  const tmp = hashCons();
1190
1190
  hashC.outputLen = tmp.outputLen;
@@ -1211,18 +1211,18 @@ var NeuraiScriptsBundle = (function (exports) {
1211
1211
  view.setUint32(byteOffset + l, wl, isLE);
1212
1212
  }
1213
1213
  /** Choice: a ? b : c */
1214
- function Chi(a, b, c) {
1214
+ function Chi$1(a, b, c) {
1215
1215
  return (a & b) ^ (~a & c);
1216
1216
  }
1217
1217
  /** Majority function, true if any two inputs is true. */
1218
- function Maj(a, b, c) {
1218
+ function Maj$1(a, b, c) {
1219
1219
  return (a & b) ^ (a & c) ^ (b & c);
1220
1220
  }
1221
1221
  /**
1222
1222
  * Merkle-Damgard hash construction base class.
1223
1223
  * Could be used to create MD5, RIPEMD, SHA1, SHA2.
1224
1224
  */
1225
- class HashMD extends Hash {
1225
+ let HashMD$1 = class HashMD extends Hash {
1226
1226
  constructor(blockLen, outputLen, padOffset, isLE) {
1227
1227
  super();
1228
1228
  this.finished = false;
@@ -1234,19 +1234,19 @@ var NeuraiScriptsBundle = (function (exports) {
1234
1234
  this.padOffset = padOffset;
1235
1235
  this.isLE = isLE;
1236
1236
  this.buffer = new Uint8Array(blockLen);
1237
- this.view = createView(this.buffer);
1237
+ this.view = createView$1(this.buffer);
1238
1238
  }
1239
1239
  update(data) {
1240
- aexists(this);
1240
+ aexists$1(this);
1241
1241
  data = toBytes(data);
1242
- abytes(data);
1242
+ abytes$1(data);
1243
1243
  const { view, buffer, blockLen } = this;
1244
1244
  const len = data.length;
1245
1245
  for (let pos = 0; pos < len;) {
1246
1246
  const take = Math.min(blockLen - this.pos, len - pos);
1247
1247
  // Fast path: we have at least one block in input, cast it to view and process
1248
1248
  if (take === blockLen) {
1249
- const dataView = createView(data);
1249
+ const dataView = createView$1(data);
1250
1250
  for (; blockLen <= len - pos; pos += blockLen)
1251
1251
  this.process(dataView, pos);
1252
1252
  continue;
@@ -1264,8 +1264,8 @@ var NeuraiScriptsBundle = (function (exports) {
1264
1264
  return this;
1265
1265
  }
1266
1266
  digestInto(out) {
1267
- aexists(this);
1268
- aoutput(out, this);
1267
+ aexists$1(this);
1268
+ aoutput$1(out, this);
1269
1269
  this.finished = true;
1270
1270
  // Padding
1271
1271
  // We can avoid allocation of buffer for padding completely if it
@@ -1274,7 +1274,7 @@ var NeuraiScriptsBundle = (function (exports) {
1274
1274
  let { pos } = this;
1275
1275
  // append the bit '1' to the message
1276
1276
  buffer[pos++] = 0b10000000;
1277
- clean(this.buffer.subarray(pos));
1277
+ clean$1(this.buffer.subarray(pos));
1278
1278
  // we have less than padOffset left in buffer, so we cannot put length in
1279
1279
  // current block, need process it and pad again
1280
1280
  if (this.padOffset > blockLen - pos) {
@@ -1289,7 +1289,7 @@ var NeuraiScriptsBundle = (function (exports) {
1289
1289
  // So we just write lowest 64 bits of that value.
1290
1290
  setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
1291
1291
  this.process(view, 0);
1292
- const oview = createView(out);
1292
+ const oview = createView$1(out);
1293
1293
  const len = this.outputLen;
1294
1294
  // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
1295
1295
  if (len % 4)
@@ -1323,13 +1323,13 @@ var NeuraiScriptsBundle = (function (exports) {
1323
1323
  clone() {
1324
1324
  return this._cloneInto();
1325
1325
  }
1326
- }
1326
+ };
1327
1327
  /**
1328
1328
  * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
1329
1329
  * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
1330
1330
  */
1331
1331
  /** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
1332
- const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
1332
+ const SHA256_IV$1 = /* @__PURE__ */ Uint32Array.from([
1333
1333
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
1334
1334
  ]);
1335
1335
 
@@ -1345,7 +1345,7 @@ var NeuraiScriptsBundle = (function (exports) {
1345
1345
  * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
1346
1346
  */
1347
1347
  // prettier-ignore
1348
- const SHA256_K = /* @__PURE__ */ Uint32Array.from([
1348
+ const SHA256_K$1 = /* @__PURE__ */ Uint32Array.from([
1349
1349
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
1350
1350
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
1351
1351
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -1356,20 +1356,20 @@ var NeuraiScriptsBundle = (function (exports) {
1356
1356
  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
1357
1357
  ]);
1358
1358
  /** Reusable temporary buffer. "W" comes straight from spec. */
1359
- const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
1360
- class SHA256 extends HashMD {
1359
+ const SHA256_W$1 = /* @__PURE__ */ new Uint32Array(64);
1360
+ class SHA256 extends HashMD$1 {
1361
1361
  constructor(outputLen = 32) {
1362
1362
  super(64, outputLen, 8, false);
1363
1363
  // We cannot use array here since array allows indexing by variable
1364
1364
  // which means optimizer/compiler cannot use registers.
1365
- this.A = SHA256_IV[0] | 0;
1366
- this.B = SHA256_IV[1] | 0;
1367
- this.C = SHA256_IV[2] | 0;
1368
- this.D = SHA256_IV[3] | 0;
1369
- this.E = SHA256_IV[4] | 0;
1370
- this.F = SHA256_IV[5] | 0;
1371
- this.G = SHA256_IV[6] | 0;
1372
- this.H = SHA256_IV[7] | 0;
1365
+ this.A = SHA256_IV$1[0] | 0;
1366
+ this.B = SHA256_IV$1[1] | 0;
1367
+ this.C = SHA256_IV$1[2] | 0;
1368
+ this.D = SHA256_IV$1[3] | 0;
1369
+ this.E = SHA256_IV$1[4] | 0;
1370
+ this.F = SHA256_IV$1[5] | 0;
1371
+ this.G = SHA256_IV$1[6] | 0;
1372
+ this.H = SHA256_IV$1[7] | 0;
1373
1373
  }
1374
1374
  get() {
1375
1375
  const { A, B, C, D, E, F, G, H } = this;
@@ -1389,21 +1389,21 @@ var NeuraiScriptsBundle = (function (exports) {
1389
1389
  process(view, offset) {
1390
1390
  // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
1391
1391
  for (let i = 0; i < 16; i++, offset += 4)
1392
- SHA256_W[i] = view.getUint32(offset, false);
1392
+ SHA256_W$1[i] = view.getUint32(offset, false);
1393
1393
  for (let i = 16; i < 64; i++) {
1394
- const W15 = SHA256_W[i - 15];
1395
- const W2 = SHA256_W[i - 2];
1396
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
1397
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
1398
- SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
1394
+ const W15 = SHA256_W$1[i - 15];
1395
+ const W2 = SHA256_W$1[i - 2];
1396
+ const s0 = rotr$1(W15, 7) ^ rotr$1(W15, 18) ^ (W15 >>> 3);
1397
+ const s1 = rotr$1(W2, 17) ^ rotr$1(W2, 19) ^ (W2 >>> 10);
1398
+ SHA256_W$1[i] = (s1 + SHA256_W$1[i - 7] + s0 + SHA256_W$1[i - 16]) | 0;
1399
1399
  }
1400
1400
  // Compression function main loop, 64 rounds
1401
1401
  let { A, B, C, D, E, F, G, H } = this;
1402
1402
  for (let i = 0; i < 64; i++) {
1403
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
1404
- const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
1405
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
1406
- const T2 = (sigma0 + Maj(A, B, C)) | 0;
1403
+ const sigma1 = rotr$1(E, 6) ^ rotr$1(E, 11) ^ rotr$1(E, 25);
1404
+ const T1 = (H + sigma1 + Chi$1(E, F, G) + SHA256_K$1[i] + SHA256_W$1[i]) | 0;
1405
+ const sigma0 = rotr$1(A, 2) ^ rotr$1(A, 13) ^ rotr$1(A, 22);
1406
+ const T2 = (sigma0 + Maj$1(A, B, C)) | 0;
1407
1407
  H = G;
1408
1408
  G = F;
1409
1409
  F = E;
@@ -1425,11 +1425,11 @@ var NeuraiScriptsBundle = (function (exports) {
1425
1425
  this.set(A, B, C, D, E, F, G, H);
1426
1426
  }
1427
1427
  roundClean() {
1428
- clean(SHA256_W);
1428
+ clean$1(SHA256_W$1);
1429
1429
  }
1430
1430
  destroy() {
1431
1431
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
1432
- clean(this.buffer);
1432
+ clean$1(this.buffer);
1433
1433
  }
1434
1434
  }
1435
1435
  /**
@@ -1439,7 +1439,7 @@ var NeuraiScriptsBundle = (function (exports) {
1439
1439
  * To break sha256 using birthday attack, attackers need to try 2^128 hashes.
1440
1440
  * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
1441
1441
  */
1442
- const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
1442
+ const sha256$2 = /* @__PURE__ */ createHasher$1(() => new SHA256());
1443
1443
 
1444
1444
  /**
1445
1445
  * SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
@@ -1452,7 +1452,7 @@ var NeuraiScriptsBundle = (function (exports) {
1452
1452
  * @deprecated
1453
1453
  */
1454
1454
  /** @deprecated Use import from `noble/hashes/sha2` module */
1455
- const sha256 = sha256$1;
1455
+ const sha256$1 = sha256$2;
1456
1456
 
1457
1457
  function bs58checkBase (checksumFn) {
1458
1458
  // Encode a buffer as a base58-check encoded string
@@ -1500,7 +1500,7 @@ var NeuraiScriptsBundle = (function (exports) {
1500
1500
 
1501
1501
  // SHA256(SHA256(buffer))
1502
1502
  function sha256x2(buffer) {
1503
- return sha256(sha256(buffer));
1503
+ return sha256$1(sha256$1(buffer));
1504
1504
  }
1505
1505
  var bs58check = bs58checkBase(sha256x2);
1506
1506
 
@@ -2563,7 +2563,9 @@ var NeuraiScriptsBundle = (function (exports) {
2563
2563
  * Numbers are minimal CScriptNum stack values (0 = empty element). Wrap the
2564
2564
  * result with `buildAuthScriptWitnessNoAuth({ args, witnessScript: covenant })`
2565
2565
  * (from `standard/authscript.ts`) to get the final `[0x00, ...args, covenant]`
2566
- * witness.
2566
+ * witness, and serialize the spending transaction with
2567
+ * `serializeTransaction` from `@neuraiproject/neurai-create-transaction`
2568
+ * (0.5.1+, witness elements as hex strings: `witness.map(bytesToHex)`).
2567
2569
  */
2568
2570
  const MAX_PQ_SCRIPT_ELEMENT_SIZE = 3072;
2569
2571
  /**