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"
@@ -73,9 +70,7 @@ func SignIndexB64(idx IndexFile, signer Signer) (indexB64 string, creatorSigB64
7370//
7471// It validates the layout has exactly one block.
7572//
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)
73+ // The signer directly signs the message bytes (raw signing).
7974func CreateSignatures (layout codec.Layout , signer Signer , ic , max uint32 ) (indexSignatureFormat string , indexIDs []string , err error ) {
8075 layoutB64 , layoutSigB64 , err := SignLayoutB64 (layout , signer )
8176 if err != nil {
@@ -105,12 +100,10 @@ func CreateSignatures(layout codec.Layout, signer Signer, ic, max uint32) (index
105100 return indexSignatureFormat , indexIDs , nil
106101}
107102
108- // CreateSignaturesWithKeyring signs layout and index using a Cosmos keyring (legacy path) .
103+ // CreateSignaturesWithKeyring signs layout and index using a Cosmos keyring.
109104// Message signed = raw bytes passed by SignLayoutB64 / SignIndexB64:
110105// - layout: layoutB64 string
111106// - index: index JSON string
112- //
113- // The verification pipeline already handles both raw and ADR-36, so this remains valid.
114107func CreateSignaturesWithKeyring (
115108 layout codec.Layout ,
116109 kr sdkkeyring.Keyring ,
@@ -122,97 +115,3 @@ func CreateSignaturesWithKeyring(
122115 }
123116 return CreateSignatures (layout , signer , ic , max )
124117}
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