postchain-client 0.7.4 → 0.10.0

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.
Files changed (42) hide show
  1. package/aa.js +51 -0
  2. package/bar.js +2 -0
  3. package/foo.js +6 -0
  4. package/index.js +2 -0
  5. package/package.json +1 -1
  6. package/postchain-client.js +17019 -9709
  7. package/src/gtv/index.js +10 -0
  8. package/src/{base → gtv}/merkle/binarytree.js +0 -0
  9. package/src/{base → gtv}/merkle/binarytreefactory.js +0 -0
  10. package/src/{base → gtv}/merkle/merklehashcalculator.js +3 -3
  11. package/src/{base → gtv}/merkle/path.js +0 -0
  12. package/src/{base → gtv}/merkle/proof/merklehashcarrier.js +0 -0
  13. package/src/{base → gtv}/merkle/proof/merklehashsummaryfactory.js +0 -0
  14. package/src/{base → gtv}/merkle/proof/merkleproof.js +0 -0
  15. package/src/{base → gtv}/merkle/proof/merkleprooftree.js +0 -0
  16. package/src/{base → gtv}/merkle/proof/merkleprooftreefactory.js +0 -0
  17. package/src/{gtx → gtv}/serialization.js +12 -63
  18. package/src/gtx/gtx.js +65 -28
  19. package/src/gtx/gtxclient.js +4 -4
  20. package/src/restclient.js +2 -4
  21. package/src/util.js +5 -5
  22. package/test/{base → gtv}/merkle/merklerootcalculatortest.js +1 -1
  23. package/test/{base → gtv}/merkle/treehelper.js +0 -0
  24. package/test/{base → gtv}/merkle/treeprinter.js +10 -10
  25. package/test/{base → gtv}/stringbuilder.js +0 -0
  26. package/test/gtx/checkGTXSignaturetest.js +81 -0
  27. package/test/gtx/gtxclienttest.js +95 -83
  28. package/test/gtx/serializationtest.js +26 -30
  29. package/test/merkle/hash/arraytomerkleroottest.js +2 -2
  30. package/test/merkle/hash/dicttomerkleroottest.js +2 -2
  31. package/test/merkle/hash/mixtomerkleroottest.js +2 -2
  32. package/test/merkle/merklehashcalculatordummy.js +1 -1
  33. package/test/merkle/pathtest.js +1 -1
  34. package/test/merkle/proof/arraytomerkletreeprooftest.js +7 -7
  35. package/test/merkle/proof/dicttomerkletreeprooftest.js +7 -7
  36. package/test/merkle/proof/mixtomerkletreeprooftest.js +7 -7
  37. package/test/merkle/tree/arraytobinarytest.js +6 -6
  38. package/test/merkle/tree/dicttobinarytest.js +6 -6
  39. package/test/merkle/tree/mixarraydictbinarytest.js +6 -6
  40. package/test/restclientintegrationtestmanual.js +1 -1
  41. package/test/restclienttest.js +2 -1
  42. package/test/signatures.js +4 -2
@@ -0,0 +1,10 @@
1
+ const {MerkleHashCalculator, CryptoSystem } = require("./merkle/merklehashcalculator");
2
+ const theMerkleHashCalculator = new MerkleHashCalculator(new CryptoSystem);
3
+ const merkleHashSummary = require('./merkle/proof/merkleproof').merkleHashSummary;
4
+ const serialization = require('./serialization');
5
+
6
+ exports.gtvHash = (obj) => {
7
+ return merkleHashSummary(obj, theMerkleHashCalculator).merkleHash;
8
+ };
9
+ exports.encodeGtv = serialization.encodeValue;
10
+ exports.decodeGtv = serialization.decodeValue;
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- var serialization = require('../../gtx/serialization')
1
+ var serialization = require('../serialization')
2
2
  var HASH_PREFIX_LEAF = require('./binarytree').HASH_PREFIX_LEAF
