@@ -13,6 +13,10 @@ import { assert } from "@canvas-js/utils"
1313import type { SubstrateMessage , SubstrateSessionData } from "./types.js"
1414import { validateSessionData , randomKeypair , parseAddress , addressPattern } from "./utils.js"
1515
16+ const constructSubstrateMessage = ( message : SubstrateMessage ) => {
17+ return json . encode ( message )
18+ }
19+
1620type SubstrateSignerInit = {
1721 sessionDuration ?: number
1822 extension ?: InjectedExtension
@@ -40,7 +44,10 @@ export class SubstrateSigner extends AbstractSessionSigner<SubstrateSessionData>
4044 #signer: AbstractSigner
4145
4246 public constructor ( { sessionDuration, substrateKeyType, extension } : SubstrateSignerInit = { } ) {
43- super ( "chain-substrate" , { createSigner : ( init ) => new Ed25519DelegateSigner ( init ) , defaultDuration : sessionDuration } )
47+ super ( "chain-substrate" , {
48+ createSigner : ( init ) => new Ed25519DelegateSigner ( init ) ,
49+ defaultDuration : sessionDuration ,
50+ } )
4451 if ( extension ) {
4552 const signRaw = extension . signer . signRaw
4653 if ( signRaw === undefined ) {
@@ -159,7 +166,7 @@ export class SubstrateSigner extends AbstractSessionSigner<SubstrateSessionData>
159166 } ) . addFromAddress ( decodedAddress )
160167
161168 const { nonce, signature } = authorizationData . signatureResult
162- const signedData = bytesToHex ( nonce ) + bytesToHex ( json . encode ( message ) )
169+ const signedData = bytesToHex ( nonce ) + bytesToHex ( constructSubstrateMessage ( message ) )
163170
164171 const valid = signerKeyring . verify ( signedData , signature , decodedAddress )
165172
@@ -187,7 +194,7 @@ export class SubstrateSigner extends AbstractSessionSigner<SubstrateSessionData>
187194 expirationTime : null ,
188195 }
189196
190- const signatureResult = await this . #signer. signMessage ( json . encode ( message ) )
197+ const signatureResult = await this . #signer. signMessage ( constructSubstrateMessage ( message ) )
191198 const substrateKeyType = await this . #signer. getSubstrateKeyType ( )
192199
193200 return {
0 commit comments