diff --git a/src/notes/index.ts b/src/notes/index.ts index 404a7da..2cd64ab 100644 --- a/src/notes/index.ts +++ b/src/notes/index.ts @@ -7,7 +7,7 @@ export { Memo } from './memo.js' export type { NoteParams } from './note.js' export { Note } from './note.js' export type { ShieldNoteCreateParams, ShieldNoteParams } from './shield-note.js' -export { ShieldNote } from './shield-note.js' +export { SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE, ShieldNote } from './shield-note.js' export type { ShieldRequest } from './shield-request.js' export { buildShieldRequest } from './shield-request.js' export type { UnshieldNoteParams } from './unshield-note.js' diff --git a/src/notes/shield-note.ts b/src/notes/shield-note.ts index dae2477..936b064 100644 --- a/src/notes/shield-note.ts +++ b/src/notes/shield-note.ts @@ -33,6 +33,15 @@ type ShieldNoteCreateParams = { /** Maximum note value representable in the contract's uint120 preimage field. */ const UINT_120_MAX = 2n ** 120n - 1n +/** + * Message a public wallet signs to derive a shield private key. + * + * DO NOT MODIFY. The shield private key is derived from a signature over this + * exact string, so any change yields a different key and shields created under + * the previous message can no longer be decrypted. + */ +const SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE = 'RAILGUN_SHIELD' + /** * Represents a Shield note for converting public assets into private RAILGUN notes. * This is the entry point for funds entering the privacy system via on-chain shield transactions. @@ -282,4 +291,4 @@ class ShieldNote extends Note { } export type { ShieldNoteParams, ShieldNoteCreateParams } -export { ShieldNote } +export { SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE, ShieldNote } diff --git a/src/wallet/railgun-wallet.ts b/src/wallet/railgun-wallet.ts index 6d938c5..c498b6e 100644 --- a/src/wallet/railgun-wallet.ts +++ b/src/wallet/railgun-wallet.ts @@ -63,16 +63,6 @@ export class RailgunWallet { this.initializeKeyPairs() } - /** - * Retrieves the constant signature message used for shield private key operations. - * This message is a predefined string that should not be modified. - * @returns The constant signature message 'RAILGUN_SHIELD'. - */ - static getShieldPrivateKeySignatureMessage () { - // DO NOT MODIFY THIS CONSTANT. - return 'RAILGUN_SHIELD' - } - /** * Initializes the key pairs and related cryptographic keys for the wallet node. * This method retrieves the spending key pair, nullifying key, and viewing key pair diff --git a/test/wallet-node.test.ts b/test/wallet-node.test.ts index bb6fb89..185936e 100644 --- a/test/wallet-node.test.ts +++ b/test/wallet-node.test.ts @@ -5,6 +5,7 @@ import { stringify } from '@railgun-reloaded/0zk-addresses' import { hexToBytes } from '@railgun-reloaded/bytes' import { initializeCryptographyLibs } from '../src/keys.js' +import { SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE } from '../src/notes/shield-note.js' import { RailgunWallet } from '../src/wallet/railgun-wallet.js' import { WalletNode } from '../src/wallet/wallet-node.js' @@ -205,10 +206,9 @@ test('railgun-wallet - deterministic key derivation', async () => { 'master public key should match expected value') }) -test('railgun-wallet - RailgunWallet.getShieldPrivateKeySignatureMessage', () => { - const message = RailgunWallet.getShieldPrivateKeySignatureMessage() - - assert.equal(message, 'RAILGUN_SHIELD', 'should return correct constant message') +test('shield-note - SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE', () => { + assert.equal(SHIELD_PRIVATE_KEY_SIGNATURE_MESSAGE, 'RAILGUN_SHIELD', + 'should return correct constant message') }) test('railgun-wallet - Different mnemonics generate different wallets', async () => {