3
3
  var util = require('../../util')
4
4
 
@@ -41,7 +41,7 @@ MerkleHashCalculator.prototype.calculateNodeHash = function(prefix, hashLeft, ha
41
41
  * @param {*} value
42
42
  */
43
43
  MerkleHashCalculator.prototype.calculateLeafHash = function(value) {
44
- return this.calculateHashOfValueInternal(value, serialization.encode, hashingFun)
44
+ return this.calculateHashOfValueInternal(value, serialization.encodeValue, hashingFun)
45
45
  }
46
46
 
47
47
  /**
@@ -74,4 +74,4 @@ MerkleHashCalculator.prototype.isContainerProofValueLeaf = function(value) {
74
74
  }
75
75
  }
76
76
 
77
- module.exports = {MerkleHashCalculator}
77
+ module.exports = {MerkleHashCalculator, CryptoSystem};
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- var asn = require('asn1.js');
1
+ var asn = require('asn1.js/lib/asn1');
2
2
 
3
3
  var ASNDictPair = asn.define('DictPair', function () {
4
4
  this.seq().obj(
@@ -18,26 +18,10 @@ var ASNGTXValue = asn.define('GtxValue', function () {
18
18
  });
19
19
  });
20
20
 
21
- var ASNGTXOperation = asn.define('GtxOperation', function () {
22
- this.seq().obj(
23
- this.key('opName').utf8str(),
24
- this.key('args').seqof(ASNGTXValue)
25
- )
26
- })
27
-
28
-
29
21
  var ASNBuffer = asn.define('Buffer', function() {
30
22
  this.octstr();
31
23
  });
32
24
 
33
- var ASNGTXTransaction = asn.define('GtxTransaction', function () {
34
- this.seq().obj(
35
- this.key('blockchainRID').octstr(),
36
- this.key('operations').seqof(ASNGTXOperation),
37
- this.key('signers').seqof(ASNBuffer),
38
- this.key('signatures').seqof(ASNBuffer)
39
- )
40
- })
41
25
  /*
42
26
  Messages DEFINITIONS ::= BEGIN
43
27
 
@@ -54,58 +38,23 @@ GTXValue ::= CHOICE {
54
38
  dict [4] SEQUENCE OF DictPair,
55
39
  array [5] SEQUENCE OF GTXValue
56
40
  }
57
-
58
- GTXOperation ::= SEQUENCE {
59
- opName UTF8String,
60
- args SEQUENCE OF GTXValue
61
- }
62
-
63
- GTXTransaction ::= SEQUENCE {
64
- blockchainID OCTET STRING,
65
- operations SEQUENCE OF GTXOperation,
66
- signers SEQUENCE OF OCTET STRING,
67
- signatures SEQUENCE OF OCTET STRING
68
- }
69
-
70
41
  END
71
42
  */
72
- /**
73
- * @param bytes the raw client message
74
- * @returns {calls: [{functionName: <funcName>, args: [arg1, arg2, ...]}, ...],
75
- * signatures: [{pubKey: <buffer>, signature: <buffer>}]}
76
- */
77
- module.exports.decode = (bytes) => {
78
- var rawObject = ASNGTXTransaction.decode(bytes);
79
- rawObject.operations.forEach(operation => {
80
- operation.args = operation.args.map(arg => parseValue(arg));
81
- });
82
- return rawObject;
83
- };
84
43
 
85
- module.exports.encode = (opsAndSigs) => {
86
- var preparedOps = opsAndSigs.operations.map((op) => {
87
- return {opName: op.opName,
88
- args: op.args.map((arg) => createTypedArg(arg))}
89
- });
90
- var toEncode = {blockchainRID: opsAndSigs.blockchainRID, operations: preparedOps,
91
- signers: opsAndSigs.signers, signatures: opsAndSigs.signatures}
92
- if (toEncode.signatures == null) {
93
- // use empty signatures
94
- toEncode.signatures = opsAndSigs.signers.map(function () { return Buffer.alloc(0); })
95
- }
96
- return ASNGTXTransaction.encode(toEncode);
97
- };
44
+ function encodeValue (arg) {
45
+ return ASNGTXValue.encode(createTypedArg(arg));
46
+ }
98
47
 
99
- module.exports.encodeValue = (arg) => {
100
- return ASNGTXValue.encode(createTypedArg(arg))
101
- };
48
+ exports.encodeValue = encodeValue;
102
49
 
103
- module.exports.decodeValue = (bytes) => {
50
+ function decodeValue (bytes) {
104
51
  const obj = ASNGTXValue.decode(bytes);
105
52
  return parseValue(obj);
106
- };
53
+ }
54
+
55
+ exports.decodeValue = decodeValue;
107
56
 
108
- var BN = require('bn.js')
57
+ var BN = require('bn.js');
109
58
  function parseValue(typedArg) {
110
59
  // console.log("Typedarg:", typedArg);
111
60
  if (typedArg.type === 'null') {
@@ -124,10 +73,10 @@ function parseValue(typedArg) {
124
73
  return typedArg.value.map(item => parseValue(item));
125
74
  }
126
75
  if (typedArg.type === 'dict') {
127
- var result = {}
76
+ var result = {};
128
77
  typedArg.value.forEach(function (pair) {
129
78
  result[pair.name] = parseValue(pair.value);
130
- })
79
+ });
131
80
  return result
132
81
  }
133
82
  throw new Error(`Cannot parse typedArg ${typedArg}. Unknown type ${typedArg.type}`);
package/src/gtx/gtx.js CHANGED
@@ -1,9 +1,10 @@
1
- var serialization = require('./serialization');
2
- var util = require('../util');
3
1
 
4
- module.exports.emptyGtx = function (blockchainRID) {
2
+ const util = require('../util');
3
+ const gtv = require("../gtv");
4
+
5
+ exports.emptyGtx = function (blockchainRID) {
5
6
  return {blockchainRID: blockchainRID, operations: [], signers: []};
6
- }
7
+ };
7
8
 
8
9
  /**
9
10
  * Adds a function call to a GTX. Creates a new GTX if none specified.
@@ -14,7 +15,7 @@ module.exports.emptyGtx = function (blockchainRID) {
14
15
  * @returns the gtx
15
16
  * @throws if gtx is null or if gtx is already signed
16
17
  */
17
- module.exports.addTransactionToGtx = function (opName, args, gtx) {
18
+ exports.addTransactionToGtx = function (opName, args, gtx) {
18
19
  if (gtx == null) {
19
20
  throw new Error("No Gtx to add operation to")
20
21
  }
@@ -25,50 +26,59 @@ module.exports.addTransactionToGtx = function (opName, args, gtx) {
25
26
  return gtx;
26
27
  }
27
28
 
28
- module.exports.addSignerToGtx = function (signer, gtx) {
29
+ exports.addSignerToGtx = function (signer, gtx) {
29
30
  if (gtx.signatures) {
30
31
  throw new Error("Cannot add signers to an already signed gtx");
31
32
  }
32
33
  gtx.signers.push(signer);
33
- }
34
+ };
34
35
 
35
36
  /**
36
37
  * Serializes the gtx for signing
37
38
  * @param gtx the gtx to serialize
38
39
  */
39
- module.exports.getBufferToSign = function (gtx) {
40
- // console.log("Buffer to sign: " + JSON.stringify({calls: gtx.calls, signers: gtx.signers}));
40
+ exports.getDigestToSign = function (gtx) {
41
+ return gtv.gtvHash(gtvTxBody(gtx));
42
+ };
41
43
 
42
- return serialization.encode({blockchainRID: gtx.blockchainRID, operations: gtx.operations,
43
- signers: gtx.signers, signatures: []});
44
+ function gtvTxBody(txData) {
45
+ return [
46
+ txData.blockchainRID,
47
+ txData.operations.map(
48
+ (op) => [op.opName, op.args]
49
+ ),
50
+ txData.signers
51
+ ];
44
52
  }
45
53
 
46
54
  /**
47
55
  * Signs the gtx with the provided privKey. This is a convenience function
48
56
  * for situations where you don't have to ask someone else to sign.
49
57
  */
50
- module.exports.sign = function(privKey, pubKey, gtx) {
51
- var bufferToSign = module.exports.getBufferToSign(gtx);
52
- var signature = util.sign(bufferToSign, privKey);
58
+ exports.sign = function (privKey, pubKey, gtx) {
59
+ var digestToSign = module.exports.getDigestToSign(gtx);
60
+ var signature = util.signDigest(digestToSign, privKey);
53
61
  console.log("PubKey: " + pubKey.toString('hex'));
54
62
  console.log("Signature: " + signature.toString('hex'));
55
63
  module.exports.addSignature(pubKey, signature, gtx);
56
- }
64
+ };
57
65
 
58
- module.exports.signRawTransaction = function(keyPair, rawTransaction) {
66
+ exports.signRawTransaction = function (keyPair, rawTransaction) {
67
+ throw Error("TODO");
68
+ //TODO
59
69
  const gtx = module.exports.deserialize(rawTransaction);
60
70
  module.exports.sign(keyPair.privKey, keyPair.pubKey, gtx);
61
71
  return module.exports.serialize(gtx)
62
- }
72
+ };
63
73
 
64
74
  /**
65
75
  * Adds a signature to the gtx
66
76
  */
67
- module.exports.addSignature = function(pubKeyBuffer, signatureBuffer, gtx) {
77
+ exports.addSignature = function (pubKeyBuffer, signatureBuffer, gtx) {
68
78
  if (!gtx.signatures) {
69
79
  gtx.signatures = Array(gtx.signers.length).fill(Buffer.alloc(0));
70
80
  }
71
- if (gtx.signers.length != gtx.signatures.length) {
81
+ if (gtx.signers.length !== gtx.signatures.length) {
72
82
  throw new Error("Mismatching signers and signatures");
73
83
  }
74
84
  var signerIndex = gtx.signers.findIndex((signer) => pubKeyBuffer.equals(signer));
@@ -76,20 +86,47 @@ module.exports.addSignature = function(pubKeyBuffer, signatureBuffer, gtx) {
76
86
  throw new Error("No such signer, remember to call addSignerToGtx() before adding a signature");
77
87
  }
78
88
  gtx.signatures[signerIndex] = signatureBuffer;
79
- }
89
+ };
80
90
 
81
- module.exports.serialize = function(gtx) {
91
+ exports.serialize = function (gtx) {
82
92
  if (!gtx.signatures) {
93
+ // TODO
83
94
  // The gtx is not signed, but we must include
84
95
  // the signatures attribute, so let's add that.
85
96
  gtx.signatures = [];
86
97
  }
87
- return serialization.encode(gtx);
88
- }
98
+ return gtv.encodeGtv([
99
+ gtvTxBody(gtx),
100
+ gtx.signatures
101
+ ]);
102
+ };
103
+
104
+ exports.deserialize = function (gtxBytes) {
105
+ const deserializedTx = gtv.decodeGtv(gtxBytes);
106
+ const body = deserializedTx[0];
107
+ const gtvTxBody = {
108
+ blockchainRID: body[0],
109
+ operations: body[1].map(operation => ({opName: operation[0], args: operation[1]})),
110
+ signers: body[2]
111
+ };
112
+ const signatures = deserializedTx[1];
113
+
114
+ return {
115
+ ...gtvTxBody,
116
+ signatures
117
+ }
118
+ };
119
+
120
+ exports.checkGTXSignatures = function(txHash, gtx) {
121
+ if(gtx.signatures.length < gtx.signers.length) throw Error("Not enough signatures");
122
+ for(const i in gtx.signers) {
123
+ const signValid = util.checkDigestSignature(txHash, gtx.signers[i], gtx.signatures[i]);
124
+ if(!signValid) return signValid;
125
+ }
126
+ return true;
127
+ };
89
128
 
90
- module.exports.deserialize = function(gtxBytes) {
91
- return serialization.decode(gtxBytes);
92
- }
93
129
 
94
- module.exports.encodeValue = serialization.encodeValue;
95
- module.exports.decodeValue = serialization.decodeValue;
130
+ // DEPRECATED
131
+ exports.encodeValue = gtv.encodeGtv;
132
+ exports.decodeValue = gtv.decodeGtv;
@@ -3,7 +3,7 @@ var gtxTool = require('./gtx');
3
3
  var secp256k1 = require('secp256k1');
4
4
  var util = require('../util');
5
5
 
6
- module.exports.createClient = function (restApiClient, blockchainRID, functionNames) {
6
+ exports.createClient = function (restApiClient, blockchainRID, functionNames) {
7
7
  functionNames.push('message');
8
8
 
9
9
  function transaction(gtx) {
@@ -19,11 +19,11 @@ module.exports.createClient = function (restApiClient, blockchainRID, functionNa
19
19
  },
20
20
 
21
21
  getTxRID: function () {
22
- return util.sha256(this.getBufferToSign());
22
+ return this.getDigestToSign();
23
23
  },
24
24
 
25
- getBufferToSign: function () {
26
- return gtxTool.getBufferToSign(this.gtx);
25
+ getDigestToSign: function () {
26
+ return gtxTool.getDigestToSign(this.gtx);
27
27
  },
28
28
 
29
29
  addSignature: function (pubKey, signature) {
package/src/restclient.js CHANGED
@@ -3,9 +3,7 @@
3
3
  var url = require('url');
4
4
  var rq = require('request');
5
5
 
6
- var separateReqPool = {maxSockets: 100};
7
-
8
- module.exports.createRestClient = function (urlBase, blockchainRID, maxSockets) {
6
+ exports.createRestClient = function (urlBase, blockchainRID, maxSockets) {
9
7
  return {
10
8
  config: {urlBase: urlBase, pool: {maxSockets: maxSockets ? maxSockets : 10}},
11
9
 
@@ -19,7 +17,7 @@ module.exports.createRestClient = function (urlBase, blockchainRID, maxSockets)
19
17
  * the callback will be called with (null, null).
20
18
  */
21
19
  getTransaction: function (messageHash, callback) {
22
- validateMessageHash(messageHash)
20
+ validateMessageHash(messageHash);
23
21
  get(this.config, 'tx/' + blockchainRID + '/' + messageHash.toString('hex'), (error, statusCode, responseObject) => {
24
22
  handleGetResponse(error, statusCode, statusCode === 200 ? Buffer.from(responseObject.tx, 'hex') : null, callback);
25
23
  });
package/src/util.js CHANGED
@@ -24,7 +24,7 @@ module.exports = {
24
24
  };
25
25
 
26
26
  function createPublicKey(privateKey) {
27
- if (!Buffer.isBuffer(privateKey) || privateKey.length != 32) {
27
+ if (!Buffer.isBuffer(privateKey) || privateKey.length !== 32) {
28
28
  throw "privateKey must be a Buffer of 32 bytes"
29
29
  }
30
30
  return secp256k1.publicKeyCreate(privateKey, true);
@@ -164,7 +164,7 @@ function validateMerklePath(path, target, merkleRoot) {
164
164
  for (let i = 0; i < path.length; i++) {
165
165
  const item = path[i];
166
166
 
167
- const prefix = (i == 0) ? Buffer.from([1]) : Buffer.from([0]);
167
+ const prefix = (i === 0) ? Buffer.from([1]) : Buffer.from([0]);
168
168
 
169
169
  if (item.side === 0) {
170
170
  currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
@@ -215,7 +215,7 @@ function sign(content, privKey) {
215
215
  if (!privKey) {
216
216
  throw new Error("Programmer error, missing privKey");
217
217
  }
218
- if (privKey.length != 32) {
218
+ if (privKey.length !== 32) {
219
219
  throw new Error(`Programmer error. Invalid key length. Expected 32, but got ${privKey.length}`);
220
220
  }
221
221
  var digestBuffer = sha256(content);
@@ -244,8 +244,8 @@ function makeKeyPair() {
244
244
  let privKey;
245
245
  do {
246
246
  privKey = crypto.randomBytes(32)
247
- } while (!secp256k1.privateKeyVerify(privKey))
248
- const pubKey = secp256k1.publicKeyCreate(privKey)
247
+ } while (!secp256k1.privateKeyVerify(privKey));
248
+ const pubKey = secp256k1.publicKeyCreate(privKey);
249
249
  return {pubKey, privKey}
250
250
  }
251
251
 
@@ -1,5 +1,5 @@
1
1
  var assert = require('chai').assert;
2
- var merkleHash = require('../../../src/base/merkle/proof/merkleproof').merkleHash
2
+ var merkleHash = require('../../../src/gtv/merkle/proof/merkleproof').merkleHash
3
3
  var TreeHelper = require('./treehelper').TreeHelper
4
4
  var MerkleHashCalculatorDummy = require('../../merkle/merklehashcalculatordummy').MerkleHashCalculatorDummy
5
5
  var calculator = new MerkleHashCalculatorDummy()
File without changes
@@ -1,14 +1,14 @@
1
1
  var StringBuilder = require('../stringbuilder').StringBuilder
2
- var BinaryTreeElement = require('../../../src/base/merkle/binarytree').BinaryTreeElement
3
- var BinaryTree = require('../../../src/base/merkle/binarytree').BinaryTree
4
- var EmptyLeaf = require('../../../src/base/merkle/binarytree').EmptyLeaf
5
- var Leaf = require('../../../src/base/merkle/binarytree').Leaf
6
- var Node = require('../../../src/base/merkle/binarytree').Node
7
- var ProofNode = require('../../../src/base/merkle/proof/merkleprooftree').ProofNode
8
- var ProofValueLeaf = require('../../../src/base/merkle/proof/merkleprooftree').ProofValueLeaf
9
- var ProofHashedLeaf = require('../../../src/base/merkle/proof/merkleprooftree').ProofHashedLeaf
10
- var ProofNodeArrayHead = require('../../../src/base/merkle/proof/merkleprooftree').ProofNodeArrayHead
11
- var ProofNodeDictHead = require('../../../src/base/merkle/proof/merkleprooftree').ProofNodeDictHead
2
+ var BinaryTreeElement = require('../../../src/gtv/merkle/binarytree').BinaryTreeElement
3
+ var BinaryTree = require('../../../src/gtv/merkle/binarytree').BinaryTree
4
+ var EmptyLeaf = require('../../../src/gtv/merkle/binarytree').EmptyLeaf
5
+ var Leaf = require('../../../src/gtv/merkle/binarytree').Leaf
6
+ var Node = require('../../../src/gtv/merkle/binarytree').Node
7
+ var ProofNode = require('../../../src/gtv/merkle/proof/merkleprooftree').ProofNode
8
+ var ProofValueLeaf = require('../../../src/gtv/merkle/proof/merkleprooftree').ProofValueLeaf
9
+ var ProofHashedLeaf = require('../../../src/gtv/merkle/proof/merkleprooftree').ProofHashedLeaf
10
+ var ProofNodeArrayHead = require('../../../src/gtv/merkle/proof/merkleprooftree').ProofNodeArrayHead
11
+ var ProofNodeDictHead = require('../../../src/gtv/merkle/proof/merkleprooftree').ProofNodeDictHead
12
12
  var TreeHelper = require('./treehelper').TreeHelper
13
13
  var helper = new TreeHelper()
14
14
 
File without changes
@@ -0,0 +1,81 @@
1
+ const gtv = require("../../src/gtv");
2
+
3
+ const assert = require('chai').assert;
4
+ const expect = require('chai').expect;
5
+ const gtxU = require('../../src/gtx/gtx');
6
+
7
+ var sigs = require('../signatures');
8
+ var sig = sigs.sig;
9
+ var signatures = sigs.signatures;
10
+ var signers = sigs.signers;
11
+ const blockchainRID = Buffer.from("DEADBEEF94");
12
+
13
+ describe("check gtx signature", () => {
14
+ function test(txHash, gtx) {
15
+ console.log("GTX", gtx);
16
+ const checkResult = gtxU.checkGTXSignatures(txHash, gtx);
17
+ console.log("RESULT", checkResult);
18
+ assert.deepEqual(checkResult, true);
19
+ }
20
+
21
+ function testFail(txHash, gtx) {
22
+ const checkResult = gtxU.checkGTXSignatures(txHash, gtx);
23
+ assert.deepEqual(checkResult, false)
24
+ }
25
+
26
+ function tx(calls, signers, signaturesCount) {
27
+ const tx = {blockchainRID, operations: calls, signers};
28
+ console.log("THE TX", tx);
29
+ for(let i=0; i<signaturesCount; i++) {
30
+ const signer = sig(i);
31
+ gtxU.sign(signer.privKey, signer.pubKey, tx);
32
+ }
33
+
34
+ if(!tx.signatures) tx.signatures = [];
35
+ return tx;
36
+ }
37
+
38
+ it('empty call should be ok', () => {
39
+ const aTx = tx( [], [], 0);
40
+ const txHash = gtxU.getDigestToSign(aTx);
41
+ test(txHash, aTx);
42
+ });
43
+
44
+ it('empty call with one signature', () => {
45
+ const aTx = tx( [], [], signatures(1));
46
+ const txHash = gtxU.getDigestToSign(aTx);
47
+ test(txHash, aTx);
48
+ });
49
+
50
+ it('single call with no param, one signature and no signers', () => {
51
+ const aTx = tx([{opName: 'func1åäö', args: []}], [], 0);
52
+ const txHash = gtxU.getDigestToSign(aTx);
53
+ test(txHash, aTx);
54
+ });
55
+
56
+ it('single call with not enough signatures FAILS', () => {
57
+ const aTx = tx([{opName: 'func1åäö', args: []}], signers(2), 1);
58
+ const txHash = gtxU.getDigestToSign(aTx);
59
+ const checkResult = () => gtxU.checkGTXSignatures(txHash, aTx);
60
+ expect(checkResult).to.throw();
61
+ });
62
+
63
+ it('single call with enough signatueres works', () => {
64
+ const aTx = tx([{opName: 'func1åääö', args: []}], signers(1), 1);
65
+ const txHash = gtxU.getDigestToSign(aTx);
66
+ test(txHash, aTx);
67
+ });
68
+
69
+ it('single call with enough multiple signatures work', () => {
70
+ const aTx = tx([{opName: 'func1åääö', args: []}], signers(2), 2);
71
+ const txHash = gtxU.getDigestToSign(aTx);
72
+ test(txHash, aTx)
73
+ });
74
+
75
+ it('multiple calls with enought multiple signatures work', () => {
76
+ const aTx = tx([{opName: 'func1åääö', args: []}, {opName: 'guess_the_function', args: ['John Doe', 2222]}], signers(3), 3);
77
+ const txHash = gtxU.getDigestToSign(aTx);
78
+ test(txHash, aTx)
79
+ });
80
+ });
81
+