-
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.
- Loading branch information
Showing
8 changed files
with
89 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
interface SignWithAdapterInput { | ||
/** the message as a utf-8 encoded string */ | ||
msg: string, | ||
verifyingKey?: string, | ||
// LATER: | ||
// auxillaryData: any | ||
} | ||
|
||
function stringToHex (str: string): string { | ||
return Buffer.from(str).toString('hex') | ||
} | ||
|
||
export async function signWithAdapter (entropy, input: SignWithAdapterInput) { | ||
return entropy.signWithAdaptersInOrder({ | ||
msg: { | ||
msg: stringToHex(input.msg) | ||
}, | ||
// type | ||
order: ['deviceKeyProxy'], | ||
signatureVerifyingKey: input.verifyingKey | ||
// auxillaryData | ||
}) | ||
} |
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,21 @@ | ||
import test from 'tape' | ||
|
||
import { signWithAdapter } from '../src/flows/sign/sign' | ||
import { setupTest, charlieStashSeed } from './testing-utils' | ||
|
||
test('Sign - signWithAdapter', async (t) => { | ||
const { run, entropy } = await setupTest(t, { seed: charlieStashSeed }) | ||
|
||
await run('register', entropy.register()) | ||
|
||
const signature = await run( | ||
'sign', | ||
signWithAdapter(entropy, { msg: "heyo!" }) | ||
) | ||
|
||
t.true(signature && signature.length > 32, 'signature has some body!') | ||
signature && console.log(signature) | ||
|
||
t.end() | ||
}) | ||
|
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,30 +1,51 @@ | ||
import { wasmGlobalsReady } from '@entropyxyz/sdk' | ||
import { Test } from 'tape' | ||
import { Entropy, wasmGlobalsReady } from '@entropyxyz/sdk' | ||
// @ts-ignore | ||
import { spinNetworkUp, spinNetworkDown, } from "@entropyxyz/sdk/testing" | ||
|
||
import { initializeEntropy } from '../../src/common/initializeEntropy' | ||
import * as config from '../../src/config' | ||
import { makeSeed, promiseRunner, sleep } from './' | ||
|
||
interface SetupTestOpts { | ||
configPath?: string | ||
networkType?: string | ||
seed?: string, | ||
} | ||
const NETWORK_TYPE_DEFAULT = 'two-nodes' | ||
let counter = 0 | ||
|
||
export async function setupTest (t: Test, opts?: SetupTestOpts): Promise<{ entropy: Entropy; run: any }> { | ||
const { | ||
configPath = `/tmp/entropy-cli-${Date.now()}_${counter++}.json`, | ||
networkType = NETWORK_TYPE_DEFAULT, | ||
seed = makeSeed() | ||
} = opts || {} | ||
|
||
export async function setupTest (t, networkType = NETWORK_TYPE_DEFAULT) { | ||
const run = promiseRunner(t) | ||
|
||
await run('wasm', wasmGlobalsReady()) | ||
await run('network up', spinNetworkUp(networkType)) | ||
// this gets called after all tests are run | ||
// this gets called after t.end() is called | ||
t.teardown(async () => { | ||
await entropy.close() | ||
await spinNetworkDown(networkType).catch((error) => | ||
console.error('Error while spinning network down', error.message) | ||
) | ||
}) | ||
|
||
await run('config.init', config.init(configPath)) | ||
|
||
// TODO: remove this after new SDK is published | ||
await sleep(process.env.GITHUB_WORKSPACE ? 30_000 : 5_000) | ||
|
||
const newSeed = makeSeed() | ||
const entropy = await initializeEntropy({ keyMaterial: { seed: newSeed, debug: true }, endpoint: 'ws://127.0.0.1:9944', }) | ||
const newAddress = entropy.keyring.accounts.registration.address | ||
|
||
const entropy = await initializeEntropy({ | ||
keyMaterial: { seed, debug: true }, | ||
endpoint: 'ws://127.0.0.1:9944', | ||
configPath | ||
}) | ||
|
||
await run('entropy ready', entropy.ready) | ||
|
||
return { t, run, entropy } | ||
return { entropy, run } | ||
} |