Skip to content

Commit

Permalink
Account federation (#41)
Browse files Browse the repository at this point in the history
* refactor: update go-sequence to use proto enums

* deps: update go-sequence

* proto: update schema and generated files

* data: implement (*AccountTable).Delete method

* rpc: implement account intents

* rpc: fix the tests

* rpc: return an error if email already used

* rpc: add more context to ErrEmailAlreadyInUse

* rpc: modify account RPCs to use the new identity.Verifier

* deps: pin go-sequence to v0.31.0

* update protos
  • Loading branch information
patrislav authored May 20, 2024
1 parent eef988f commit 93710c8
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 375 deletions.
14 changes: 14 additions & 0 deletions data/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ func (t *AccountTable) ListByEmail(ctx context.Context, projectID uint64, email

return accounts, nil
}

func (t *AccountTable) Delete(ctx context.Context, projectID uint64, identity proto.Identity) error {
acct := Account{ProjectID: projectID, Identity: Identity(identity)}
input := &dynamodb.DeleteItemInput{
TableName: &t.tableARN,
Key: acct.Key(),
}

_, err := t.db.DeleteItem(ctx, input)
if err != nil {
return err
}
return nil
}
9 changes: 5 additions & 4 deletions proto/authenticator.gen.go

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

6 changes: 5 additions & 1 deletion proto/authenticator.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ name = sequence-waas-authenticator
version = v0.1.0


import ./intent.ridl
import ../vendor/github.com/0xsequence/go-sequence/intents/intent.ridl
- IntentName
- Intent
- IntentResponseCode
- IntentResponse
- Signature
- IntentName
Expand Down Expand Up @@ -147,6 +149,8 @@ struct SessionData
error 1000 Unauthorized "Unauthorized access" HTTP 401
error 1001 TenantNotFound "Tenant not found" HTTP 404

error 2000 EmailAlreadyInUse "Could not create account as the email is already in use" HTTP 409


##
## Services
Expand Down
9 changes: 5 additions & 4 deletions proto/clients/authenticator.gen.go

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

19 changes: 17 additions & 2 deletions proto/clients/authenticator.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// sequence-waas-authenticator v0.1.0 f7bf79363b992ace30e01ed2c6700c9ad0336c95
// sequence-waas-authenticator v0.1.0 2b3aee6b2e912ae0b3a6b4878672632d3025a99a
// --
// 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 = "f7bf79363b992ace30e01ed2c6700c9ad0336c95"
export const WebRPCSchemaHash = "2b3aee6b2e912ae0b3a6b4878672632d3025a99a"

//
// Types
Expand Down Expand Up @@ -655,6 +655,19 @@ export class TenantNotFoundError extends WebrpcError {
}
}

export class EmailAlreadyInUseError extends WebrpcError {
constructor(
name: string = 'EmailAlreadyInUse',
code: number = 2000,
message: string = 'Could not create account as the email is already in use',
status: number = 0,
cause?: string
) {
super(name, code, message, status, cause)
Object.setPrototypeOf(this, EmailAlreadyInUseError.prototype)
}
}


export enum errors {
WebrpcEndpoint = 'WebrpcEndpoint',
Expand All @@ -670,6 +683,7 @@ export enum errors {
WebrpcStreamFinished = 'WebrpcStreamFinished',
Unauthorized = 'Unauthorized',
TenantNotFound = 'TenantNotFound',
EmailAlreadyInUse = 'EmailAlreadyInUse',
}

const webrpcErrorByCode: { [code: number]: any } = {
Expand All @@ -686,6 +700,7 @@ const webrpcErrorByCode: { [code: number]: any } = {
[-10]: WebrpcStreamFinishedError,
[1000]: UnauthorizedError,
[1001]: TenantNotFoundError,
[2000]: EmailAlreadyInUseError,
}

export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
Expand Down
Loading

0 comments on commit 93710c8

Please sign in to comment.