cashscript 0.10.0-next.1 → 0.10.0-next.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.
@@ -1,12 +1,12 @@
1
1
  import { Artifact } from '@cashscript/utils';
2
- import { AuthenticationTemplate, AuthenticationProgramStateBCHCHIPs } from '@bitauth/libauth';
2
+ import { WalletTemplate, AuthenticationProgramStateBCHCHIPs } from '@bitauth/libauth';
3
3
  import { Transaction } from './Transaction.js';
4
4
  export declare const stringify: (any: any, spaces?: number | undefined) => string;
5
5
  export declare const buildTemplate: ({ transaction, transactionHex, }: {
6
6
  transaction: Transaction;
7
7
  transactionHex?: string | undefined;
8
- }) => Promise<AuthenticationTemplate>;
9
- export declare const getBitauthUri: (template: AuthenticationTemplate) => string;
10
- export declare const evaluateTemplate: (template: AuthenticationTemplate) => boolean;
8
+ }) => Promise<WalletTemplate>;
9
+ export declare const getBitauthUri: (template: WalletTemplate) => string;
10
+ export declare const evaluateTemplate: (template: WalletTemplate) => boolean;
11
11
  export declare type DebugResult = AuthenticationProgramStateBCHCHIPs[];
12
- export declare const debugTemplate: (template: AuthenticationTemplate, artifact: Artifact) => DebugResult;
12
+ export declare const debugTemplate: (template: WalletTemplate, artifact: Artifact) => DebugResult;
@@ -1,7 +1,7 @@
1
1
  import { Op, PrimitiveType, bytecodeToScript, decodeBool, decodeInt, decodeString, formatBitAuthScript, } from '@cashscript/utils';
2
- import { hash160, hexToBin, decodeTransaction, binToHex, authenticationTemplateToCompilerConfiguration, createCompiler, createVirtualMachineBCHCHIPs, binToBase64, utf8ToBin, isHex, AuthenticationErrorCommon, } from '@bitauth/libauth';
2
+ import { hash160, hexToBin, decodeTransaction, binToHex, walletTemplateToCompilerConfiguration, createCompiler, createVirtualMachineBCHCHIPs, binToBase64, utf8ToBin, isHex, AuthenticationErrorCommon, } from '@bitauth/libauth';
3
3
  import { deflate } from 'pako';
4
- import { isUtxoP2PKH, } from '../src/interfaces.js';
4
+ import { isUtxoP2PKH, } from './interfaces.js';
5
5
  import { encodeArgument as csEncodeArgument } from './Argument.js';
6
6
  import { toRegExp } from './utils.js';
7
7
  // all bitauth variables must be in snake case
@@ -105,7 +105,14 @@ const createScenarioTransaction = (libauthTransaction, csTransaction) => {
105
105
  lockingBytecode: lockingBytecode instanceof Uint8Array
106
106
  ? binToHex(lockingBytecode)
107
107
  : lockingBytecode,
108
- token: output.token,
108
+ token: output.token ? {
109
+ amount: output.token.amount.toString(),
110
+ category: binToHex(output.token.category),
111
+ nft: output.token.nft ? {
112
+ capability: output.token.nft.capability,
113
+ commitment: binToHex(output.token.nft.commitment),
114
+ } : undefined,
115
+ } : undefined,
109
116
  valueSatoshis: Number(output.valueSatoshis),
110
117
  };
111
118
  });
@@ -357,7 +364,7 @@ export const getBitauthUri = (template) => {
357
364
  };
358
365
  // internal util. instantiates the virtual machine and compiles the template into a program
