@btc-vision/btc-runtime 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "types": "btc/index.ts",
@@ -210,7 +210,7 @@ export abstract class OP_20 extends OP_NET implements IOP_20 {
210
210
  return this.balanceOfMap.get(owner);
211
211
  }
212
212
 
213
- protected _burn(value: u256): boolean {
213
+ protected _burn(value: u256, onlyOwner: boolean = true): boolean {
214
214
  if (u256.eq(value, u256.Zero)) {
215
215
  throw new Revert(`No tokens`);
216
216
  }
@@ -218,7 +218,7 @@ export abstract class OP_20 extends OP_NET implements IOP_20 {
218
218
  const callee = Blockchain.callee();
219
219
  const caller = Blockchain.caller();
220
220
 
221
- this.onlyOwner(callee); // only indexers can burn tokens
221
+ if (onlyOwner) this.onlyOwner(callee); // only indexers can burn tokens
222
222
 
223
223
  if (this._totalSupply.value < value) throw new Revert(`Insufficient total supply.`);
224
224
  if (!this.balanceOfMap.has(caller)) throw new Revert('Empty');
@@ -236,11 +236,11 @@ export abstract class OP_20 extends OP_NET implements IOP_20 {
236
236
  return true;
237
237
  }
238
238
 
239
- protected _mint(to: Address, value: u256): boolean {
239
+ protected _mint(to: Address, value: u256, onlyOwner: boolean = true): boolean {
240
240
  const callee = Blockchain.callee();
241
241
  const caller = Blockchain.caller();
242
242
 
243
- this.onlyOwner(callee);
243
+ if (onlyOwner) this.onlyOwner(callee);
244
244
 
245
245
  if (caller !== callee) throw new Revert(`callee != caller`);
246
246
  if (callee !== this.owner) throw new Revert('Only indexers can mint tokens');
@@ -223,8 +223,7 @@ export class Sha256 {
223
223
  * @returns A hash function state
224
224
  */
225
225
  constructor() {
226
- let st = Internal._hashInit();
227
- this.st = st;
226
+ this.st = Internal._hashInit();
228
227
  }
229
228
 
230
229
  /**
@@ -248,6 +247,15 @@ export class Sha256 {
248
247
  return Internal._hmac(m, k);
249
248
  }
250
249
 
250
+ /**
251
+ * Hash256
252
+ * @param {Uint8Array} m Message
253
+ * @returns {Uint8Array} `SHA-256(SHA-256(m))`
254
+ */
255
+ static hash256(m: Uint8Array): Uint8Array {
256
+ return Sha256.hash(Sha256.hash(m));
257
+ }
258
+
251
259
  /**
252
260
  * Absorb data to be hashed
253
261
  * @param m (partial) message