Skip to content

Commit

Permalink
applied review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Feb 9, 2024
1 parent f300f52 commit 93873c2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 79 deletions.
50 changes: 23 additions & 27 deletions intentv1/intent.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions intentv1/intent.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// sequence-waas-intents v0.1.0 b0dc5c3bceb25d04f130e1807829bd8110a0a3e4
// sequence-waas-intents v0.1.0 cee7350afc8c71efb922f9b8c6a79991997f5d7a
// --
// Code generated by [email protected] with typescript generator. DO NOT EDIT.
//
Expand All @@ -12,7 +12,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v0.1.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "b0dc5c3bceb25d04f130e1807829bd8110a0a3e4"
export const WebRPCSchemaHash = "cee7350afc8c71efb922f9b8c6a79991997f5d7a"

//
// Types
Expand All @@ -27,20 +27,16 @@ export interface Signature {
export interface Intent {
version: string
name: string
expires: number
issued: number
expiresAt: number
issuedAt: number
data: any
signatures: Array<Signature>
}

export interface SessionPacketProof {
email?: string
idToken?: string
}

export interface IntentDataOpenSession {
sessionId: string
proof: SessionPacketProof
email?: string
idToken?: string
}

export interface IntentDataCloseSession {
Expand Down Expand Up @@ -70,7 +66,7 @@ export interface IntentDataSign {
message: string
}

export interface IntentDataTransaction {
export interface IntentDataSendTransaction {
network: string
identifier: string
transactions: Array<any>
Expand All @@ -85,14 +81,14 @@ export interface TransactionRaw {

export interface TransactionERC20 {
type: string
token: string
tokenAddress: string
to: string
value: string
}

export interface TransactionERC721 {
type: string
token: string
tokenAddress: string
to: string
id: string
safe?: boolean
Expand All @@ -106,7 +102,7 @@ export interface TransactionERC1155Value {

export interface TransactionERC1155 {
type: string
token: string
tokenAddress: string
to: string
vals: Array<TransactionERC1155Value>
data?: string
Expand Down
45 changes: 21 additions & 24 deletions intentv1/intent.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ webrpc = v1
name = sequence-waas-intents
version = v0.1.0

struct Intent
- version: string
- name: string
- expiresAt: uint64
- issuedAt: uint64
- data: any
- signatures: []Signature

struct Signature
- sessionId: string
- signature: string
Expand All @@ -16,23 +24,12 @@ struct Signature
# - listSessions
# - getSession
# - sign
# - transaction

struct Intent
- version: string
- name: string
- expires: uint64
- issued: uint64
- data: any
- signatures: []Signature

struct SessionPacketProof
- email?: string
- idToken?: string
# - sendTransaction

struct IntentDataOpenSession
- sessionId: string
- proof: SessionPacketProof
- email?: string
- idToken?: string

struct IntentDataCloseSession
- sessionId: string
Expand All @@ -55,33 +52,33 @@ struct IntentDataSign
- network: string
- message: string

struct IntentDataTransaction
struct IntentDataSendTransaction
- network: string
- identifier: string
- transactions: []any

struct TransactionRaw
- type: string
- to: string
- value: string
- data: string

# no way to generate string enums
#enum TransactionType: uint8
# - transaction
# - erc20send
# - erc721send
# - erc1155send

struct TransactionRaw
- type: string
- to: string
- value: string
- data: string

struct TransactionERC20
- type: string
- token: string
- tokenAddress: string
- to: string
- value: string

struct TransactionERC721
- type: string
- token: string
- tokenAddress: string
- to: string
- id: string
- safe?: bool
Expand All @@ -93,7 +90,7 @@ struct TransactionERC1155Value

struct TransactionERC1155
- type: string
- token: string
- tokenAddress: string
- to: string
- vals: []TransactionERC1155Value
- data?: string
Expand Down
6 changes: 3 additions & 3 deletions intentv1/intent_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func (intent *Intent) IsValid() error {
}

// check if the intent is expired
if intent.Expires+IntentAllowedTimeDriftInSec < uint64(time.Now().Unix()) {
if intent.ExpiresAt+IntentAllowedTimeDriftInSec < uint64(time.Now().Unix()) {
return fmt.Errorf("intent expired")
}

// check if the intent is issued in the future
if intent.Issued-IntentAllowedTimeDriftInSec > uint64(time.Now().Unix()) {
if intent.IssuedAt-IntentAllowedTimeDriftInSec > uint64(time.Now().Unix()) {
return fmt.Errorf("intent issued in the future")
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func (intent *Intent) isValidSignatureP256R1(sessionId string, signature string)

// validate session id
sessionIdBytes := common.FromHex(sessionId)
if len(sessionIdBytes) != 65 {
if len(sessionIdBytes) != 66 {
return fmt.Errorf("invalid sessionId length")
}

Expand Down
14 changes: 7 additions & 7 deletions intentv1/intent_typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func IntentDataTypeToName[T any](t *T) string {
return "getSession"
case *IntentDataSign:
return "sign"
case *IntentDataTransaction:
return "transaction"
case *IntentDataSendTransaction:
return "sendTransaction"
default:
return ""
}
Expand All @@ -38,11 +38,11 @@ type IntentTyped[T any] struct {
func NewIntentTyped[T any](data T) *IntentTyped[T] {
return &IntentTyped[T]{
Intent: Intent{
Version: "1",
Expires: uint64(time.Now().Unix()) + IntentValidTimeInSec,
Issued: uint64(time.Now().Unix()),
Name: IntentDataTypeToName(&data),
Data: data,
Version: "1",
ExpiresAt: uint64(time.Now().Unix()) + IntentValidTimeInSec,
IssuedAt: uint64(time.Now().Unix()),
Name: IntentDataTypeToName(&data),
Data: data,
},
Data: data,
}
Expand Down
8 changes: 4 additions & 4 deletions intentv1/intent_typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestIntentNewIntentTyped(t *testing.T) {
})

t.Run("transaction", func(t *testing.T) {
intent := NewIntentTyped(IntentDataTransaction{})
assert.Equal(t, "transaction", intent.Name)
intent := NewIntentTyped(IntentDataSendTransaction{})
assert.Equal(t, "sendTransaction", intent.Name)
})

t.Run("unknown", func(t *testing.T) {
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestIntentIsValid(t *testing.T) {

t.Run("expired", func(t *testing.T) {
intent := NewIntentTyped(IntentDataOpenSession{SessionId: "0x1234"})
intent.Expires = 0
intent.ExpiresAt = 0

wallet, err := ethwallet.NewWalletFromRandomEntropy()
require.NoError(t, err)
Expand All @@ -152,7 +152,7 @@ func TestIntentIsValid(t *testing.T) {

t.Run("issuedInFuture", func(t *testing.T) {
intent := NewIntentTyped(IntentDataOpenSession{SessionId: "0x1234"})
intent.Issued = uint64(1 << 63)
intent.IssuedAt = uint64(1 << 63)

wallet, err := ethwallet.NewWalletFromRandomEntropy()
require.NoError(t, err)
Expand Down

0 comments on commit 93873c2

Please sign in to comment.