359
366
  const createProgram = (template) => {
360
- const configuration = authenticationTemplateToCompilerConfiguration(template);
367
+ const configuration = walletTemplateToCompilerConfiguration(template);
361
368
  const vm = createVirtualMachineBCHCHIPs();
362
369
  const compiler = createCompiler(configuration);
363
370
  const scenarioGeneration = compiler.generateScenario({
@@ -1,3 +1,4 @@
1
+ import { WalletTemplate } from '@bitauth/libauth';
1
2
  import { AbiFunction } from '@cashscript/utils';
2
3
  import { Utxo, Output, Recipient, TokenDetails, TransactionDetails, Unlocker } from './interfaces.js';
3
4
  import SignatureTemplate from './SignatureTemplate.js';
@@ -37,6 +38,7 @@ export declare class Transaction {
37
38
  send(raw: true): Promise<string>;
38
39
  debug(): Promise<DebugResult>;
39
40
  bitauthUri(): Promise<string>;
41
+ getLibauthTemplate(): Promise<WalletTemplate>;
40
42
  private getTxDetails;
41
43
  private setInputsAndOutputs;
42
44
  }
@@ -139,17 +139,16 @@ export class Transaction {
139
139
  }
140
140
  // method to debug the transaction with libauth VM, throws upon evaluation error
141
141
  async debug() {
142
- const template = await buildTemplate({
143
- transaction: this,
144
- });
142
+ const template = await this.getLibauthTemplate();
145
143
  return debugTemplate(template, this.contract.artifact);
146
144
  }
147
145
  async bitauthUri() {
148
- const template = await buildTemplate({
149
- transaction: this,
150
- });
146
+ const template = await this.getLibauthTemplate();
151
147
  return getBitauthUri(template);
152
148
  }
149
+ async getLibauthTemplate() {
150
+ return buildTemplate({ transaction: this });
151
+ }
153
152
  async getTxDetails(txid, raw) {
154
153
  for (let retries = 0; retries < 1200; retries += 1) {
155
154
  await delay(500);
@@ -18,7 +18,7 @@ export default class MockNetworkProvider {
18
18
  }
19
19
  }
20
20
  async getUtxos(address) {
21
- return this.utxoMap[address];
21
+ return this.utxoMap[address] ?? [];
22
22
  }
23
23
  async getBlockHeight() {
24
24
  return 133700;
@@ -19,6 +19,8 @@ Received: ${printReceived(received)}`;
19
19
  catch (error) {
20
20
  message = error;
21
21
  }
22
+ // TODO: If no console.log was called, then spyOnLoggerError.mock.calls[0] is undefined.
23
+ // We should handle that case properly.
22
24
  const received = spyOnLoggerError.mock.calls[0][0];
23
25
  spyOnLoggerError.mockClear();
24
26
  return {
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cashAddressToLockingBytecode, decodeCashAddress, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, generateSigningSerializationBCH, utf8ToBin, hexToBin, flattenBinArray, LockingBytecodeType, encodeTransactionOutput, isHex, bigIntToCompactSize, AuthenticationErrorCommon, NonFungibleTokenCapability, bigIntToVmNumber, } from '@bitauth/libauth';
1
+ import { cashAddressToLockingBytecode, decodeCashAddress, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, generateSigningSerializationBCH, utf8ToBin, hexToBin, flattenBinArray, LockingBytecodeType, encodeTransactionOutput, isHex, bigIntToCompactUint, AuthenticationErrorCommon, NonFungibleTokenCapability, bigIntToVmNumber, } from '@bitauth/libauth';
2
2
  import { encodeInt, hash160, hash256, sha256, Op, scriptToBytecode, } from '@cashscript/utils';
3
3
  import { Network, } from './interfaces.js';
4
4
  import { VERSION_SIZE, LOCKTIME_SIZE } from './constants.js';
@@ -102,7 +102,7 @@ export function getTxSizeWithoutInputs(outputs) {
102
102
  let size = VERSION_SIZE + LOCKTIME_SIZE;
103
103
  size += outputs.reduce((acc, output) => acc + getOutputSize(output), 0);
104
104
  // Add tx-out count (accounting for a potential change output)
105
- size += bigIntToCompactSize(BigInt(outputs.length + 1)).byteLength;
105
+ size += bigIntToCompactUint(BigInt(outputs.length + 1)).byteLength;
106
106
  return size;
107
107
  }
108
108
  // ////////// BUILD OBJECTS ///////////////////////////////////////////////////
@@ -254,14 +254,14 @@ export const randomUtxo = (defaults) => ({
254
254
  ...{
255
255
  txid: binToHex(sha256(bigIntToVmNumber(randomInt()))),
256
256
  vout: Math.floor(Math.random() * 10),
257
- satoshis: 20000n + randomInt(),
257
+ satoshis: 100000n + randomInt(),
258
258
  },
259
259
  ...defaults,
260
260
  });
261
261
  export const randomToken = (defaults) => ({
262
262
  ...{
263
263
  category: binToHex(sha256(bigIntToVmNumber(randomInt()))),
264
- amount: 10000n + randomInt(),
264
+ amount: 100000n + randomInt(),
265
265
  },
266
266
  ...defaults,
267
267
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cashscript",
3
- "version": "0.10.0-next.1",
3
+ "version": "0.10.0-next.3",
4
4
  "description": "Easily write and interact with Bitcoin Cash contracts",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -43,8 +43,8 @@
43
43
  "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
44
44
  },
45
45
  "dependencies": {
46
- "@bitauth/libauth": "^2.0.0-alpha.8",
47
- "@cashscript/utils": "^0.10.0-next.1",
46
+ "@bitauth/libauth": "^2.0.0",
47
+ "@cashscript/utils": "^0.10.0-next.3",
48
48
  "bip68": "^1.0.4",
49
49
  "bitcoin-rpc-promise-retry": "^1.3.0",
50
50
  "delay": "^5.0.0",
@@ -61,5 +61,5 @@
61
61
  "jest": "^29.4.1",
62
62
  "typescript": "^4.1.5"
63
63
  },
64
- "gitHead": "1370c6b1b1489b96964b6df4a860709cd73a06cc"
64
+ "gitHead": "1b66bdb92f972d311d968667290e96085d7fcdc7"
65
65
  }