@@ -14,6 +14,12 @@ import {
1414} from "../src/core/modules/account/account-actions"
1515import { AccountId } from "../src/core/modules/account/account-types"
1616import { DeviceId } from "../src/core/modules/device/device-types"
17+ import {
18+ createMasterKey ,
19+ deriveDefaultSparkWalletSecret ,
20+ SparkSecretSchema ,
21+ sparkSecretToMnemonic ,
22+ } from "../src/core/modules/shared/key-derivation"
1723import {
1824 AccountKindSchema ,
1925 FiatCurrencySchema ,
@@ -42,7 +48,7 @@ const accountsWithDetailsQuery = createQuery((db) =>
4248 evoluJsonObjectFrom (
4349 eb
4450 . selectFrom ( "accountSpark" )
45- . select ( [ "accountSpark.mnemonic " ] )
51+ . select ( [ "accountSpark.secret " ] )
4652 . whereRef ( "accountSpark.id" , "=" , "account.id" )
4753 ) . as ( "spark" ) ,
4854 evoluJsonObjectFrom (
@@ -77,7 +83,7 @@ const accountWithDetailsByIdQuery = (id: AccountId) =>
7783 evoluJsonObjectFrom (
7884 eb
7985 . selectFrom ( "accountSpark" )
80- . select ( [ "accountSpark.mnemonic " ] )
86+ . select ( [ "accountSpark.secret " ] )
8187 . whereRef ( "accountSpark.id" , "=" , "account.id" )
8288 ) . as ( "spark" ) ,
8389 evoluJsonObjectFrom (
@@ -159,8 +165,8 @@ export const registerAccountsCommand =
159165 currency : FiatCurrencySchema . optional ( ) . describe (
160166 "c;Currency for IBAN or cash register accounts"
161167 ) ,
162- mnemonic : NonEmptyString255Schema . optional ( ) . describe (
163- "m ;Spark wallet mnemonic "
168+ secret : SparkSecretSchema . optional ( ) . describe (
169+ "s ;Spark wallet secret as 16-byte hex "
164170 ) ,
165171 } ,
166172 async action ( _ , options ) {
@@ -194,16 +200,16 @@ export const registerAccountsCommand =
194200 }
195201
196202 if ( options . kind === "spark" ) {
197- if ( options . mnemonic === undefined ) {
198- printInvalidAccountInput ( "Spark account requires --mnemonic ." )
203+ if ( options . secret === undefined ) {
204+ printInvalidAccountInput ( "Spark account requires --secret ." )
199205 return
200206 }
201207
202208 const id = await run . orThrow (
203209 createAccount ( {
204210 ...root ,
205211 spark : {
206- mnemonic : options . mnemonic ,
212+ secret : options . secret ,
207213 } ,
208214 } )
209215 )
@@ -253,27 +259,21 @@ export const registerAccountsCommand =
253259 } ,
254260 } )
255261
256- const { wallet, mnemonic } = await SparkWallet . initialize ( {
262+ const secret = deriveDefaultSparkWalletSecret ( createMasterKey ( ) )
263+ const { wallet } = await SparkWallet . initialize ( {
264+ mnemonicOrSeed : sparkSecretToMnemonic ( secret ) ,
257265 options : {
258266 network,
259267 } ,
260268 } )
261269
262270 try {
263- if ( mnemonic === undefined ) {
264- printInvalidAccountInput (
265- "Spark wallet did not return a mnemonic."
266- )
267- return
268- }
269-
270- const accountMnemonic = NonEmptyString255Schema . parse ( mnemonic )
271271 const id = await run . orThrow (
272272 createAccount ( {
273273 deviceId : options . deviceId ?? null ,
274274 name : options . name ,
275275 spark : {
276- mnemonic : accountMnemonic ,
276+ secret ,
277277 } ,
278278 } )
279279 )
@@ -283,7 +283,8 @@ export const registerAccountsCommand =
283283 id,
284284 name : options . name ,
285285 network,
286- mnemonic,
286+ secret,
287+ mnemonic : sparkSecretToMnemonic ( secret ) ,
287288 } ) } `
288289 )
289290 } finally {
@@ -309,8 +310,8 @@ export const registerAccountsCommand =
309310 currency : FiatCurrencySchema . optional ( ) . describe (
310311 "c;Currency for IBAN or cash register accounts"
311312 ) ,
312- mnemonic : NonEmptyString255Schema . optional ( ) . describe (
313- "m ;Spark wallet mnemonic "
313+ secret : SparkSecretSchema . optional ( ) . describe (
314+ "s ;Spark wallet secret as 16-byte hex "
314315 ) ,
315316 } ,
316317 async action ( _ , options ) {
@@ -339,7 +340,7 @@ export const registerAccountsCommand =
339340 deviceId : options . deviceId ,
340341 name : options . name ,
341342 spark : {
342- mnemonic : options . mnemonic ,
343+ secret : options . secret ,
343344 } ,
344345 } )
345346 )
0 commit comments