Skip to content

Commit e9b46a3

Browse files
Use raw signing by default
1 parent 274b178 commit e9b46a3

File tree

2 files changed

+11
-120
lines changed

2 files changed

+11
-120
lines changed

pkg/cascadekit/signatures.go

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
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).
7974
func 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.
114107
func 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-
}

sdk/action/client.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Client interface {
4848
// and returns CascadeMetadata (with signatures) along with price and expiration time.
4949
// Internally derives ic (random in [1..100]), max (from chain params), price (GetActionFee),
5050
// and expiration (params duration + 1h buffer). signerAddr overrides the bech32 signer
51-
// used in ADR-36 sign bytes; pass empty string to use the keyring address.
51+
// used for key selection (e.g. ICA owner key); pass empty string to use the client signer.
5252
BuildCascadeMetadataFromFile(ctx context.Context, filePath string, public bool, signerAddr string) (actiontypes.CascadeMetadata, string, string, error)
5353
// GenerateStartCascadeSignatureFromFile computes blake3(file) and signs it with the configured key; returns base64 signature.
5454
GenerateStartCascadeSignatureFromFile(ctx context.Context, filePath string) (string, error)
@@ -292,7 +292,7 @@ func (c *ClientImpl) BuildCascadeMetadataFromFile(ctx context.Context, filePath
292292
rnd, _ := crand.Int(crand.Reader, big.NewInt(100))
293293
ic := uint32(rnd.Int64() + 1) // 1..100
294294

295-
// Create signatures from the layout struct using ADR-36 scheme (JS compatible).
295+
// Create signatures from the layout struct using raw signing (pure Go internal format).
296296
if signerAddr == "" {
297297
signerAddr = c.signerAddr
298298
}
@@ -309,11 +309,10 @@ func (c *ClientImpl) BuildCascadeMetadataFromFile(ctx context.Context, filePath
309309
event.KeyMessage: "metadata signed with ICA signer address",
310310
}))
311311
}
312-
indexSignatureFormat, _, err := cascadekit.CreateSignaturesWithKeyringADR36WithSigner(
312+
indexSignatureFormat, _, err := cascadekit.CreateSignaturesWithKeyring(
313313
layout,
314314
c.keyring,
315315
keyName,
316-
signerAddr,
317316
ic,
318317
max,
319318
)
@@ -370,15 +369,14 @@ func (c *ClientImpl) GenerateStartCascadeSignatureFromFileDeprecated(ctx context
370369
return base64.StdEncoding.EncodeToString(sig), nil
371370
}
372371

373-
// GenerateStartCascadeSignatureFromFile computes blake3(file) and signs it with the configured key
374-
// using the ADR-36 scheme, matching Keplr's signArbitrary(dataHash) behavior.
375-
// Returns base64-encoded signature suitable for StartCascade.
372+
// GenerateStartCascadeSignatureFromFile computes blake3(file) and signs the base64 hash string
373+
// using raw signing (pure Go internal format). Returns base64-encoded signature suitable for StartCascade.
376374
func (c *ClientImpl) GenerateStartCascadeSignatureFromFile(ctx context.Context, filePath string) (string, error) {
377375
return c.GenerateStartCascadeSignatureFromFileWithSigner(ctx, filePath, "")
378376
}
379377

380378
// GenerateStartCascadeSignatureFromFileWithSigner computes blake3(file) and signs it with the configured key,
381-
// using the provided bech32 signer address for ADR-36 sign bytes.
379+
// using signerAddr for key selection (e.g. ICA owner key).
382380
func (c *ClientImpl) GenerateStartCascadeSignatureFromFileWithSigner(ctx context.Context, filePath string, signerAddr string) (string, error) {
383381
// Compute blake3(file), encode as base64 string
384382
h, err := utils.Blake3HashFile(filePath)
@@ -387,7 +385,6 @@ func (c *ClientImpl) GenerateStartCascadeSignatureFromFileWithSigner(ctx context
387385
}
388386
dataHashB64 := base64.StdEncoding.EncodeToString(h)
389387

390-
// Sign the dataHashB64 string using ADR-36 (same as JS / Keplr).
391388
if signerAddr == "" {
392389
signerAddr = c.signerAddr
393390
}
@@ -400,17 +397,12 @@ func (c *ClientImpl) GenerateStartCascadeSignatureFromFileWithSigner(ctx context
400397
logtrace.Info(ctx, "auth: ICA start signature", logFields)
401398
c.logger.Info(ctx, "Signing cascade start with ICA signer", "signer", signerAddr, "key_name", keyName)
402399
}
403-
sigB64, err := cascadekit.SignADR36String(
404-
c.keyring,
405-
keyName,
406-
signerAddr, // bech32 address for ADR-36 sign bytes
407-
dataHashB64,
408-
)
400+
sig, err := snkeyring.SignBytes(c.keyring, keyName, []byte(dataHashB64))
409401
if err != nil {
410-
return "", fmt.Errorf("sign adr36 hash string: %w", err)
402+
return "", fmt.Errorf("sign hash string: %w", err)
411403
}
412404

413-
return sigB64, nil
405+
return base64.StdEncoding.EncodeToString(sig), nil
414406
}
415407

416408
func (c *ClientImpl) resolveSigningKeyName(signerAddr string) (string, bool) {

0 commit comments

Comments
 (0)