diff --git a/docs/passkey-er.drawio b/docs/passkey-er.drawio index 3cbc535..40855ac 100644 --- a/docs/passkey-er.drawio +++ b/docs/passkey-er.drawio @@ -4,328 +4,328 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - + - + diff --git a/plugins/passkey_relay_party/signup.go b/plugins/passkey_relay_party/signup.go index e994f80..7f85120 100644 --- a/plugins/passkey_relay_party/signup.go +++ b/plugins/passkey_relay_party/signup.go @@ -128,25 +128,27 @@ func (relay *RelayParty) finishRegistration(ctx *gin.Context) { if user, err := relay.authSessionStore.FinishRegSession(&stubReg, ctx); err != nil { response.GetResponse().FailCode(ctx, 401, "SignUp failed: "+err.Error()) - return } else { // TODO: special logic for align testing if strings.HasSuffix(stubReg.Email, "@aastar.org") { response.GetResponse().WithDataSuccess(ctx, user) return } - if initCode, address, eoaAddress, err := createAA(user, stubReg.Network); err != nil { // TODO: persistent initCode and address - response.InternalServerError(ctx, err.Error()) - return - } else { - // TODO: special logic for tokyo - relay.db.Save(user, false) - relay.db.SaveAccounts(user, initCode, address, eoaAddress, string(network)) + signup(relay, ctx, &stubReg, user) + } +} - ginJwtMiddleware().LoginHandler(ctx) +func signup(relay *RelayParty, ctx *gin.Context, reg *seedworks.FinishRegistration, user *seedworks.User) { + if initCode, address, eoaAddress, err := createAA(user, reg.Network); err != nil { + response.InternalServerError(ctx, err.Error()) + return + } else { + relay.db.Save(user, false) + relay.db.SaveAccounts(user, initCode, address, eoaAddress, string(reg.Network)) - return - } + ginJwtMiddleware().LoginHandler(ctx) + + return } } diff --git a/plugins/passkey_relay_party/storage/migrations/migrate_20240828.go b/plugins/passkey_relay_party/storage/migrations/migrate_20240828.go new file mode 100644 index 0000000..1f4d868 --- /dev/null +++ b/plugins/passkey_relay_party/storage/migrations/migrate_20240828.go @@ -0,0 +1,57 @@ +package migrations + +import ( + "another_node/plugins/passkey_relay_party/storage/model" + + "gorm.io/gorm" +) + +type Migration20240828 struct { +} + +var _ Migration = (*Migration20240828)(nil) + +func (m *Migration20240828) Up(db *gorm.DB) error { + + if !db.Migrator().HasTable(&model.AirAccount{}) { + if err := db.AutoMigrate(&model.AirAccount{}); err != nil { + return err + } + } + + if !db.Migrator().HasTable(&model.AirAccountChain{}) { + if err := db.AutoMigrate(&model.AirAccountChain{}); err != nil { + return err + } + } + + if !db.Migrator().HasTable(&model.Passkey{}) { + if err := db.AutoMigrate(&model.Passkey{}); err != nil { + return err + } + } + + return nil +} + +func (m *Migration20240828) Down(db *gorm.DB) error { + if err := db.Migrator().DropTable( + &model.Passkey{}, + ); err != nil { + return err + } + + if err := db.Migrator().DropTable( + &model.AirAccountChain{}, + ); err != nil { + return err + } + + if err := db.Migrator().DropTable( + &model.AirAccount{}, + ); err != nil { + return err + } + + return nil +} diff --git a/plugins/passkey_relay_party/storage/model/airaccount.go b/plugins/passkey_relay_party/storage/model/airaccount.go new file mode 100644 index 0000000..cb0c5b1 --- /dev/null +++ b/plugins/passkey_relay_party/storage/model/airaccount.go @@ -0,0 +1,14 @@ +package model + +import "another_node/internal/community/storage" + +type AirAccount struct { + storage.BaseData + Email string `json:"email" gorm:"type:varchar(255)"` + Facebook string `json:"facebook" gorm:"type:varchar(255)"` + Twitter string `json:"twitter" gorm:"type:varchar(255)"` +} + +func (AirAccount) TableName() string { + return "airaccounts" +} diff --git a/plugins/passkey_relay_party/storage/model/airaccount_chain.go b/plugins/passkey_relay_party/storage/model/airaccount_chain.go new file mode 100644 index 0000000..5c9735a --- /dev/null +++ b/plugins/passkey_relay_party/storage/model/airaccount_chain.go @@ -0,0 +1,17 @@ +package model + +import "another_node/internal/community/storage" + +type AirAccountChain struct { + storage.BaseData + AirAccountId int64 `json:"airaccount_id" gorm:"column:airaccount_id"` + InitCode string `json:"init_code" gorm:"type:text"` + AA_Address string `json:"aa_address" gorm:"type:varchar(255)"` + EOA_Address string `json:"eoa_address" gorm:"type:varchar(255)"` + Chain string `json:"chain" gorm:"type:varchar(64)"` + WalletVault string `json:"wallet_vault" gorm:"type:text"` +} + +func (AirAccountChain) TableName() string { + return "airaccount_chains" +} diff --git a/plugins/passkey_relay_party/storage/model/passkey.go b/plugins/passkey_relay_party/storage/model/passkey.go new file mode 100644 index 0000000..94d8047 --- /dev/null +++ b/plugins/passkey_relay_party/storage/model/passkey.go @@ -0,0 +1,17 @@ +package model + +import "another_node/internal/community/storage" + +type Passkey struct { + storage.BaseData + AirAccountId int64 `json:"airaccount_id" gorm:"column:airaccount_id"` + PasskeyId string `json:"passkey_id" gorm:"type:varchar(128)"` + PasskeyRawId string `json:"passkey_rawid" gorm:"type:varchar(128)"` + PublicKey string `json:"public_key" gorm:"type:varchar(512)"` + Algorithm string `json:"algorithm" gorm:"type:varchar(64)"` + Origin string `json:"origin" gorm:"type:varchar(255)"` +} + +func (Passkey) TableName() string { + return "passkeys" +}