-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,740 additions
and
1,394 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
set -e | ||
symbol-bootstrap enrollRewardProgram -t target/testnet-supernode --useKnownRestGateways --password 1111 $1 $2 $3 | ||
symbol-bootstrap enrollRewardProgram -t target/testnet-supernode --maxFee 1000000 --useKnownRestGateways --password 1111 $1 $2 $3 |
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 2021 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { LedgerNetworkType, SymbolLedger } from 'symbol-ledger-typescript/lib'; | ||
import { Account, Address, AggregateTransaction, Convert, KeyPair, NetworkType, SignedTransaction, Transaction, UInt64 } from 'symbol-sdk'; | ||
import { LogType } from '../logger'; | ||
import Logger from '../logger/Logger'; | ||
import LoggerFactory from '../logger/LoggerFactory'; | ||
|
||
const logger: Logger = LoggerFactory.getLogger(LogType.System); | ||
|
||
/** | ||
* An account that knows how to asynchronously sign and co-sign transactions | ||
*/ | ||
export interface SigningAccount { | ||
readonly publicKey: string; | ||
readonly address: Address; | ||
cosignTransaction(transaction: Transaction, transactionHash: string): Promise<string>; | ||
signTransaction(transaction: Transaction, generationHash: string): Promise<SignedTransaction>; | ||
} | ||
|
||
/** | ||
* Basic signing account that adapts the sdk's account. | ||
*/ | ||
export class PrivateKeyAccount implements SigningAccount { | ||
public readonly address: Address; | ||
public readonly publicKey: string; | ||
constructor(private readonly account: Account) { | ||
this.address = account.address; | ||
this.publicKey = account.publicAccount.publicKey; | ||
} | ||
|
||
async cosignTransaction(transaction: Transaction, transactionHash: string): Promise<string> { | ||
const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(this.account.privateKey); | ||
return Convert.uint8ToHex(KeyPair.sign(keyPairEncoded, Convert.hexToUint8(transactionHash))); | ||
} | ||
|
||
async signTransaction(transaction: Transaction, generationHash: string): Promise<SignedTransaction> { | ||
return this.account.sign(transaction, generationHash); | ||
} | ||
} | ||
|
||
/** | ||
* Ledger account that can sign by connecting to the device. | ||
*/ | ||
export class LedgerAccount implements SigningAccount { | ||
public readonly address: Address; | ||
|
||
constructor( | ||
private readonly ledger: SymbolLedger, | ||
networkType: LedgerNetworkType, | ||
private readonly path: string, | ||
public readonly publicKey: string, | ||
private readonly isOptinSymbolWallet: boolean, | ||
) { | ||
this.address = Address.createFromPublicKey(publicKey, networkType as number as NetworkType); | ||
} | ||
|
||
async cosignTransaction(transaction: Transaction, transactionHash: string): Promise<string> { | ||
logger.info(`Co-signing transaction ${transactionHash} with Ledger account ${this.address.plain()}. Check your device!`); | ||
return await this.ledger.signCosignatureTransaction( | ||
this.path, | ||
transaction, | ||
transactionHash, | ||
this.publicKey, | ||
this.isOptinSymbolWallet, | ||
); | ||
} | ||
|
||
async signTransaction(transaction: Transaction, generationHash: string): Promise<SignedTransaction> { | ||
logger.info(`Signing transaction with Ledger account ${this.address.plain()}. Check your device!`); | ||
const { payload } = await this.ledger.signTransaction(this.path, transaction, generationHash, this.publicKey, false); | ||
const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); | ||
return new SignedTransaction( | ||
payload, | ||
Transaction.createTransactionHash(payload, generationHashBytes), | ||
this.publicKey, | ||
transaction.type, | ||
transaction.networkType, | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Utility object to sign transactions asynchronously | ||
*/ | ||
export class SigningUtils { | ||
public static async signTransactionWithCosignatories( | ||
initiatorAccount: SigningAccount, | ||
transaction: AggregateTransaction, | ||
cosignatories: SigningAccount[], | ||
generationHash: string, | ||
): Promise<SignedTransaction> { | ||
const signedTransaction = await initiatorAccount.signTransaction(transaction, generationHash); | ||
let signedPayload = signedTransaction.payload; | ||
for (const cosigner of cosignatories) { | ||
const signature = await cosigner.cosignTransaction(transaction, signedTransaction.hash); | ||
Convert.validateHexString(signature, 128, 'Cosignature is not valid hex!'); | ||
signedPayload += UInt64.fromUint(0).toHex() + cosigner.publicKey + signature; | ||
} | ||
// Calculate new size | ||
const size = `00000000${(signedPayload.length / 2).toString(16)}`; | ||
const formatedSize = size.substr(size.length - 8, size.length); | ||
const littleEndianSize = | ||
formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); | ||
signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); | ||
return new SignedTransaction( | ||
signedPayload, | ||
signedTransaction.hash, | ||
initiatorAccount.publicKey, | ||
transaction.type, | ||
transaction.networkType, | ||
); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
#privateKeySecurityMode: PROMPT_MAIN | ||
nodeUseRemoteAccount: false | ||
nodeUseRemoteAccount: true | ||
logLevel: 'Debug' | ||
nodes: | ||
- voting: false | ||
- voting: true | ||
rewardProgram: 'supernode' | ||
host: fboucquez-agent-symbollocal.ngrok.io | ||
agentUrl: https://fboucquez-agent-symbollocal.ngrok.io | ||
restGatewayUrl: http://fboucquez-rest-gateway-symbollocal.ngrok.io | ||
mainPrivateKey: E095162875BB1D98CA5E0941670E01C1B0DBDF86DF7B3BEDA4A93635F8E51A03 | ||
transportPrivateKey: 415F253ABF0FB2DFD39D7F409EFA2E88769873CAEB45617313B98657A1476A15 | ||
remotePrivateKey: 24B485712045FEDA5782ECFF1752F63D41C134371BB46AC68EE6DC9183CF5061 | ||
vrfPrivateKey: D34A231C860EB1B6E3A4F8366C8F0F6C7C2462A40263DCB67124FB76CDD4E368 | ||
agentPrivateKey: AAAA231C860EB1B6E3A4F8366C8F0F6C7C2462A40263DCB67124FB76CDD4E368 | ||
host: my-supernode | ||
mainPrivateKey: CA82E7ADAF7AB729A5462A1BD5AA78632390634904A64EB1BB22295E2E1A1BDD | ||
transportPrivateKey: A15F253ABF0FB2DFD39D7F409EFA2E88769873CAEB45617313B98657A1476A15 | ||
remotePrivateKey: B4B485712045FEDA5782ECFF1752F63D41C134371BB46AC68EE6DC9183CF5061 | ||
vrfPrivateKey: C34A231C860EB1B6E3A4F8366C8F0F6C7C2462A40263DCB67124FB76CDD4E368 | ||
agentPrivateKey: DAAA231C860EB1B6E3A4F8366C8F0F6C7C2462A40263DCB67124FB76CDD4E368 |