Skip to content

Commit 26ada5c

Browse files
committed
chore: apply suggestion
1 parent faa95d9 commit 26ada5c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

core/tnclient/transport_cre.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ var _ Transport = (*CRETransport)(nil)
8787
// }
8888
func NewCRETransport(runtime cre.NodeRuntime, endpoint string, signer auth.Signer) (*CRETransport, error) {
8989
// Append /rpc/v1 if not already present (kwil-db client adds this automatically)
90+
// First trim trailing slashes to prevent duplication (e.g., "/rpc/v1/" → "/rpc/v1/rpc/v1")
91+
endpoint = strings.TrimRight(endpoint, "/")
9092
if !strings.HasSuffix(endpoint, "/rpc/v1") {
91-
endpoint = strings.TrimSuffix(endpoint, "/") + "/rpc/v1"
93+
endpoint = endpoint + "/rpc/v1"
9294
}
9395

9496
return &CRETransport{
@@ -236,8 +238,10 @@ func (t *CRETransport) Call(ctx context.Context, namespace string, action string
236238
Arguments: encodedInputs,
237239
}
238240

239-
// Create CallMessage (unauthenticated)
240-
// For unauthenticated calls, challenge is empty and signer is nil
241+
// Create CallMessage
242+
// Call operations are read-only and typically don't require authentication,
243+
// but we pass the signer (if configured) to support authenticated gateway calls.
244+
// The challenge is nil for standard calls (vs. Execute which requires it).
241245
callMsg, err := types.CreateCallMessage(payload, nil, t.signer)
242246
if err != nil {
243247
return nil, fmt.Errorf("failed to create call message: %w", err)
@@ -651,7 +655,9 @@ func (t *CRETransport) doJSONRPCWithResponse(ctx context.Context, method string,
651655
}
652656

653657
// composeGatewayAuthMessage composes a SIWE-like authentication message.
654-
// This is the same format used by the kwil-db gateway client.
658+
// This matches the format used by kwil-db gateway client.
659+
// Note: This is a custom format, not standard SIWE - it omits the account address line
660+
// and uses "Issue At" instead of "Issued At" to match kgw's expectations.
655661
func composeGatewayAuthMessage(param *gateway.AuthnParameterResponse, domain string, uri string, version string, chainID string) string {
656662
var msg bytes.Buffer
657663
msg.WriteString(domain + " wants you to sign in with your account:\n")
@@ -664,7 +670,7 @@ func composeGatewayAuthMessage(param *gateway.AuthnParameterResponse, domain str
664670
msg.WriteString(fmt.Sprintf("Version: %s\n", version))
665671
msg.WriteString(fmt.Sprintf("Chain ID: %s\n", chainID))
666672
msg.WriteString(fmt.Sprintf("Nonce: %s\n", param.Nonce))
667-
msg.WriteString(fmt.Sprintf("Issue At: %s\n", param.IssueAt))
673+
msg.WriteString(fmt.Sprintf("Issue At: %s\n", param.IssueAt)) // Note: "Issue At" not "Issued At" (kgw custom format)
668674
if param.ExpirationTime != "" {
669675
msg.WriteString(fmt.Sprintf("Expiration Time: %s\n", param.ExpirationTime))
670676
}

0 commit comments

Comments
 (0)