Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NayNay] Sign takes a verifying key now #382

Merged
merged 18 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/signing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export interface SigMsgOps {

export interface SigWithAdapptersOps extends SigMsgOps {
order: string[]
signatureVerifyingKey?: string
}

export interface SigOps {
sigRequestHash: string
hash: string
type?: string
auxiliaryData?: unknown[]
signatureVerifyingKey?: string
}

/**
Expand Down Expand Up @@ -122,6 +124,7 @@ export default class SignatureRequestManager {
async signWithAdaptersInOrder ({
msg,
order,
signatureVerifyingKey
}: SigWithAdapptersOps): Promise<unknown> {
if (!order) {
throw new Error(
Expand All @@ -142,7 +145,7 @@ export default class SignatureRequestManager {
}
return agg
}, [])
// const { sigRequestHash, auxilary_data } = await

rh0delta marked this conversation as resolved.
Show resolved Hide resolved
const results = await Promise.all(
adaptersToRun.map((adapter) => {
return adapter.preSign(this.signer, msg)
Expand All @@ -161,6 +164,7 @@ export default class SignatureRequestManager {
sigRequestHash,
hash: adaptersToRun[0].HASHING_ALGORITHM,
auxiliaryData,
signatureVerifyingKey,
})
return signature
}
Expand All @@ -180,6 +184,7 @@ export default class SignatureRequestManager {
sigRequestHash,
hash,
auxiliaryData,
signatureVerifyingKey: signatureVerifyingKeyOverwrite,
rh0delta marked this conversation as resolved.
Show resolved Hide resolved
}: SigOps): Promise<Uint8Array> {
const strippedsigRequestHash = stripHexPrefix(sigRequestHash)
const validatorsInfo: Array<ValidatorInfo> = await this.pickValidators(
Expand All @@ -188,7 +193,7 @@ export default class SignatureRequestManager {
// TO-DO: this needs to be and accounId ie hex string of the address
// which means you need a new key ie device key here

const signatureVerifyingKey = this.verifyingKey
const signatureVerifyingKey = signatureVerifyingKeyOverwrite || this.verifyingKey

const txRequests: Array<EncMsg> = await this.formatTxRequests({
strippedsigRequestHash,
Expand Down
54 changes: 54 additions & 0 deletions tests/sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
spinNetworkUp,
spinNetworkDown,
charlieStashSeed,
charlieSeed,
} from './testing-utils'

const NETWORK_TYPE = 'two-nodes'
Expand Down Expand Up @@ -55,3 +56,56 @@ test('Sign', async (t) => {

t.end()
})

test('Sign: Inputted Verifying Keys', async (t) => {
const run = promiseRunner(t)

/* Setup Network */
await run('network up', spinNetworkUp(NETWORK_TYPE))
await sleep(process.env.GITHUB_WORKSPACE ? 30_000 : 5_000)
t.teardown(async () => {
// this gets called after all tests are run
await charlieStashEntropy.close()
await charlieEntropy.close()
await spinNetworkDown(NETWORK_TYPE).catch((error) =>
console.error('Error while spinning network down', error.message)
)
})

/* Setup Entropy */
await run('wasm', wasmGlobalsReady())
const charlieStashKeyring = new Keyring({ seed: charlieStashSeed, debug: true })
const charlieKeyring = new Keyring({ seed: charlieSeed, debug: true })
rh0delta marked this conversation as resolved.
Show resolved Hide resolved
const charlieStashEntropy = new Entropy({
keyring: charlieStashKeyring,
endpoint: 'ws://127.0.0.1:9944',
})
const charlieEntropy = new Entropy({
keyring: charlieKeyring,
endpoint: 'ws://127.0.0.1:9944',
})
await run('charlieStashEntropy ready', charlieStashEntropy.ready)
await run('charlieEntropy ready', charlieEntropy.ready)
rh0delta marked this conversation as resolved.
Show resolved Hide resolved
await run('charlie stash register', charlieStashEntropy.register())
await run('charlie register', charlieEntropy.register())
rh0delta marked this conversation as resolved.
Show resolved Hide resolved


/* Sign */
const msg = Buffer
.from('Hello world: new signature from charlieStashEntropy!')
.toString('hex')

const signature = await run(
'sign',
charlieStashEntropy.signWithAdaptersInOrder({
msg: { msg },
order: ['deviceKeyProxy'],
signatureVerifyingKey: charlieEntropy.keyring.accounts.deviceKey.verifyingKeys[0]
})
)
rh0delta marked this conversation as resolved.
Show resolved Hide resolved

t.true(signature && signature.length > 32, 'signature has some body!')
signature && console.log(signature)

t.end()
})