-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added substrate signer, signature, address. - Migrated ethereum signer to crypto/ethereum. - Some encoding & signature fixes for messages. - Removed tests that failed to build. TL;DR: SDK now compiles again (make all), but haven't run the tests yet.
- Loading branch information
Showing
30 changed files
with
642 additions
and
617 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
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,51 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
"use strict"; | ||
|
||
import { Bytes, Signer as EthersSigner, utils } from "ethers"; | ||
import { Signer, Address, Signature } from "#erdstall/crypto"; | ||
import { EthereumSignature } from "./signature"; | ||
import { EthereumAddress } from "./address"; | ||
import { ethers } from "ethers"; | ||
|
||
// Compile-time check that the EthersSigner implements the Signer interface. | ||
export class EthereumSigner implements Signer<"ethereum"> { | ||
readonly ethersSigner: EthersSigner; | ||
|
||
constructor(ethersSigner: EthersSigner) { | ||
this.ethersSigner = ethersSigner; | ||
} | ||
|
||
async sign(message: Uint8Array): Promise<Signature<"ethereum">> { | ||
const sig = await this.ethersSigner.signMessage( | ||
utils.keccak256(message), | ||
); | ||
return new EthereumSignature(utils.arrayify(sig)); | ||
} | ||
|
||
async address(): Promise<EthereumAddress> { | ||
return EthereumAddress.fromString(await this.ethersSigner.getAddress()); | ||
} | ||
|
||
// Generates a unique random custodial account. Returns a signer, its | ||
// associated account's address, and the private key used for restoring | ||
// that account later using `restoreCustodialAccount()`. | ||
static generateCustodialAccount(): { | ||
signer: EthereumSigner; | ||
privateKey: string; | ||
} { | ||
let wallet = ethers.Wallet.createRandom(); | ||
return { | ||
signer: new EthereumSigner(wallet), | ||
privateKey: wallet.privateKey, | ||
}; | ||
} | ||
|
||
// Restores a custodial account from its private key, as returned by | ||
// `generateCustodialAccount()`. Returns a signer and the associated | ||
// account's address. | ||
static restoreCustodialAccount(privateKey: string): EthereumSigner { | ||
let signer = new ethers.Wallet(privateKey); | ||
return new EthereumSigner(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
Oops, something went wrong.