-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for cache-signatures (#10)
* cache signatures * mnemonic --------- Co-authored-by: nomo-fe <[email protected]>
- Loading branch information
Showing
9 changed files
with
159 additions
and
29 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,41 @@ | ||
import { resolve } from "path"; | ||
import { readFileSync, existsSync, writeFileSync } from "fs"; | ||
import { logFatal } from "../util/util"; | ||
import { NomoManifest } from "../init/interface"; | ||
import { Wallet } from "ethers"; | ||
import { ethers } from "ethers"; | ||
|
||
export async function signWebOn(args: { | ||
manifestPath: string; | ||
tarFilePath: string; | ||
mnemonic: string; | ||
}): Promise<void> { | ||
console.log("Mnemonic found in config. Creating a signature of the cache..."); | ||
|
||
const manifestPath = resolve(args.manifestPath); | ||
if (!existsSync(manifestPath)) { | ||
logFatal(`Manifest does not exist: ${manifestPath}`); | ||
} | ||
const tarFilePath = resolve(args.manifestPath); | ||
if (!existsSync(tarFilePath)) { | ||
logFatal(`tar.gz file to sign does not exist: ${tarFilePath}`); | ||
} | ||
|
||
const nomoManifestContent = readFileSync(manifestPath, "utf-8"); | ||
const nomoManifest: NomoManifest = JSON.parse(nomoManifestContent); | ||
|
||
const tarFileContent = readFileSync(tarFilePath); | ||
|
||
const ethersSigner = Wallet.fromPhrase(args.mnemonic); | ||
const cache_sig = await ethersSigner.signMessage(tarFileContent); | ||
const signerAddress = ethers.verifyMessage(tarFileContent, cache_sig); | ||
|
||
nomoManifest.cache_sig = cache_sig; | ||
|
||
const newManifestContent = JSON.stringify(nomoManifest, null, 2); | ||
|
||
writeFileSync(manifestPath, newManifestContent); | ||
console.log( | ||
`Wrote a cache-signature for address ${signerAddress} to ${manifestPath}` | ||
); | ||
} |
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