From eb95505d2e7f839324b07c1ae7d6ebecdddca050 Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Mon, 12 Feb 2024 14:53:45 +0100 Subject: [PATCH] intent.ridl update --- intents/intent.gen.go | 60 ++++++++++++++++++++++++++++++++++-- intents/intent.gen.ts | 60 ++++++++++++++++++++++++++++++++++-- intents/intent.ridl | 46 +++++++++++++++++++++++---- intents/intent_ext.go | 22 +++++++++++++ intents/intent_typed.go | 16 +++++----- intents/intent_typed_test.go | 34 ++++++++++---------- 6 files changed, 201 insertions(+), 37 deletions(-) diff --git a/intents/intent.gen.go b/intents/intent.gen.go index d7369d7..164cc3f 100644 --- a/intents/intent.gen.go +++ b/intents/intent.gen.go @@ -1,4 +1,4 @@ -// sequence-waas-intents v0.1.0 2e194b57788277e83563e48f4a88fac890a5a069 +// sequence-waas-intents v0.1.0 a199ec1e7889726ed0a6468c1b434f4a2da44728 // -- // Code generated by webrpc-gen@v0.14.0-dev with golang generator. DO NOT EDIT. // @@ -25,7 +25,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "2e194b57788277e83563e48f4a88fac890a5a069" + return "a199ec1e7889726ed0a6468c1b434f4a2da44728" } // @@ -54,7 +54,6 @@ type IntentDataOpenSession struct { type IntentDataCloseSession struct { SessionId string `json:"sessionId"` - Wallet string `json:"wallet"` } type IntentDataValidateSession struct { @@ -65,11 +64,13 @@ type IntentDataValidateSession struct { type IntentDataFinishValidateSession struct { SessionId string `json:"sessionId"` + Wallet string `json:"wallet"` Salt string `json:"salt"` Challenge string `json:"challenge"` } type IntentDataListSessions struct { + Wallet string `json:"wallet"` } type IntentDataGetSession struct { @@ -137,6 +138,59 @@ type IntentResponse struct { Data interface{} `json:"data"` } +type IntentResponseSessionOpened struct { + SessionId string `json:"sessionId"` + Wallet string `json:"wallet"` +} + +type IntentResponseSessionClosed struct { +} + +type IntentResponseValidateSession struct { +} + +type IntentResponseValidationRequired struct { + SessionId string `json:"sessionId"` +} + +type IntentResponseValidationStarted struct { + Salt string `json:"salt"` +} + +type IntentResponseValidationFinished struct { + IsValid bool `json:"isValid"` +} + +type IntentResponseListSessions struct { + Sessions []string `json:"sessions"` +} + +type IntentResponseGetSession struct { + SessionId string `json:"sessionId"` + Wallet string `json:"wallet"` + Validated bool `json:"validated"` +} + +type IntentResponseSignedMessage struct { + Signature string `json:"signature"` + Message string `json:"message"` +} + +type IntentResponseTransactionReceipt struct { + Request interface{} `json:"request"` + TxHash string `json:"txHash"` + MetaTxHash string `json:"metaTxHash"` + Receipt interface{} `json:"receipt"` + NativeReceipt interface{} `json:"nativeReceipt"` + Simulations interface{} `json:"simulations"` +} + +type IntentResponseTransactionFailed struct { + Error string `json:"error"` + Request interface{} `json:"request"` + Simulations interface{} `json:"simulations"` +} + // // Helpers // diff --git a/intents/intent.gen.ts b/intents/intent.gen.ts index e67e394..abdeb68 100644 --- a/intents/intent.gen.ts +++ b/intents/intent.gen.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// sequence-waas-intents v0.1.0 2e194b57788277e83563e48f4a88fac890a5a069 +// sequence-waas-intents v0.1.0 a199ec1e7889726ed0a6468c1b434f4a2da44728 // -- // Code generated by webrpc-gen@v0.14.0-dev with typescript generator. DO NOT EDIT. // @@ -12,7 +12,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v0.1.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "2e194b57788277e83563e48f4a88fac890a5a069" +export const WebRPCSchemaHash = "a199ec1e7889726ed0a6468c1b434f4a2da44728" // // Types @@ -41,7 +41,6 @@ export interface IntentDataOpenSession { export interface IntentDataCloseSession { sessionId: string - wallet: string } export interface IntentDataValidateSession { @@ -52,11 +51,13 @@ export interface IntentDataValidateSession { export interface IntentDataFinishValidateSession { sessionId: string + wallet: string salt: string challenge: string } export interface IntentDataListSessions { + wallet: string } export interface IntentDataGetSession { @@ -124,6 +125,59 @@ export interface IntentResponse { data: any } +export interface IntentResponseSessionOpened { + sessionId: string + wallet: string +} + +export interface IntentResponseSessionClosed { +} + +export interface IntentResponseValidateSession { +} + +export interface IntentResponseValidationRequired { + sessionId: string +} + +export interface IntentResponseValidationStarted { + salt: string +} + +export interface IntentResponseValidationFinished { + isValid: boolean +} + +export interface IntentResponseListSessions { + sessions: Array +} + +export interface IntentResponseGetSession { + sessionId: string + wallet: string + validated: boolean +} + +export interface IntentResponseSignedMessage { + signature: string + message: string +} + +export interface IntentResponseTransactionReceipt { + request: any + txHash: string + metaTxHash: string + receipt: any + nativeReceipt: any + simulations: any +} + +export interface IntentResponseTransactionFailed { + error: string + request: any + simulations: any +} + const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { diff --git a/intents/intent.ridl b/intents/intent.ridl index 083e8f4..4261325 100644 --- a/intents/intent.ridl +++ b/intents/intent.ridl @@ -33,7 +33,6 @@ struct IntentDataOpenSession struct IntentDataCloseSession - sessionId: string - - wallet: string struct IntentDataValidateSession - sessionId: string @@ -42,10 +41,13 @@ struct IntentDataValidateSession struct IntentDataFinishValidateSession - sessionId: string + - wallet: string - salt: string - challenge: string struct IntentDataListSessions + - wallet: string + struct IntentDataGetSession - sessionId: string @@ -111,24 +113,56 @@ struct IntentResponse - code: string - data: any +# no way to generate string enums +#enum IntentResponseCode: string +# - sessionOpened +# - validationRequired +# - validationStarted +# - validationFinished +# - signedMessage +# - transactionReceipt +# - transactionFailed +# - getSessionResponse + struct IntentResponseSessionOpened - sessionId: string + - wallet: string struct IntentResponseSessionClosed struct IntentResponseValidateSession -struct IntentResponseFinishValidateSession +struct IntentResponseValidationRequired + - sessionId: string + +struct IntentResponseValidationStarted + - salt: string + +struct IntentResponseValidationFinished + - isValid: bool struct IntentResponseListSessions - sessions: []string struct IntentResponseGetSession - - isValid: bool + - sessionId: string + - wallet: string + - validated: bool -struct IntentResponseSignMessage +struct IntentResponseSignedMessage - signature: string + - message: string + +struct IntentResponseTransactionReceipt + - request: any + - txHash: string + - metaTxHash: string + - receipt: any + - nativeReceipt: any + - simulations: any -struct IntentResponseSendTransaction +struct IntentResponseTransactionFailed + - error: string + - request: any + - simulations: any -struct IntentResponseSendFail diff --git a/intents/intent_ext.go b/intents/intent_ext.go index 02442cf..404daff 100644 --- a/intents/intent_ext.go +++ b/intents/intent_ext.go @@ -25,6 +25,28 @@ const ( KeyTypeUnknown ) +const ( + IntentNameOpenSession = "openSession" + IntentNameCloseSession = "closeSession" + IntentNameValidateSession = "validateSession" + IntentNameFinishValidateSession = "finishValidateSession" + IntentNameListSessions = "listSessions" + IntentNameGetSession = "getSession" + IntentNameSignMessage = "signMessage" + IntentNameSendTransaction = "sendTransaction" +) + +const ( + IntentResponseCodeSessionOpened = "sessionOpened" + IntentResponseCodeValidationRequired = "validationRequired" + IntentResponseCodeValidationStarted = "validationStarted" + IntentResponseCodeValidationFinished = "validationFinished" + IntentResponseCodeSignedMessage = "signedMessage" + IntentResponseCodeTransactionReceipt = "transactionReceipt" + IntentResponseCodeTransactionFailed = "transactionFailed" + IntentResponseCodeGetSessionResponse = "getSessionResponse" +) + type IntentDataValidator interface { IsValid() error } diff --git a/intents/intent_typed.go b/intents/intent_typed.go index af5f8a6..e9a520e 100644 --- a/intents/intent_typed.go +++ b/intents/intent_typed.go @@ -10,21 +10,21 @@ func IntentDataTypeToName[T any](t *T) string { var data any = t switch data.(type) { case *IntentDataOpenSession: - return "openSession" + return IntentNameOpenSession case *IntentDataCloseSession: - return "closeSession" + return IntentNameCloseSession case *IntentDataValidateSession: - return "validateSession" + return IntentNameValidateSession case *IntentDataFinishValidateSession: - return "finishValidateSession" + return IntentNameFinishValidateSession case *IntentDataListSessions: - return "listSessions" + return IntentNameListSessions case *IntentDataGetSession: - return "getSession" + return IntentNameGetSession case *IntentDataSignMessage: - return "signMessage" + return IntentNameSignMessage case *IntentDataSendTransaction: - return "sendTransaction" + return IntentNameSendTransaction default: return "" } diff --git a/intents/intent_typed_test.go b/intents/intent_typed_test.go index 3a8f57a..12519d4 100644 --- a/intents/intent_typed_test.go +++ b/intents/intent_typed_test.go @@ -13,44 +13,44 @@ import ( ) func TestIntentNewIntentTyped(t *testing.T) { - t.Run("openSession", func(t *testing.T) { + t.Run(IntentNameOpenSession, func(t *testing.T) { intent := NewIntentTyped(IntentDataOpenSession{SessionId: "0x1234"}) - assert.Equal(t, "openSession", intent.Name) + assert.Equal(t, IntentNameOpenSession, intent.Name) }) - t.Run("closeSession", func(t *testing.T) { + t.Run(IntentNameCloseSession, func(t *testing.T) { intent := NewIntentTyped(IntentDataCloseSession{SessionId: "0x1234"}) - assert.Equal(t, "closeSession", intent.Name) + assert.Equal(t, IntentNameCloseSession, intent.Name) }) - t.Run("validateSession", func(t *testing.T) { + t.Run(IntentNameValidateSession, func(t *testing.T) { intent := NewIntentTyped(IntentDataValidateSession{SessionId: "0x1234"}) - assert.Equal(t, "validateSession", intent.Name) + assert.Equal(t, IntentNameValidateSession, intent.Name) }) - t.Run("finishValidateSession", func(t *testing.T) { + t.Run(IntentNameFinishValidateSession, func(t *testing.T) { intent := NewIntentTyped(IntentDataFinishValidateSession{SessionId: "0x1234"}) - assert.Equal(t, "finishValidateSession", intent.Name) + assert.Equal(t, IntentNameFinishValidateSession, intent.Name) }) - t.Run("listSessions", func(t *testing.T) { + t.Run(IntentNameListSessions, func(t *testing.T) { intent := NewIntentTyped(IntentDataListSessions{}) - assert.Equal(t, "listSessions", intent.Name) + assert.Equal(t, IntentNameListSessions, intent.Name) }) - t.Run("getSession", func(t *testing.T) { + t.Run(IntentNameGetSession, func(t *testing.T) { intent := NewIntentTyped(IntentDataGetSession{SessionId: "0x1234"}) - assert.Equal(t, "getSession", intent.Name) + assert.Equal(t, IntentNameGetSession, intent.Name) }) - t.Run("sign", func(t *testing.T) { + t.Run(IntentNameSignMessage, func(t *testing.T) { intent := NewIntentTyped(IntentDataSignMessage{Network: "ethereum", Message: "0x1234"}) - assert.Equal(t, "signMessage", intent.Name) + assert.Equal(t, IntentNameSignMessage, intent.Name) }) - t.Run("transaction", func(t *testing.T) { + t.Run(IntentNameSendTransaction, func(t *testing.T) { intent := NewIntentTyped(IntentDataSendTransaction{}) - assert.Equal(t, "sendTransaction", intent.Name) + assert.Equal(t, IntentNameSendTransaction, intent.Name) }) t.Run("unknown", func(t *testing.T) { @@ -63,7 +63,7 @@ func TestIntentNewIntentTypedFromIntent(t *testing.T) { t.Run("openSession", func(t *testing.T) { intent := Intent{ Version: "1", - Name: "openSession", + Name: IntentNameOpenSession, Data: map[string]interface{}{"sessionId": "0x1234"}, }