Last active
February 10, 2019 06:11
-
-
Save planethouki/fe4dbc67cae0a5d907b8214a2340a133 to your computer and use it in GitHub Desktop.
nem catapult バイトレベルで理解する その4 Cosignature Transaction ref: https://qiita.com/planethouki/items/fcac3c9d329b0278c4b7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @internal | |
* Serialize and sign transaction creating a new SignedTransaction | |
* @param account | |
* @returns {CosignatureSignedTransaction} | |
*/ | |
public signWith(account: Account): CosignatureSignedTransaction { | |
const aggregateSignatureTransaction = new CosignaturetransactionLibrary(this.transactionToCosign.transactionInfo!.hash); | |
const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account); | |
return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, | |
signedTransactionRaw.signature, | |
signedTransactionRaw.signer); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X PUT -H 'Content-Type:application/json' -d '{ "parentHash": "222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A", "signature": "B3641A69BEC08631036B984A6206503EE928DDD3902D083D9C28030B88FD36D40EC397ACB0FFEADCC03225CF9288F08D50F5D1B506FBB0C0A47B469A3C4B4E0C", "signer": "543BB01DFEEA0D9A25ADDE515DACC72F2125A8AAE85EDD682D77251E2C4EC174" }' http://localhost:3000/transaction/cosignature | |
{"message":"packet 501 was pushed to the network via /transaction/cosignature"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl http://localhost:3000/transaction/222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A/status | |
{"group":"confirmed","status":"Success","hash":"222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A","deadline":[1650699429,16],"height":[161822,0]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node aggregate.js | |
lockFundsTransactionSigned.hash : 4FA5CF0063BE9577F0A39DB0D69B99404108021C1D6E5EE44A9F686922019546 | |
lockFundsTransactionSigned.signer: 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C | |
aggregateTransactionSigned.hash : 222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A | |
aggregateTransactionSigned.signer: 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C | |
TransactionAnnounceResponse { | |
message: 'packet 9 was pushed to the network via /transaction' } | |
TransactionAnnounceResponse { | |
message: 'packet 500 was pushed to the network via /transaction/partial' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# node sign.js | |
publicKey: 543BB01DFEEA0D9A25ADDE515DACC72F2125A8AAE85EDD682D77251E2C4EC174 | |
signature: B3641A69BEC08631036B984A6206503EE928DDD3902D083D9C28030B88FD36D40EC397ACB0FFEADCC03225CF9288F08D50F5D1B506FBB0C0A47B469A3C4B4E0C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "parentHash": "222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A", | |
"signature": "B3641A69BEC08631036B984A6206503EE928DDD3902D083D9C28030B88FD36D40EC397ACB0FFEADCC03225CF9288F08D50F5D1B506FBB0C0A47B469A3C4B4E0C", | |
"signer": "543BB01DFEEA0D9A25ADDE515DACC72F2125A8AAE85EDD682D77251E2C4EC174" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nem2lib = require("nem2-library"); | |
const signData = `222C1C99033BC372A655042C311CA5251279AD47907A6E2804DDAB606851CB3A`; | |
const privateKey = 'B332E3CA7B31D0BC663232B66D7C282BC2FE1DC0C01BB0159586A2CBEADD6B2A'; | |
const keypair = nem2lib.KeyPair.createKeyPairFromPrivateKeyString(privateKey); | |
const signature = nem2lib.KeyPair.sign(keypair, signData); | |
console.log('publicKey: ' + nem2lib.convert.uint8ToHex(keypair.publicKey)); | |
console.log('signature: ' + nem2lib.convert.uint8ToHex(signature)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Send a cosignature signed transaction of an already announced transaction | |
* @param cosignatureSignedTransaction - Cosignature signed transaction | |
* @returns Observable<TransactionAnnounceResponse> | |
*/ | |
public announceAggregateBondedCosignature( | |
cosignatureSignedTransaction: CosignatureSignedTransaction): Observable<TransactionAnnounceResponse> { | |
return Observable.fromPromise(this.transactionRoutesApi.announceCosignatureTransaction(cosignatureSignedTransaction)) | |
.map((transactionAnnounceResponseDTO) => { | |
return new TransactionAnnounceResponse(transactionAnnounceResponseDTO.message); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates cosignature transaction | |
* Announce a cosignature transaction to the network | |
* @param {module:model/TransactionPayload} payload Transaction payload | |
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link Object} and HTTP response | |
*/ | |
announceCosignatureTransactionWithHttpInfo(payload) { | |
let postBody = payload; | |
// verify the required parameter 'payload' is set | |
if (payload === undefined || payload === null) { | |
throw new Error("Missing the required parameter 'payload' when calling announceCosignatureTransaction"); | |
} | |
let pathParams = {}; | |
let queryParams = {}; | |
let headerParams = {}; | |
let formParams = {}; | |
let authNames = []; | |
let contentTypes = []; | |
let accepts = ['application/json']; | |
let returnType = Object; | |
return this.apiClient.callApi( | |
'/transaction/cosignature', 'PUT', | |
pathParams, queryParams, headerParams, formParams, postBody, | |
authNames, contentTypes, accepts, returnType | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {KeyPair} keyPair KeyPair instance | |
* @returns {module:model/TransactionPayload} Returns TransactionPayload instance | |
*/ | |
signCosignatoriesTransaction(keyPair) { | |
const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes)); | |
return { | |
parentHash: convert.uint8ToHex(this.bytes), | |
signature: convert.uint8ToHex(signature), | |
signer: keyPair.publicKey | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment