-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added signing options with extra signers to the transaction fin…
…alize method
- Loading branch information
1 parent
61ae63f
commit 514b718
Showing
20 changed files
with
288 additions
and
114 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
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
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
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
48 changes: 48 additions & 0 deletions
48
packages/wallet/src/KeyManagement/util/KeyAgentTransactionSigner.ts
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,48 @@ | ||
import { AccountKeyDerivationPath, KeyAgent, TransactionSigner, TransactionSignerResult } from '../types'; | ||
import { Cardano } from '@cardano-sdk/core'; | ||
import { ProofGenerationError } from '../errors'; | ||
import { TxInternals } from '../../Transaction'; | ||
|
||
const EXPECTED_SIG_NUM = 1; | ||
|
||
/** | ||
* Generates a Ed25519Signature of a transaction using a key agent. | ||
*/ | ||
export class KeyAgentTransactionSigner implements TransactionSigner { | ||
#keyAgent: KeyAgent; | ||
#account: AccountKeyDerivationPath; | ||
|
||
/** | ||
* Initializes a new instance of the KeyAgentTransactionSigner class. | ||
* | ||
* @param keyAgent The key agent that will produce the signature. | ||
* @param account The account derivation path of the key to be used to generate the signature. | ||
* @class | ||
*/ | ||
constructor(keyAgent: KeyAgent, account: AccountKeyDerivationPath) { | ||
this.#keyAgent = keyAgent; | ||
this.#account = account; | ||
} | ||
|
||
/** | ||
* Sings a transaction. | ||
* | ||
* @param tx The transaction to be signed. | ||
* @returns A Ed25519 transaction signature. | ||
*/ | ||
async sign(tx: TxInternals): Promise<TransactionSignerResult> { | ||
const signatures: Cardano.Signatures = await this.#keyAgent.signTransaction(tx, { | ||
additionalKeyPaths: [this.#account] | ||
}); | ||
|
||
if (signatures.size !== EXPECTED_SIG_NUM) | ||
throw new ProofGenerationError( | ||
`Invalid number of signatures. Expected ${EXPECTED_SIG_NUM} and got ${signatures.size}` | ||
); | ||
|
||
const [pubKey] = signatures.keys(); | ||
const [signature] = signatures.values(); | ||
|
||
return { pubKey, 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
Oops, something went wrong.