|
2 | 2 | // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
3 | 3 | // Code is Apache-2.0 and docs are CC-BY-4.0
|
4 | 4 |
|
5 |
| -import test from 'ava' |
6 | 5 | import base58 from 'bs58'
|
| 6 | +import { createHash } from 'crypto' |
7 | 7 | import { Ed25519Sha256 } from 'crypto-conditions'
|
8 | 8 | import { Transaction, Ed25519Keypair } from '../src'
|
9 | 9 | // TODO: Find out if ava has something like conftest, if so put this there.
|
@@ -34,20 +34,19 @@ export const bobCondition = Transaction.makeEd25519Condition(bob.publicKey)
|
34 | 34 | export const bobOutput = Transaction.makeOutput(bobCondition)
|
35 | 35 |
|
36 | 36 | export function delegatedSignTransaction(...keyPairs) {
|
37 |
| - return function sign(input, transactionHash) { |
| 37 | + return function sign(serializedTransaction, input, index) { |
| 38 | + const transactionUniqueFulfillment = input.fulfills ? serializedTransaction |
| 39 | + .concat(input.fulfills.transaction_id) |
| 40 | + .concat(input.fulfills.output_index) : serializedTransaction |
| 41 | + const transactionHash = createHash('sha3-256').update(transactionUniqueFulfillment).digest() |
38 | 42 | const filteredKeyPairs = keyPairs.filter(({ publicKey }) =>
|
39 | 43 | input.owners_before.includes(publicKey))
|
| 44 | + |
40 | 45 | const ed25519Fulfillment = new Ed25519Sha256()
|
41 | 46 | filteredKeyPairs.forEach(keyPair => {
|
42 | 47 | const privateKey = Buffer.from(base58.decode(keyPair.privateKey))
|
43 |
| - ed25519Fulfillment.sign( |
44 |
| - Buffer.from(transactionHash, 'hex'), |
45 |
| - privateKey |
46 |
| - ) |
| 48 | + ed25519Fulfillment.sign(transactionHash, privateKey) |
47 | 49 | })
|
48 | 50 | return ed25519Fulfillment.serializeUri()
|
49 | 51 | }
|
50 | 52 | }
|
51 |
| - |
52 |
| -// TODO: https://github.com/avajs/ava/issues/1190 |
53 |
| -test('', () => 'dirty hack. TODO: Exclude this file from being run by ava') |
0 commit comments