77
88 "github.com/LumeraProtocol/supernode/v2/pkg/codec"
99 "github.com/LumeraProtocol/supernode/v2/pkg/errors"
10-
11- actionkeeper "github.com/LumeraProtocol/lumera/x/action/v1/keeper"
12-
1310 keyringpkg "github.com/LumeraProtocol/supernode/v2/pkg/keyring"
1411
1512 sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
@@ -42,28 +39,26 @@ func SignLayoutB64(layout codec.Layout, signer Signer) (layoutB64 string, layout
4239}
4340
4441// SignIndexB64 marshals the index to JSON, base64-encodes it, and signs the
45- // JSON string (not the base64) , returning both the index base64 and creator-signature base64.
42+ // base64 payload , returning both the index base64 and creator-signature base64.
4643//
4744// IMPORTANT:
48- // - Message signed = index JSON string (same as JS signArbitrary(indexFileString) )
49- // - indexB64 is still base64(JSON(index)), used in metadata and RQID generation.
45+ // - Message signed = indexB64 string (chain-compatible )
46+ // - indexB64 is base64(JSON(index)), used in metadata and RQID generation.
5047func SignIndexB64 (idx IndexFile , signer Signer ) (indexB64 string , creatorSigB64 string , err error ) {
5148 raw , err := json .Marshal (idx )
5249 if err != nil {
5350 return "" , "" , errors .Errorf ("marshal index file: %w" , err )
5451 }
5552
56- indexJSON := string (raw )
53+ indexB64 = base64 . StdEncoding . EncodeToString (raw )
5754
58- // Sign the JSON string (JS-style )
59- sig , err := signer ([]byte (indexJSON ))
55+ // Sign the base64 payload (chain-compatible )
56+ sig , err := signer ([]byte (indexB64 ))
6057 if err != nil {
6158 return "" , "" , errors .Errorf ("sign index: %w" , err )
6259 }
6360 creatorSigB64 = base64 .StdEncoding .EncodeToString (sig )
6461
65- // Base64(JSON(index)) used as the first segment of indexSignatureFormat
66- indexB64 = base64 .StdEncoding .EncodeToString (raw )
6762 return indexB64 , creatorSigB64 , nil
6863}
6964
@@ -73,9 +68,7 @@ func SignIndexB64(idx IndexFile, signer Signer) (indexB64 string, creatorSigB64
7368//
7469// It validates the layout has exactly one block.
7570//
76- // The "signer" can be:
77- // - raw: directly sign msg bytes (legacy Go path)
78- // - ADR-36: wrap msg into an ADR-36 sign doc, then sign (JS-compatible path)
71+ // The signer directly signs the message bytes (raw signing).
7972func CreateSignatures (layout codec.Layout , signer Signer , ic , max uint32 ) (indexSignatureFormat string , indexIDs []string , err error ) {
8073 layoutB64 , layoutSigB64 , err := SignLayoutB64 (layout , signer )
8174 if err != nil {
@@ -89,7 +82,7 @@ func CreateSignatures(layout codec.Layout, signer Signer, ic, max uint32) (index
8982 return "" , nil , err
9083 }
9184
92- // Build and sign the index file (JS-style: message = index JSON string)
85+ // Build and sign the index file (message = indexB64 string)
9386 idx := BuildIndex (layoutIDs , layoutSigB64 )
9487 indexB64 , creatorSigB64 , err := SignIndexB64 (idx , signer )
9588 if err != nil {
@@ -105,12 +98,10 @@ func CreateSignatures(layout codec.Layout, signer Signer, ic, max uint32) (index
10598 return indexSignatureFormat , indexIDs , nil
10699}
107100
108- // CreateSignaturesWithKeyring signs layout and index using a Cosmos keyring (legacy path) .
101+ // CreateSignaturesWithKeyring signs layout and index using a Cosmos keyring.
109102// Message signed = raw bytes passed by SignLayoutB64 / SignIndexB64:
110103// - layout: layoutB64 string
111104// - index: index JSON string
112- //
113- // The verification pipeline already handles both raw and ADR-36, so this remains valid.
114105func CreateSignaturesWithKeyring (
115106 layout codec.Layout ,
116107 kr sdkkeyring.Keyring ,
@@ -122,97 +113,3 @@ func CreateSignaturesWithKeyring(
122113 }
123114 return CreateSignatures (layout , signer , ic , max )
124115}
125-
126- // adr36SignerForKeyring creates a signer that signs ADR-36 doc bytes
127- // for the given signer address. The "msg" we pass in is the *message*
128- // (layoutB64, index JSON, etc.), and this helper wraps it into ADR-36.
129- func adr36SignerForKeyring (
130- kr sdkkeyring.Keyring ,
131- keyName string ,
132- signerAddr string ,
133- ) Signer {
134- return func (msg []byte ) ([]byte , error ) {
135- // msg is the cleartext message we want to sign (e.g., layoutB64 or index JSON string)
136- dataB64 := base64 .StdEncoding .EncodeToString (msg )
137-
138- // Build ADR-36 sign bytes: signerAddr + base64(message)
139- doc , err := actionkeeper .MakeADR36AminoSignBytes (signerAddr , dataB64 )
140- if err != nil {
141- return nil , err
142- }
143-
144- // Now sign the ADR-36 doc bytes with the keyring (direct secp256k1)
145- return keyringpkg .SignBytes (kr , keyName , doc )
146- }
147- }
148-
149- // CreateSignaturesWithKeyringADR36WithSigner creates signatures in the SAME way as the JS SDK,
150- // allowing an explicit bech32 signer address override for ADR-36 sign bytes.
151- func CreateSignaturesWithKeyringADR36WithSigner (
152- layout codec.Layout ,
153- kr sdkkeyring.Keyring ,
154- keyName string ,
155- signerAddr string ,
156- ic , max uint32 ,
157- ) (string , []string , error ) {
158- if signerAddr == "" {
159- addr , err := keyringpkg .GetAddress (kr , keyName )
160- if err != nil {
161- return "" , nil , fmt .Errorf ("resolve signer address: %w" , err )
162- }
163- signerAddr = addr .String ()
164- }
165-
166- signer := adr36SignerForKeyring (kr , keyName , signerAddr )
167-
168- return CreateSignatures (layout , signer , ic , max )
169- }
170-
171- // CreateSignaturesWithKeyringADR36 creates signatures in the SAME way as the JS SDK:
172- //
173- // - layout: Keplr-like ADR-36 signature over layoutB64 string
174- // - index: Keplr-like ADR-36 signature over index JSON string
175- //
176- // The resulting indexSignatureFormat string will match what JS produces for the same
177- // layout, signer, ic, and max.
178- func CreateSignaturesWithKeyringADR36 (
179- layout codec.Layout ,
180- kr sdkkeyring.Keyring ,
181- keyName string ,
182- ic , max uint32 ,
183- ) (string , []string , error ) {
184- return CreateSignaturesWithKeyringADR36WithSigner (layout , kr , keyName , "" , ic , max )
185- }
186-
187- // SignADR36String signs a message string using the ADR-36 scheme that Keplr uses.
188- // "message" must be the same string you'd pass to Keplr's signArbitrary, e.g.:
189- // - layoutB64
190- // - index JSON
191- // - dataHash (base64 blake3)
192- func SignADR36String (
193- kr sdkkeyring.Keyring ,
194- keyName string ,
195- signerAddr string ,
196- message string ,
197- ) (string , error ) {
198- // 1) message -> []byte
199- msgBytes := []byte (message )
200-
201- // 2) base64(UTF-8(message))
202- dataB64 := base64 .StdEncoding .EncodeToString (msgBytes )
203-
204- // 3) Build ADR-36 sign bytes (Keplr-accurate)
205- docBytes , err := actionkeeper .MakeADR36AminoSignBytes (signerAddr , dataB64 )
206- if err != nil {
207- return "" , fmt .Errorf ("build adr36 sign bytes: %w" , err )
208- }
209-
210- // 4) Sign with Cosmos keyring
211- sig , err := keyringpkg .SignBytes (kr , keyName , docBytes )
212- if err != nil {
213- return "" , fmt .Errorf ("sign adr36 doc: %w" , err )
214- }
215-
216- // 5) Wire format: base64(rsSignature)
217- return base64 .StdEncoding .EncodeToString (sig ), nil
218- }
0 commit comments