mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/did accounts (#23)
* feat: add support for DID number as primary key for Controllers * refactor: rename pkg/proxy to app/proxy * feat: add vault module keeper tests * feat(vault): add DID keeper to vault module * refactor: move vault client code to its own package * refactor(vault): extract schema definition * refactor: use vaulttypes for MsgAllocateVault * refactor: update vault assembly logic to use new methods * feat: add dwn-proxy command * refactor: remove unused context.go file * refactor: remove unused web-related code * feat: add DWN proxy server * feat: add BuildTx RPC to vault module * fix: Implement BuildTx endpoint * feat: add devbox integration to project
This commit is contained in:
@@ -1,165 +0,0 @@
|
||||
package dexmodel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/table"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
subtle = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}
|
||||
highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
|
||||
special = lipgloss.AdaptiveColor{Light: "#43BF6D", Dark: "#73F59F"}
|
||||
|
||||
titleStyle = lipgloss.NewStyle().
|
||||
MarginLeft(1).
|
||||
MarginRight(5).
|
||||
Padding(0, 1).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#FFF7DB")).
|
||||
SetString("Cosmos Block Explorer")
|
||||
|
||||
infoStyle = lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.NormalBorder()).
|
||||
BorderTop(true).
|
||||
BorderForeground(subtle)
|
||||
)
|
||||
|
||||
type model struct {
|
||||
blocks []string
|
||||
transactionTable table.Model
|
||||
stats map[string]string
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
columns := []table.Column{
|
||||
{Title: "Hash", Width: 10},
|
||||
{Title: "Type", Width: 15},
|
||||
{Title: "Height", Width: 10},
|
||||
{Title: "Time", Width: 20},
|
||||
}
|
||||
|
||||
rows := []table.Row{
|
||||
{"abc123", "Transfer", "1000", time.Now().Format(time.RFC3339)},
|
||||
{"def456", "Delegate", "999", time.Now().Add(-1 * time.Minute).Format(time.RFC3339)},
|
||||
{"ghi789", "Vote", "998", time.Now().Add(-2 * time.Minute).Format(time.RFC3339)},
|
||||
}
|
||||
|
||||
t := table.New(
|
||||
table.WithColumns(columns),
|
||||
table.WithRows(rows),
|
||||
table.WithFocused(true),
|
||||
table.WithHeight(7),
|
||||
)
|
||||
|
||||
s := table.DefaultStyles()
|
||||
s.Header = s.Header.
|
||||
BorderStyle(lipgloss.NormalBorder()).
|
||||
BorderForeground(lipgloss.Color("240")).
|
||||
BorderBottom(true).
|
||||
Bold(false)
|
||||
s.Selected = s.Selected.
|
||||
Foreground(lipgloss.Color("229")).
|
||||
Background(lipgloss.Color("57")).
|
||||
Bold(false)
|
||||
t.SetStyles(s)
|
||||
|
||||
return model{
|
||||
blocks: []string{"Block 1", "Block 2", "Block 3"},
|
||||
transactionTable: t,
|
||||
stats: map[string]string{
|
||||
"Latest Block": "1000",
|
||||
"Validators": "100",
|
||||
"Bonded Tokens": "1,000,000",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return tick
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q", "ctrl+c":
|
||||
return m, tea.Quit
|
||||
case "enter":
|
||||
return m, tea.Batch(
|
||||
tea.Printf("Selected transaction: %s", m.transactionTable.SelectedRow()[0]),
|
||||
)
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
m.height = msg.Height
|
||||
m.width = msg.Width
|
||||
case tickMsg:
|
||||
// Update data here
|
||||
m.blocks = append([]string{"New Block"}, m.blocks...)
|
||||
if len(m.blocks) > 5 {
|
||||
m.blocks = m.blocks[:5]
|
||||
}
|
||||
|
||||
// Add a new transaction to the table
|
||||
newRow := table.Row{
|
||||
fmt.Sprintf("tx%d", time.Now().Unix()),
|
||||
"NewTxType",
|
||||
fmt.Sprintf("%d", 1000+len(m.transactionTable.Rows())),
|
||||
time.Now().Format(time.RFC3339),
|
||||
}
|
||||
m.transactionTable.SetRows(append([]table.Row{newRow}, m.transactionTable.Rows()...))
|
||||
if len(m.transactionTable.Rows()) > 10 {
|
||||
m.transactionTable.SetRows(m.transactionTable.Rows()[:10])
|
||||
}
|
||||
|
||||
return m, tick
|
||||
}
|
||||
m.transactionTable, cmd = m.transactionTable.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
s := titleStyle.Render("Cosmos Block Explorer")
|
||||
s += "\n\n"
|
||||
|
||||
// Blocks
|
||||
s += lipgloss.NewStyle().Bold(true).Render("Recent Blocks") + "\n"
|
||||
for _, block := range m.blocks {
|
||||
s += "• " + block + "\n"
|
||||
}
|
||||
s += "\n"
|
||||
|
||||
// Transactions
|
||||
s += lipgloss.NewStyle().Bold(true).Render("Recent Transactions") + "\n"
|
||||
s += m.transactionTable.View() + "\n\n"
|
||||
|
||||
// Stats
|
||||
s += lipgloss.NewStyle().Bold(true).Render("Network Statistics") + "\n"
|
||||
for key, value := range m.stats {
|
||||
s += fmt.Sprintf("%s: %s\n", key, value)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
type tickMsg time.Time
|
||||
|
||||
func tick() tea.Msg {
|
||||
time.Sleep(time.Second)
|
||||
return tickMsg{}
|
||||
}
|
||||
|
||||
func RunExplorerTUI(cmd *cobra.Command, args []string) error {
|
||||
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
|
||||
if _, err := p.Run(); err != nil {
|
||||
return fmt.Errorf("error running explorer: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/onsonr/sonr/internal/cli/dexmodel"
|
||||
"github.com/onsonr/sonr/internal/cli/txmodel"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func AddTUICmds(rootCmd *cobra.Command) {
|
||||
rootCmd.AddCommand(newBuildTxnTUICmd())
|
||||
rootCmd.AddCommand(newExplorerTUICmd())
|
||||
}
|
||||
|
||||
func newBuildTxnTUICmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "dash",
|
||||
Short: "TUI for managing the local Sonr validator node",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBody, err := txmodel.RunBuildTxnTUI()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
marshaler := codec.NewProtoCodec(interfaceRegistry)
|
||||
jsonBytes, err := marshaler.MarshalJSON(txBody)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal tx body: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Generated Protobuf Message (JSON format):")
|
||||
fmt.Println(string(jsonBytes))
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newExplorerTUICmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "cosmos-explorer",
|
||||
Short: "A terminal-based Cosmos blockchain explorer",
|
||||
RunE: dexmodel.RunExplorerTUI,
|
||||
}
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
package txmodel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/huh"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
const maxWidth = 100
|
||||
|
||||
var (
|
||||
red = lipgloss.AdaptiveColor{Light: "#FE5F86", Dark: "#FE5F86"}
|
||||
indigo = lipgloss.AdaptiveColor{Light: "#5A56E0", Dark: "#7571F9"}
|
||||
green = lipgloss.AdaptiveColor{Light: "#02BA84", Dark: "#02BF87"}
|
||||
)
|
||||
|
||||
type Styles struct {
|
||||
Base,
|
||||
HeaderText,
|
||||
Status,
|
||||
StatusHeader,
|
||||
Highlight,
|
||||
ErrorHeaderText,
|
||||
Help lipgloss.Style
|
||||
}
|
||||
|
||||
func NewStyles(lg *lipgloss.Renderer) *Styles {
|
||||
s := Styles{}
|
||||
s.Base = lg.NewStyle().
|
||||
Padding(1, 2, 0, 1)
|
||||
s.HeaderText = lg.NewStyle().
|
||||
Foreground(indigo).
|
||||
Bold(true).
|
||||
Padding(0, 1, 0, 1)
|
||||
s.Status = lg.NewStyle().
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(indigo).
|
||||
PaddingLeft(1).
|
||||
MarginTop(1)
|
||||
s.StatusHeader = lg.NewStyle().
|
||||
Foreground(green).
|
||||
Bold(true)
|
||||
s.Highlight = lg.NewStyle().
|
||||
Foreground(lipgloss.Color("212"))
|
||||
s.ErrorHeaderText = s.HeaderText.
|
||||
Foreground(red)
|
||||
s.Help = lg.NewStyle().
|
||||
Foreground(lipgloss.Color("240"))
|
||||
return &s
|
||||
}
|
||||
|
||||
type state int
|
||||
|
||||
const (
|
||||
statusNormal state = iota
|
||||
stateDone
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
state state
|
||||
lg *lipgloss.Renderer
|
||||
styles *Styles
|
||||
form *huh.Form
|
||||
width int
|
||||
message *tx.TxBody
|
||||
}
|
||||
|
||||
func NewModel() Model {
|
||||
m := Model{width: maxWidth}
|
||||
m.lg = lipgloss.DefaultRenderer()
|
||||
m.styles = NewStyles(m.lg)
|
||||
|
||||
m.form = huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewInput().
|
||||
Key("from").
|
||||
Title("From Address").
|
||||
Placeholder("cosmos1...").
|
||||
Validate(func(s string) error {
|
||||
if !strings.HasPrefix(s, "cosmos1") {
|
||||
return fmt.Errorf("invalid address format")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
|
||||
huh.NewInput().
|
||||
Key("to").
|
||||
Title("To Address").
|
||||
Placeholder("cosmos1...").
|
||||
Validate(func(s string) error {
|
||||
if !strings.HasPrefix(s, "cosmos1") {
|
||||
return fmt.Errorf("invalid address format")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
|
||||
huh.NewInput().
|
||||
Key("amount").
|
||||
Title("Amount").
|
||||
Placeholder("100").
|
||||
Validate(func(s string) error {
|
||||
if _, err := sdk.ParseCoinNormalized(s + "atom"); err != nil {
|
||||
return fmt.Errorf("invalid coin amount")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
|
||||
huh.NewSelect[string]().
|
||||
Key("denom").
|
||||
Title("Denom").
|
||||
Options(huh.NewOptions("atom", "osmo", "usnr", "snr")...),
|
||||
|
||||
huh.NewInput().
|
||||
Key("memo").
|
||||
Title("Memo").
|
||||
Placeholder("Optional"),
|
||||
|
||||
huh.NewConfirm().
|
||||
Key("done").
|
||||
Title("Ready to convert?").
|
||||
Validate(func(v bool) error {
|
||||
if !v {
|
||||
return fmt.Errorf("Please confirm when you're ready to convert")
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
Affirmative("Yes, convert!").
|
||||
Negative("Not yet"),
|
||||
),
|
||||
).
|
||||
WithWidth(60).
|
||||
WithShowHelp(false).
|
||||
WithShowErrors(false)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
return m.form.Init()
|
||||
}
|
||||
|
||||
func min(x, y int) int {
|
||||
if x > y {
|
||||
return y
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.width = min(msg.Width, maxWidth) - m.styles.Base.GetHorizontalFrameSize()
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc", "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
||||
var cmds []tea.Cmd
|
||||
|
||||
form, cmd := m.form.Update(msg)
|
||||
if f, ok := form.(*huh.Form); ok {
|
||||
m.form = f
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
|
||||
if m.form.State == huh.StateCompleted {
|
||||
m.buildMessage()
|
||||
cmds = append(cmds, tea.Quit)
|
||||
}
|
||||
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
s := m.styles
|
||||
|
||||
switch m.form.State {
|
||||
case huh.StateCompleted:
|
||||
pklCode := m.generatePkl()
|
||||
messageView := m.getMessageView()
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "Final Tx:\n\n%s\n\n%s", pklCode, messageView)
|
||||
return s.Status.Margin(0, 1).Padding(1, 2).Width(80).Render(b.String()) + "\n\n"
|
||||
default:
|
||||
var schemaType string
|
||||
if m.form.GetString("schemaType") != "" {
|
||||
schemaType = "Schema Type: " + m.form.GetString("schemaType")
|
||||
}
|
||||
|
||||
v := strings.TrimSuffix(m.form.View(), "\n\n")
|
||||
form := m.lg.NewStyle().Margin(1, 0).Render(v)
|
||||
|
||||
var status string
|
||||
{
|
||||
preview := "(Preview will appear here)"
|
||||
if m.form.GetString("schema") != "" {
|
||||
preview = m.generatePkl()
|
||||
}
|
||||
|
||||
const statusWidth = 40
|
||||
statusMarginLeft := m.width - statusWidth - lipgloss.Width(form) - s.Status.GetMarginRight()
|
||||
status = s.Status.
|
||||
Height(lipgloss.Height(form)).
|
||||
Width(statusWidth).
|
||||
MarginLeft(statusMarginLeft).
|
||||
Render(s.StatusHeader.Render("Pkl Preview") + "\n" +
|
||||
schemaType + "\n\n" +
|
||||
preview)
|
||||
}
|
||||
|
||||
errors := m.form.Errors()
|
||||
header := m.appBoundaryView("Sonr TX Builder")
|
||||
if len(errors) > 0 {
|
||||
header = m.appErrorBoundaryView(m.errorView())
|
||||
}
|
||||
body := lipgloss.JoinHorizontal(lipgloss.Top, form, status)
|
||||
|
||||
footer := m.appBoundaryView(m.form.Help().ShortHelpView(m.form.KeyBinds()))
|
||||
if len(errors) > 0 {
|
||||
footer = m.appErrorBoundaryView("")
|
||||
}
|
||||
|
||||
return s.Base.Render(header + "\n" + body + "\n\n" + footer)
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) errorView() string {
|
||||
var s string
|
||||
for _, err := range m.form.Errors() {
|
||||
s += err.Error()
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (m Model) appBoundaryView(text string) string {
|
||||
return lipgloss.PlaceHorizontal(
|
||||
m.width,
|
||||
lipgloss.Left,
|
||||
m.styles.HeaderText.Render(text),
|
||||
lipgloss.WithWhitespaceChars("="),
|
||||
lipgloss.WithWhitespaceForeground(indigo),
|
||||
)
|
||||
}
|
||||
|
||||
func (m Model) appErrorBoundaryView(text string) string {
|
||||
return lipgloss.PlaceHorizontal(
|
||||
m.width,
|
||||
lipgloss.Left,
|
||||
m.styles.ErrorHeaderText.Render(text),
|
||||
lipgloss.WithWhitespaceChars("="),
|
||||
lipgloss.WithWhitespaceForeground(red),
|
||||
)
|
||||
}
|
||||
|
||||
func (m Model) generatePkl() string {
|
||||
schemaType := m.form.GetString("schemaType")
|
||||
schema := m.form.GetString("schema")
|
||||
|
||||
// This is a placeholder for the actual conversion logic
|
||||
// In a real implementation, you would parse the schema and generate Pkl code
|
||||
return fmt.Sprintf("// Converted from %s\n\nclass ConvertedSchema {\n // TODO: Implement conversion from %s\n // Original schema:\n /*\n%s\n */\n}", schemaType, schemaType, schema)
|
||||
}
|
||||
|
||||
func (m *Model) buildMessage() {
|
||||
from := m.form.GetString("from")
|
||||
to := m.form.GetString("to")
|
||||
amount := m.form.GetString("amount")
|
||||
denom := m.form.GetString("denom")
|
||||
memo := m.form.GetString("memo")
|
||||
|
||||
coin, _ := sdk.ParseCoinNormalized(fmt.Sprintf("%s%s", amount, denom))
|
||||
sendMsg := &banktypes.MsgSend{
|
||||
FromAddress: from,
|
||||
ToAddress: to,
|
||||
Amount: sdk.NewCoins(coin),
|
||||
}
|
||||
|
||||
anyMsg, _ := codectypes.NewAnyWithValue(sendMsg)
|
||||
m.message = &tx.TxBody{
|
||||
Messages: []*codectypes.Any{anyMsg},
|
||||
Memo: memo,
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) getMessageView() string {
|
||||
if m.message == nil {
|
||||
return "Current Message: None"
|
||||
}
|
||||
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
marshaler := codec.NewProtoCodec(interfaceRegistry)
|
||||
jsonBytes, _ := marshaler.MarshalJSON(m.message)
|
||||
|
||||
return fmt.Sprintf("Current Message:\n%s", string(jsonBytes))
|
||||
}
|
||||
|
||||
func RunBuildTxnTUI() (*tx.TxBody, error) {
|
||||
m := NewModel()
|
||||
p := tea.NewProgram(m)
|
||||
|
||||
finalModel, err := p.Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to run program: %w", err)
|
||||
}
|
||||
|
||||
finalM, ok := finalModel.(Model)
|
||||
if !ok || finalM.message == nil {
|
||||
return nil, fmt.Errorf("form not completed")
|
||||
}
|
||||
|
||||
return finalM.message, nil
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
promise "github.com/nlepage/go-js-promise"
|
||||
"github.com/onsonr/sonr/internal/dwn/middleware"
|
||||
"github.com/onsonr/sonr/internal/dwn/state"
|
||||
"github.com/onsonr/sonr/pkg/nebula"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.Use(middleware.UseSession)
|
||||
nebula.RegisterHandlers(e)
|
||||
state.RegisterHandlers(e)
|
||||
Serve(e)
|
||||
}
|
||||
|
||||
// Serve serves HTTP requests using handler or http.DefaultServeMux if handler is nil.
|
||||
func Serve(handler http.Handler) func() {
|
||||
h := handler
|
||||
if h == nil {
|
||||
h = http.DefaultServeMux
|
||||
}
|
||||
|
||||
prefix := js.Global().Get("wasmhttp").Get("path").String()
|
||||
for strings.HasSuffix(prefix, "/") {
|
||||
prefix = strings.TrimSuffix(prefix, "/")
|
||||
}
|
||||
|
||||
if prefix != "" {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle(prefix+"/", http.StripPrefix(prefix, h))
|
||||
h = mux
|
||||
}
|
||||
|
||||
cb := js.FuncOf(func(_ js.Value, args []js.Value) interface{} {
|
||||
resPromise, resolve, reject := promise.New()
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if err, ok := r.(error); ok {
|
||||
reject(fmt.Sprintf("wasmhttp: panic: %+v\n", err))
|
||||
} else {
|
||||
reject(fmt.Sprintf("wasmhttp: panic: %v\n", r))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
res := NewResponseRecorder()
|
||||
|
||||
h.ServeHTTP(res, Request(args[0]))
|
||||
|
||||
resolve(res.JSResponse())
|
||||
}()
|
||||
|
||||
return resPromise
|
||||
})
|
||||
|
||||
js.Global().Get("wasmhttp").Call("setHandler", cb)
|
||||
|
||||
return cb.Release
|
||||
}
|
||||
|
||||
// Request builds and returns the equivalent http.Request
|
||||
func Request(r js.Value) *http.Request {
|
||||
jsBody := js.Global().Get("Uint8Array").New(promise.Await(r.Call("arrayBuffer")))
|
||||
body := make([]byte, jsBody.Get("length").Int())
|
||||
js.CopyBytesToGo(body, jsBody)
|
||||
|
||||
req := httptest.NewRequest(
|
||||
r.Get("method").String(),
|
||||
r.Get("url").String(),
|
||||
bytes.NewBuffer(body),
|
||||
)
|
||||
|
||||
headersIt := r.Get("headers").Call("entries")
|
||||
for {
|
||||
e := headersIt.Call("next")
|
||||
if e.Get("done").Bool() {
|
||||
break
|
||||
}
|
||||
v := e.Get("value")
|
||||
req.Header.Set(v.Index(0).String(), v.Index(1).String())
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
|
||||
// ResponseRecorder uses httptest.ResponseRecorder to build a JS Response
|
||||
type ResponseRecorder struct {
|
||||
*httptest.ResponseRecorder
|
||||
}
|
||||
|
||||
// NewResponseRecorder returns a new ResponseRecorder
|
||||
func NewResponseRecorder() ResponseRecorder {
|
||||
return ResponseRecorder{httptest.NewRecorder()}
|
||||
}
|
||||
|
||||
// JSResponse builds and returns the equivalent JS Response
|
||||
func (rr ResponseRecorder) JSResponse() js.Value {
|
||||
res := rr.Result()
|
||||
|
||||
body := js.Undefined()
|
||||
if res.ContentLength != 0 {
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
body = js.Global().Get("Uint8Array").New(len(b))
|
||||
js.CopyBytesToJS(body, b)
|
||||
}
|
||||
|
||||
init := make(map[string]interface{}, 2)
|
||||
|
||||
if res.StatusCode != 0 {
|
||||
init["status"] = res.StatusCode
|
||||
}
|
||||
|
||||
if len(res.Header) != 0 {
|
||||
headers := make(map[string]interface{}, len(res.Header))
|
||||
for k := range res.Header {
|
||||
headers[k] = res.Header.Get(k)
|
||||
}
|
||||
init["headers"] = headers
|
||||
}
|
||||
|
||||
return js.Global().Get("Response").New(body, init)
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package middleware
|
||||
|
||||
type RequestHeaders struct {
|
||||
Authorization *string `header:"Authorization"`
|
||||
CacheControl *string `header:"Cache-Control"`
|
||||
DeviceMemory *string `header:"Device-Memory"`
|
||||
Forwarded *string `header:"Forwarded"`
|
||||
From *string `header:"From"`
|
||||
Host *string `header:"Host"`
|
||||
Link *string `header:"Link"`
|
||||
PermissionsPolicy *string `header:"Permissions-Policy"`
|
||||
ProxyAuthorization *string `header:"Proxy-Authorization"`
|
||||
Referer *string `header:"Referer"`
|
||||
UserAgent *string `header:"User-Agent"`
|
||||
ViewportWidth *string `header:"Viewport-Width"`
|
||||
Width *string `header:"Width"`
|
||||
WWWAuthenticate *string `header:"WWW-Authenticate"`
|
||||
|
||||
// HTMX Specific
|
||||
HXBoosted *string `header:"HX-Boosted"`
|
||||
HXCurrentURL *string `header:"HX-Current-URL"`
|
||||
HXHistoryRestoreRequest *string `header:"HX-History-Restore-Request"`
|
||||
HXPrompt *string `header:"HX-Prompt"`
|
||||
HXRequest *string `header:"HX-Request"`
|
||||
HXTarget *string `header:"HX-Target"`
|
||||
HXTriggerName *string `header:"HX-Trigger-Name"`
|
||||
HXTrigger *string `header:"HX-Trigger"`
|
||||
}
|
||||
|
||||
type ResponseHeaders struct {
|
||||
AcceptCH *string `header:"Accept-CH"`
|
||||
AccessControlAllowCredentials *string `header:"Access-Control-Allow-Credentials"`
|
||||
AccessControlAllowHeaders *string `header:"Access-Control-Allow-Headers"`
|
||||
AccessControlAllowMethods *string `header:"Access-Control-Allow-Methods"`
|
||||
AccessControlExposeHeaders *string `header:"Access-Control-Expose-Headers"`
|
||||
AccessControlRequestHeaders *string `header:"Access-Control-Request-Headers"`
|
||||
ContentSecurityPolicy *string `header:"Content-Security-Policy"`
|
||||
CrossOriginEmbedderPolicy *string `header:"Cross-Origin-Embedder-Policy"`
|
||||
PermissionsPolicy *string `header:"Permissions-Policy"`
|
||||
ProxyAuthorization *string `header:"Proxy-Authorization"`
|
||||
WWWAuthenticate *string `header:"WWW-Authenticate"`
|
||||
|
||||
// HTMX Specific
|
||||
HXLocation *string `header:"HX-Location"`
|
||||
HXPushURL *string `header:"HX-Push-Url"`
|
||||
HXRedirect *string `header:"HX-Redirect"`
|
||||
HXRefresh *string `header:"HX-Refresh"`
|
||||
HXReplaceURL *string `header:"HX-Replace-Url"`
|
||||
HXReswap *string `header:"HX-Reswap"`
|
||||
HXRetarget *string `header:"HX-Retarget"`
|
||||
HXReselect *string `header:"HX-Reselect"`
|
||||
HXTrigger *string `header:"HX-Trigger"`
|
||||
HXTriggerAfterSettle *string `header:"HX-Trigger-After-Settle"`
|
||||
HXTriggerAfterSwap *string `header:"HX-Trigger-After-Swap"`
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"gopkg.in/macaroon.v2"
|
||||
)
|
||||
|
||||
// GetSession returns the current Session
|
||||
func GetSession(c echo.Context) *Session {
|
||||
return c.(*Session)
|
||||
}
|
||||
|
||||
// UseSession establishes a Session Cookie.
|
||||
func UseSession(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
sc := initSession(c)
|
||||
headers := new(RequestHeaders)
|
||||
sc.Bind(headers)
|
||||
return next(sc)
|
||||
}
|
||||
}
|
||||
|
||||
func MacaroonMiddleware(secretKeyStr string, location string) echo.MiddlewareFunc {
|
||||
secretKey := []byte(secretKeyStr)
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// Extract the macaroon from the Authorization header
|
||||
auth := c.Request().Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "Missing Authorization header"})
|
||||
}
|
||||
|
||||
// Decode the macaroon
|
||||
mac, err := macaroon.Base64Decode([]byte(auth))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid macaroon encoding"})
|
||||
}
|
||||
|
||||
token, err := macaroon.New(secretKey, mac, location, macaroon.LatestVersion)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid macaroon"})
|
||||
}
|
||||
|
||||
// Verify the macaroon
|
||||
err = token.Verify(secretKey, func(caveat string) error {
|
||||
for _, c := range MacroonCaveats {
|
||||
if c.String() == caveat {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil // Return nil if the caveat is valid
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "Invalid macaroon"})
|
||||
}
|
||||
|
||||
// Macaroon is valid, proceed to the next handler
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/donseba/go-htmx"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/segmentio/ksuid"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
echo.Context
|
||||
htmx *htmx.HTMX
|
||||
}
|
||||
|
||||
func (c *Session) Htmx() *htmx.HTMX {
|
||||
return c.htmx
|
||||
}
|
||||
|
||||
func (c *Session) ID() string {
|
||||
return ReadCookie(c, "session")
|
||||
}
|
||||
|
||||
func initSession(c echo.Context) *Session {
|
||||
s := &Session{Context: c}
|
||||
if val := ReadCookie(c, "session"); val == "" {
|
||||
id := ksuid.New().String()
|
||||
WriteCookie(c, "session", id)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func ReadCookie(c echo.Context, key string) string {
|
||||
cookie, err := c.Cookie(key)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if cookie == nil {
|
||||
return ""
|
||||
}
|
||||
return cookie.Value
|
||||
}
|
||||
|
||||
func WriteCookie(c echo.Context, key string, value string) {
|
||||
cookie := new(http.Cookie)
|
||||
cookie.Name = key
|
||||
cookie.Value = value
|
||||
cookie.Expires = time.Now().Add(24 * time.Hour)
|
||||
c.SetCookie(cookie)
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
OriginMacroonCaveat MacroonCaveat = "origin"
|
||||
ScopesMacroonCaveat MacroonCaveat = "scopes"
|
||||
SubjectMacroonCaveat MacroonCaveat = "subject"
|
||||
ExpMacroonCaveat MacroonCaveat = "exp"
|
||||
TokenMacroonCaveat MacroonCaveat = "token"
|
||||
)
|
||||
|
||||
type MacroonCaveat string
|
||||
|
||||
func (c MacroonCaveat) Equal(other string) bool {
|
||||
return string(c) == other
|
||||
}
|
||||
|
||||
func (c MacroonCaveat) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (c MacroonCaveat) Verify(value string) error {
|
||||
switch c {
|
||||
case OriginMacroonCaveat:
|
||||
return nil
|
||||
case ScopesMacroonCaveat:
|
||||
return nil
|
||||
case SubjectMacroonCaveat:
|
||||
return nil
|
||||
case ExpMacroonCaveat:
|
||||
// Check if the expiration time is still valid
|
||||
exp, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if time.Now().After(exp) {
|
||||
return fmt.Errorf("expired")
|
||||
}
|
||||
return nil
|
||||
case TokenMacroonCaveat:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unknown caveat: %s", c)
|
||||
}
|
||||
}
|
||||
|
||||
var MacroonCaveats = []MacroonCaveat{OriginMacroonCaveat, ScopesMacroonCaveat, SubjectMacroonCaveat, ExpMacroonCaveat, TokenMacroonCaveat}
|
||||
@@ -1,43 +0,0 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func checkSubjectIsValid(e echo.Context) error {
|
||||
credentialID := e.FormValue("credentialID")
|
||||
return e.JSON(200, credentialID)
|
||||
}
|
||||
|
||||
func handleCredentialAssertion(e echo.Context) error {
|
||||
return e.JSON(200, "HandleCredentialAssertion")
|
||||
}
|
||||
|
||||
func handleCredentialCreation(e echo.Context) error {
|
||||
// Get the serialized credential data from the form
|
||||
credentialDataJSON := e.FormValue("credentialData")
|
||||
|
||||
// Deserialize the JSON into a temporary struct
|
||||
var ccr protocol.CredentialCreationResponse
|
||||
err := json.Unmarshal([]byte(credentialDataJSON), &ccr)
|
||||
if err != nil {
|
||||
return e.JSON(500, err.Error())
|
||||
}
|
||||
//
|
||||
// // Parse the CredentialCreationResponse
|
||||
// parsedData, err := ccr.Parse()
|
||||
// if err != nil {
|
||||
// return e.JSON(500, err.Error())
|
||||
// }
|
||||
//
|
||||
// // Create the Credential
|
||||
// // credential := orm.NewCredential(parsedData, e.Request().Host, "")
|
||||
//
|
||||
// // Set additional fields
|
||||
// credential.Controller = "" // Set this to the appropriate controller value
|
||||
return e.JSON(200, fmt.Sprintf("REGISTER: %s", string(ccr.ID)))
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package state
|
||||
@@ -1,23 +0,0 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func grantAuthorization(e echo.Context) error {
|
||||
// Implement authorization endpoint using passkey authentication
|
||||
// Store session data in cache
|
||||
return nil
|
||||
}
|
||||
|
||||
func getJWKS(e echo.Context) error {
|
||||
// Implement token endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func getToken(e echo.Context) error {
|
||||
// Implement token endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
middleware "github.com/onsonr/sonr/internal/dwn/middleware"
|
||||
)
|
||||
|
||||
func RegisterHandlers(e *echo.Echo) {
|
||||
g := e.Group("state")
|
||||
g.POST("/login/:identifier", handleCredentialAssertion)
|
||||
// g.GET("/discovery", state.GetDiscovery)
|
||||
g.GET("/jwks", getJWKS)
|
||||
g.GET("/token", getToken)
|
||||
g.POST("/:origin/grant/:subject", grantAuthorization)
|
||||
g.POST("/register/:subject", handleCredentialCreation)
|
||||
g.POST("/register/:subject/check", checkSubjectIsValid)
|
||||
}
|
||||
|
||||
func RegisterSync(e *echo.Echo) {
|
||||
g := e.Group("sync")
|
||||
g.Use(middleware.MacaroonMiddleware("test", "test"))
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package state
|
||||
@@ -1 +0,0 @@
|
||||
package state
|
||||
@@ -1,20 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Account struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Name string `pkl:"name" json:"name,omitempty"`
|
||||
|
||||
Address any `pkl:"address" json:"address,omitempty"`
|
||||
|
||||
PublicKey string `pkl:"publicKey" json:"publicKey,omitempty"`
|
||||
|
||||
ChainCode uint `pkl:"chainCode" json:"chainCode,omitempty"`
|
||||
|
||||
Index int `pkl:"index" json:"index,omitempty"`
|
||||
|
||||
Controller string `pkl:"controller" json:"controller,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Asset struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Name string `pkl:"name" json:"name,omitempty"`
|
||||
|
||||
Symbol string `pkl:"symbol" json:"symbol,omitempty"`
|
||||
|
||||
Decimals int `pkl:"decimals" json:"decimals,omitempty"`
|
||||
|
||||
ChainCode uint `pkl:"chainCode" json:"chainCode,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Chain struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Name string `pkl:"name" json:"name,omitempty"`
|
||||
|
||||
NetworkId string `pkl:"networkId" json:"networkId,omitempty"`
|
||||
|
||||
ChainCode uint `pkl:"chainCode" json:"chainCode,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Credential struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Subject string `pkl:"subject" json:"subject,omitempty"`
|
||||
|
||||
Controller string `pkl:"controller" json:"controller,omitempty"`
|
||||
|
||||
AttestationType string `pkl:"attestationType" json:"attestationType,omitempty"`
|
||||
|
||||
Origin string `pkl:"origin" json:"origin,omitempty"`
|
||||
|
||||
Label *string `pkl:"label" json:"label,omitempty"`
|
||||
|
||||
DeviceId *string `pkl:"deviceId" json:"deviceId,omitempty"`
|
||||
|
||||
CredentialId string `pkl:"credentialId" json:"credentialId,omitempty"`
|
||||
|
||||
PublicKey string `pkl:"publicKey" json:"publicKey,omitempty"`
|
||||
|
||||
Transport []string `pkl:"transport" json:"transport,omitempty"`
|
||||
|
||||
SignCount uint `pkl:"signCount" json:"signCount,omitempty"`
|
||||
|
||||
UserPresent bool `pkl:"userPresent" json:"userPresent,omitempty"`
|
||||
|
||||
UserVerified bool `pkl:"userVerified" json:"userVerified,omitempty"`
|
||||
|
||||
BackupEligible bool `pkl:"backupEligible" json:"backupEligible,omitempty"`
|
||||
|
||||
BackupState bool `pkl:"backupState" json:"backupState,omitempty"`
|
||||
|
||||
CloneWarning bool `pkl:"cloneWarning" json:"cloneWarning,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
|
||||
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty"`
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Grant struct {
|
||||
Id uint `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Subject string `pkl:"subject" json:"subject,omitempty"`
|
||||
|
||||
Controller string `pkl:"controller" json:"controller,omitempty"`
|
||||
|
||||
Origin string `pkl:"origin" json:"origin,omitempty"`
|
||||
|
||||
Token string `pkl:"token" json:"token,omitempty"`
|
||||
|
||||
Scopes []string `pkl:"scopes" json:"scopes,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
|
||||
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type JWK struct {
|
||||
Kty string `pkl:"kty" json:"kty,omitempty"`
|
||||
|
||||
Crv string `pkl:"crv" json:"crv,omitempty"`
|
||||
|
||||
X string `pkl:"x" json:"x,omitempty"`
|
||||
|
||||
Y string `pkl:"y" json:"y,omitempty"`
|
||||
|
||||
N string `pkl:"n" json:"n,omitempty"`
|
||||
|
||||
E string `pkl:"e" json:"e,omitempty"`
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Keyshare struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Data string `pkl:"data" json:"data,omitempty"`
|
||||
|
||||
Role int `pkl:"role" json:"role,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
|
||||
LastRefreshed *string `pkl:"lastRefreshed" json:"lastRefreshed,omitempty"`
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/apple/pkl-go/pkl"
|
||||
)
|
||||
|
||||
type Orm struct {
|
||||
DbName string `pkl:"db_name"`
|
||||
|
||||
DbVersion int `pkl:"db_version"`
|
||||
}
|
||||
|
||||
// LoadFromPath loads the pkl module at the given path and evaluates it into a Orm
|
||||
func LoadFromPath(ctx context.Context, path string) (ret *Orm, err error) {
|
||||
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
cerr := evaluator.Close()
|
||||
if err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Orm
|
||||
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Orm, error) {
|
||||
var ret Orm
|
||||
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
type Profile struct {
|
||||
Id string `pkl:"id" json:"id,omitempty" query:"id"`
|
||||
|
||||
Subject string `pkl:"subject" json:"subject,omitempty"`
|
||||
|
||||
Controller string `pkl:"controller" json:"controller,omitempty"`
|
||||
|
||||
OriginUri *string `pkl:"originUri" json:"originUri,omitempty"`
|
||||
|
||||
PublicMetadata *string `pkl:"publicMetadata" json:"publicMetadata,omitempty"`
|
||||
|
||||
PrivateMetadata *string `pkl:"privateMetadata" json:"privateMetadata,omitempty"`
|
||||
|
||||
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty"`
|
||||
|
||||
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty"`
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/internal/orm/keyalgorithm"
|
||||
"github.com/onsonr/sonr/internal/orm/keycurve"
|
||||
"github.com/onsonr/sonr/internal/orm/keyencoding"
|
||||
"github.com/onsonr/sonr/internal/orm/keyrole"
|
||||
"github.com/onsonr/sonr/internal/orm/keytype"
|
||||
)
|
||||
|
||||
type PublicKey struct {
|
||||
Role keyrole.KeyRole `pkl:"role" json:"role,omitempty" query:"role"`
|
||||
|
||||
Algorithm keyalgorithm.KeyAlgorithm `pkl:"algorithm"`
|
||||
|
||||
Encoding keyencoding.KeyEncoding `pkl:"encoding"`
|
||||
|
||||
Curve keycurve.KeyCurve `pkl:"curve"`
|
||||
|
||||
KeyType keytype.KeyType `pkl:"key_type"`
|
||||
|
||||
Raw string `pkl:"raw"`
|
||||
|
||||
Jwk *JWK `pkl:"jwk"`
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package assettype
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type AssetType string
|
||||
|
||||
const (
|
||||
Native AssetType = "native"
|
||||
Wrapped AssetType = "wrapped"
|
||||
Staking AssetType = "staking"
|
||||
Pool AssetType = "pool"
|
||||
Ibc AssetType = "ibc"
|
||||
Cw20 AssetType = "cw20"
|
||||
)
|
||||
|
||||
// String returns the string representation of AssetType
|
||||
func (rcv AssetType) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(AssetType)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for AssetType.
|
||||
func (rcv *AssetType) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "native":
|
||||
*rcv = Native
|
||||
case "wrapped":
|
||||
*rcv = Wrapped
|
||||
case "staking":
|
||||
*rcv = Staking
|
||||
case "pool":
|
||||
*rcv = Pool
|
||||
case "ibc":
|
||||
*rcv = Ibc
|
||||
case "cw20":
|
||||
*rcv = Cw20
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid AssetType`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha512"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/onsonr/sonr/internal/orm/didmethod"
|
||||
)
|
||||
|
||||
type ChainCode uint32
|
||||
|
||||
func GetChainCode(m didmethod.DIDMethod) ChainCode {
|
||||
switch m {
|
||||
case didmethod.Bitcoin:
|
||||
return 0 // 0
|
||||
case didmethod.Ethereum:
|
||||
return 64 // 60
|
||||
case didmethod.Ibc:
|
||||
return 118 // 118
|
||||
case didmethod.Sonr:
|
||||
return 703 // 703
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func FormatAddress(pubKey *PublicKey, m didmethod.DIDMethod) (string, error) {
|
||||
hexPubKey, err := hex.DecodeString(pubKey.Raw)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// switch m {
|
||||
// case didmethod.Bitcoin:
|
||||
// return bech32.Encode("bc", pubKey.Bytes())
|
||||
//
|
||||
// case didmethod.Ethereum:
|
||||
// epk, err := pubKey.ECDSA()
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return ComputeEthAddress(*epk), nil
|
||||
//
|
||||
// case didmethod.Sonr:
|
||||
// return bech32.Encode("idx", hexPubKey)
|
||||
//
|
||||
// case didmethod.Ibc:
|
||||
// return bech32.Encode("cosmos", hexPubKey)
|
||||
//
|
||||
// }
|
||||
return string(hexPubKey), nil
|
||||
}
|
||||
|
||||
// ComputeAccountPublicKey computes the public key of a child key given the extended public key, chain code, and index.
|
||||
func ComputeBip32AccountPublicKey(extPubKey PublicKey, chainCode ChainCode, index int) (*PublicKey, error) {
|
||||
// Check if the index is a hardened child key
|
||||
if chainCode&0x80000000 != 0 && index < 0 {
|
||||
return nil, errors.New("invalid index")
|
||||
}
|
||||
|
||||
hexPubKey, err := hex.DecodeString(extPubKey.Raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Serialize the public key
|
||||
pubKey, err := btcec.ParsePubKey(hexPubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pubKeyBytes := pubKey.SerializeCompressed()
|
||||
|
||||
// Serialize the index
|
||||
indexBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(indexBytes, uint32(index))
|
||||
|
||||
// Compute the HMAC-SHA512
|
||||
mac := hmac.New(sha512.New, []byte{byte(chainCode)})
|
||||
mac.Write(pubKeyBytes)
|
||||
mac.Write(indexBytes)
|
||||
I := mac.Sum(nil)
|
||||
|
||||
// Split I into two 32-byte sequences
|
||||
IL := I[:32]
|
||||
|
||||
// Convert IL to a big integer
|
||||
ilNum := new(big.Int).SetBytes(IL)
|
||||
|
||||
// Check if parse256(IL) >= n
|
||||
curve := btcec.S256()
|
||||
if ilNum.Cmp(curve.N) >= 0 {
|
||||
return nil, errors.New("invalid child key")
|
||||
}
|
||||
|
||||
// Compute the child public key
|
||||
ilx, ily := curve.ScalarBaseMult(IL)
|
||||
childX, childY := curve.Add(ilx, ily, pubKey.X(), pubKey.Y())
|
||||
lx := newBigIntFieldVal(childX)
|
||||
ly := newBigIntFieldVal(childY)
|
||||
|
||||
// Create the child public key
|
||||
_ = btcec.NewPublicKey(lx, ly)
|
||||
return &PublicKey{}, nil
|
||||
}
|
||||
|
||||
// newBigIntFieldVal creates a new field value from a big integer.
|
||||
func newBigIntFieldVal(val *big.Int) *btcec.FieldVal {
|
||||
lx := new(btcec.FieldVal)
|
||||
lx.SetByteSlice(val.Bytes())
|
||||
return lx
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type AuthenticatorSelectionCriteria struct {
|
||||
AuthenticatorAttachment string `pkl:"authenticatorAttachment"`
|
||||
|
||||
RequireResidentKey bool `pkl:"requireResidentKey"`
|
||||
|
||||
UserVerification string `pkl:"userVerification"`
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/apple/pkl-go/pkl"
|
||||
)
|
||||
|
||||
type Browser struct {
|
||||
}
|
||||
|
||||
// LoadFromPath loads the pkl module at the given path and evaluates it into a Browser
|
||||
func LoadFromPath(ctx context.Context, path string) (ret *Browser, err error) {
|
||||
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
cerr := evaluator.Close()
|
||||
if err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Browser
|
||||
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Browser, error) {
|
||||
var ret Browser
|
||||
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type PublicKeyCredentialCreationOptions struct {
|
||||
Rp *RpEntity `pkl:"rp"`
|
||||
|
||||
User *UserEntity `pkl:"user"`
|
||||
|
||||
Challenge string `pkl:"challenge"`
|
||||
|
||||
PubKeyCredParams []*PublicKeyCredentialParameters `pkl:"pubKeyCredParams"`
|
||||
|
||||
Timeout int `pkl:"timeout"`
|
||||
|
||||
ExcludeCredentials []*PublicKeyCredentialDescriptor `pkl:"excludeCredentials"`
|
||||
|
||||
AuthenticatorSelection *AuthenticatorSelectionCriteria `pkl:"authenticatorSelection"`
|
||||
|
||||
Attestation string `pkl:"attestation"`
|
||||
|
||||
Extensions []*PublicKeyCredentialParameters `pkl:"extensions"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type PublicKeyCredentialDescriptor struct {
|
||||
Id string `pkl:"id"`
|
||||
|
||||
Transports []string `pkl:"transports"`
|
||||
|
||||
Type string `pkl:"type"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type PublicKeyCredentialParameters struct {
|
||||
Type string `pkl:"type"`
|
||||
|
||||
Alg *int `pkl:"alg"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type PublicKeyCredentialRequestOptions struct {
|
||||
Challenge string `pkl:"challenge"`
|
||||
|
||||
Timeout int `pkl:"timeout"`
|
||||
|
||||
RpId string `pkl:"rpId"`
|
||||
|
||||
AllowCredentials []*PublicKeyCredentialDescriptor `pkl:"allowCredentials"`
|
||||
|
||||
UserVerification string `pkl:"userVerification"`
|
||||
|
||||
Extensions []*PublicKeyCredentialParameters `pkl:"extensions"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type RpEntity struct {
|
||||
Id string `pkl:"id"`
|
||||
|
||||
Name *string `pkl:"name"`
|
||||
|
||||
Icon *string `pkl:"icon"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type SWT struct {
|
||||
Origin string `pkl:"origin"`
|
||||
|
||||
Location string `pkl:"location"`
|
||||
|
||||
Identifier string `pkl:"identifier"`
|
||||
|
||||
Scopes []string `pkl:"scopes"`
|
||||
|
||||
Properties map[string]string `pkl:"properties"`
|
||||
|
||||
ExpiryBlock int `pkl:"expiryBlock"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
type UserEntity struct {
|
||||
Id string `pkl:"id"`
|
||||
|
||||
DisplayName *string `pkl:"displayName"`
|
||||
|
||||
Name *string `pkl:"name"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated from Pkl module `browser`. DO NOT EDIT.
|
||||
package browser
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
func init() {
|
||||
pkl.RegisterMapping("browser", Browser{})
|
||||
pkl.RegisterMapping("browser#PublicKeyCredentialRequestOptions", PublicKeyCredentialRequestOptions{})
|
||||
pkl.RegisterMapping("browser#PublicKeyCredentialDescriptor", PublicKeyCredentialDescriptor{})
|
||||
pkl.RegisterMapping("browser#PublicKeyCredentialParameters", PublicKeyCredentialParameters{})
|
||||
pkl.RegisterMapping("browser#AuthenticatorSelectionCriteria", AuthenticatorSelectionCriteria{})
|
||||
pkl.RegisterMapping("browser#PublicKeyCredentialCreationOptions", PublicKeyCredentialCreationOptions{})
|
||||
pkl.RegisterMapping("browser#RpEntity", RpEntity{})
|
||||
pkl.RegisterMapping("browser#UserEntity", UserEntity{})
|
||||
pkl.RegisterMapping("browser#SWT", SWT{})
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/x/did/types"
|
||||
)
|
||||
|
||||
type (
|
||||
AuthenticatorAttachment string
|
||||
AuthenticatorTransport string
|
||||
)
|
||||
|
||||
const (
|
||||
// Platform represents a platform authenticator is attached using a client device-specific transport, called
|
||||
// platform attachment, and is usually not removable from the client device. A public key credential bound to a
|
||||
// platform authenticator is called a platform credential.
|
||||
Platform AuthenticatorAttachment = "platform"
|
||||
|
||||
// CrossPlatform represents a roaming authenticator is attached using cross-platform transports, called
|
||||
// cross-platform attachment. Authenticators of this class are removable from, and can "roam" among, client devices.
|
||||
// A public key credential bound to a roaming authenticator is called a roaming credential.
|
||||
CrossPlatform AuthenticatorAttachment = "cross-platform"
|
||||
)
|
||||
|
||||
func ParseAuthenticatorAttachment(s string) AuthenticatorAttachment {
|
||||
switch s {
|
||||
case "platform":
|
||||
return Platform
|
||||
default:
|
||||
return CrossPlatform
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
// USB indicates the respective authenticator can be contacted over removable USB.
|
||||
USB AuthenticatorTransport = "usb"
|
||||
|
||||
// NFC indicates the respective authenticator can be contacted over Near Field Communication (NFC).
|
||||
NFC AuthenticatorTransport = "nfc"
|
||||
|
||||
// BLE indicates the respective authenticator can be contacted over Bluetooth Smart (Bluetooth Low Energy / BLE).
|
||||
BLE AuthenticatorTransport = "ble"
|
||||
|
||||
// SmartCard indicates the respective authenticator can be contacted over ISO/IEC 7816 smart card with contacts.
|
||||
//
|
||||
// WebAuthn Level 3.
|
||||
SmartCard AuthenticatorTransport = "smart-card"
|
||||
|
||||
// Hybrid indicates the respective authenticator can be contacted using a combination of (often separate)
|
||||
// data-transport and proximity mechanisms. This supports, for example, authentication on a desktop computer using
|
||||
// a smartphone.
|
||||
//
|
||||
// WebAuthn Level 3.
|
||||
Hybrid AuthenticatorTransport = "hybrid"
|
||||
|
||||
// Internal indicates the respective authenticator is contacted using a client device-specific transport, i.e., it
|
||||
// is a platform authenticator. These authenticators are not removable from the client device.
|
||||
Internal AuthenticatorTransport = "internal"
|
||||
)
|
||||
|
||||
func ParseAuthenticatorTransport(s string) AuthenticatorTransport {
|
||||
switch s {
|
||||
case "usb":
|
||||
return USB
|
||||
case "nfc":
|
||||
return NFC
|
||||
case "ble":
|
||||
return BLE
|
||||
case "smart-card":
|
||||
return SmartCard
|
||||
case "hybrid":
|
||||
return Hybrid
|
||||
default:
|
||||
return Internal
|
||||
}
|
||||
}
|
||||
|
||||
type AuthenticatorFlags byte
|
||||
|
||||
const (
|
||||
// FlagUserPresent Bit 00000001 in the byte sequence. Tells us if user is present. Also referred to as the UP flag.
|
||||
FlagUserPresent AuthenticatorFlags = 1 << iota // Referred to as UP
|
||||
|
||||
// FlagRFU1 is a reserved for future use flag.
|
||||
FlagRFU1
|
||||
|
||||
// FlagUserVerified Bit 00000100 in the byte sequence. Tells us if user is verified
|
||||
// by the authenticator using a biometric or PIN. Also referred to as the UV flag.
|
||||
FlagUserVerified
|
||||
|
||||
// FlagBackupEligible Bit 00001000 in the byte sequence. Tells us if a backup is eligible for device. Also referred
|
||||
// to as the BE flag.
|
||||
FlagBackupEligible // Referred to as BE
|
||||
|
||||
// FlagBackupState Bit 00010000 in the byte sequence. Tells us if a backup state for device. Also referred to as the
|
||||
// BS flag.
|
||||
FlagBackupState
|
||||
|
||||
// FlagRFU2 is a reserved for future use flag.
|
||||
FlagRFU2
|
||||
|
||||
// FlagAttestedCredentialData Bit 01000000 in the byte sequence. Indicates whether
|
||||
// the authenticator added attested credential data. Also referred to as the AT flag.
|
||||
FlagAttestedCredentialData
|
||||
|
||||
// FlagHasExtensions Bit 10000000 in the byte sequence. Indicates if the authenticator data has extensions. Also
|
||||
// referred to as the ED flag.
|
||||
FlagHasExtensions
|
||||
)
|
||||
|
||||
type AttestationFormat string
|
||||
|
||||
const (
|
||||
// AttestationFormatPacked is the "packed" attestation statement format is a WebAuthn-optimized format for
|
||||
// attestation. It uses a very compact but still extensible encoding method. This format is implementable by
|
||||
// authenticators with limited resources (e.g., secure elements).
|
||||
AttestationFormatPacked AttestationFormat = "packed"
|
||||
|
||||
// AttestationFormatTPM is the TPM attestation statement format returns an attestation statement in the same format
|
||||
// as the packed attestation statement format, although the rawData and signature fields are computed differently.
|
||||
AttestationFormatTPM AttestationFormat = "tpm"
|
||||
|
||||
// AttestationFormatAndroidKey is the attestation statement format for platform authenticators on versions "N", and
|
||||
// later, which may provide this proprietary "hardware attestation" statement.
|
||||
AttestationFormatAndroidKey AttestationFormat = "android-key"
|
||||
|
||||
// AttestationFormatAndroidSafetyNet is the attestation statement format that Android-based platform authenticators
|
||||
// MAY produce an attestation statement based on the Android SafetyNet API.
|
||||
AttestationFormatAndroidSafetyNet AttestationFormat = "android-safetynet"
|
||||
|
||||
// AttestationFormatFIDOUniversalSecondFactor is the attestation statement format that is used with FIDO U2F
|
||||
// authenticators.
|
||||
AttestationFormatFIDOUniversalSecondFactor AttestationFormat = "fido-u2f"
|
||||
|
||||
// AttestationFormatApple is the attestation statement format that is used with Apple devices' platform
|
||||
// authenticators.
|
||||
AttestationFormatApple AttestationFormat = "apple"
|
||||
|
||||
// AttestationFormatNone is the attestation statement format that is used to replace any authenticator-provided
|
||||
// attestation statement when a WebAuthn Relying Party indicates it does not wish to receive attestation information.
|
||||
AttestationFormatNone AttestationFormat = "none"
|
||||
)
|
||||
|
||||
func ExtractAttestationFormats(p *types.Params) []AttestationFormat {
|
||||
var formats []AttestationFormat
|
||||
for _, v := range p.AttestationFormats {
|
||||
formats = append(formats, parseAttestationFormat(v))
|
||||
}
|
||||
return formats
|
||||
}
|
||||
|
||||
func parseAttestationFormat(s string) AttestationFormat {
|
||||
switch s {
|
||||
case "packed":
|
||||
return AttestationFormatPacked
|
||||
case "tpm":
|
||||
return AttestationFormatTPM
|
||||
case "android-key":
|
||||
return AttestationFormatAndroidKey
|
||||
case "android-safetynet":
|
||||
return AttestationFormatAndroidSafetyNet
|
||||
case "fido-u2f":
|
||||
return AttestationFormatFIDOUniversalSecondFactor
|
||||
case "apple":
|
||||
return AttestationFormatApple
|
||||
case "none":
|
||||
return AttestationFormatNone
|
||||
default:
|
||||
return AttestationFormatPacked
|
||||
}
|
||||
}
|
||||
|
||||
type CredentialType string
|
||||
|
||||
const (
|
||||
CredentialTypePublicKeyCredential CredentialType = "public-key"
|
||||
)
|
||||
|
||||
type ConveyancePreference string
|
||||
|
||||
const (
|
||||
// PreferNoAttestation is a ConveyancePreference value.
|
||||
//
|
||||
// This value indicates that the Relying Party is not interested in authenticator attestation. For example, in order
|
||||
// to potentially avoid having to obtain user consent to relay identifying information to the Relying Party, or to
|
||||
// save a round trip to an Attestation CA or Anonymization CA.
|
||||
//
|
||||
// This is the default value.
|
||||
//
|
||||
// Specification: §5.4.7. Attestation Conveyance Preference Enumeration (https://www.w3.org/TR/webauthn/#dom-attestationconveyancepreference-none)
|
||||
PreferNoAttestation ConveyancePreference = "none"
|
||||
|
||||
// PreferIndirectAttestation is a ConveyancePreference value.
|
||||
//
|
||||
// This value indicates that the Relying Party prefers an attestation conveyance yielding verifiable attestation
|
||||
// statements, but allows the client to decide how to obtain such attestation statements. The client MAY replace the
|
||||
// authenticator-generated attestation statements with attestation statements generated by an Anonymization CA, in
|
||||
// order to protect the user’s privacy, or to assist Relying Parties with attestation verification in a
|
||||
// heterogeneous ecosystem.
|
||||
//
|
||||
// Note: There is no guarantee that the Relying Party will obtain a verifiable attestation statement in this case.
|
||||
// For example, in the case that the authenticator employs self attestation.
|
||||
//
|
||||
// Specification: §5.4.7. Attestation Conveyance Preference Enumeration (https://www.w3.org/TR/webauthn/#dom-attestationconveyancepreference-indirect)
|
||||
PreferIndirectAttestation ConveyancePreference = "indirect"
|
||||
|
||||
// PreferDirectAttestation is a ConveyancePreference value.
|
||||
//
|
||||
// This value indicates that the Relying Party wants to receive the attestation statement as generated by the
|
||||
// authenticator.
|
||||
//
|
||||
// Specification: §5.4.7. Attestation Conveyance Preference Enumeration (https://www.w3.org/TR/webauthn/#dom-attestationconveyancepreference-direct)
|
||||
PreferDirectAttestation ConveyancePreference = "direct"
|
||||
|
||||
// PreferEnterpriseAttestation is a ConveyancePreference value.
|
||||
//
|
||||
// This value indicates that the Relying Party wants to receive an attestation statement that may include uniquely
|
||||
// identifying information. This is intended for controlled deployments within an enterprise where the organization
|
||||
// wishes to tie registrations to specific authenticators. User agents MUST NOT provide such an attestation unless
|
||||
// the user agent or authenticator configuration permits it for the requested RP ID.
|
||||
//
|
||||
// If permitted, the user agent SHOULD signal to the authenticator (at invocation time) that enterprise
|
||||
// attestation is requested, and convey the resulting AAGUID and attestation statement, unaltered, to the Relying
|
||||
// Party.
|
||||
//
|
||||
// Specification: §5.4.7. Attestation Conveyance Preference Enumeration (https://www.w3.org/TR/webauthn/#dom-attestationconveyancepreference-enterprise)
|
||||
PreferEnterpriseAttestation ConveyancePreference = "enterprise"
|
||||
)
|
||||
|
||||
func ExtractConveyancePreference(p *types.Params) ConveyancePreference {
|
||||
switch p.ConveyancePreference {
|
||||
case "none":
|
||||
return PreferNoAttestation
|
||||
case "indirect":
|
||||
return PreferIndirectAttestation
|
||||
case "direct":
|
||||
return PreferDirectAttestation
|
||||
case "enterprise":
|
||||
return PreferEnterpriseAttestation
|
||||
default:
|
||||
return PreferNoAttestation
|
||||
}
|
||||
}
|
||||
|
||||
type PublicKeyCredentialHints string
|
||||
|
||||
const (
|
||||
// PublicKeyCredentialHintSecurityKey is a PublicKeyCredentialHint that indicates that the Relying Party believes
|
||||
// that users will satisfy this request with a physical security key. For example, an enterprise Relying Party may
|
||||
// set this hint if they have issued security keys to their employees and will only accept those authenticators for
|
||||
// registration and authentication.
|
||||
//
|
||||
// For compatibility with older user agents, when this hint is used in PublicKeyCredentialCreationOptions, the
|
||||
// authenticatorAttachment SHOULD be set to cross-platform.
|
||||
PublicKeyCredentialHintSecurityKey PublicKeyCredentialHints = "security-key"
|
||||
|
||||
// PublicKeyCredentialHintClientDevice is a PublicKeyCredentialHint that indicates that the Relying Party believes
|
||||
// that users will satisfy this request with a platform authenticator attached to the client device.
|
||||
//
|
||||
// For compatibility with older user agents, when this hint is used in PublicKeyCredentialCreationOptions, the
|
||||
// authenticatorAttachment SHOULD be set to platform.
|
||||
PublicKeyCredentialHintClientDevice PublicKeyCredentialHints = "client-device"
|
||||
|
||||
// PublicKeyCredentialHintHybrid is a PublicKeyCredentialHint that indicates that the Relying Party believes that
|
||||
// users will satisfy this request with general-purpose authenticators such as smartphones. For example, a consumer
|
||||
// Relying Party may believe that only a small fraction of their customers possesses dedicated security keys. This
|
||||
// option also implies that the local platform authenticator should not be promoted in the UI.
|
||||
//
|
||||
// For compatibility with older user agents, when this hint is used in PublicKeyCredentialCreationOptions, the
|
||||
// authenticatorAttachment SHOULD be set to cross-platform.
|
||||
PublicKeyCredentialHintHybrid PublicKeyCredentialHints = "hybrid"
|
||||
)
|
||||
|
||||
func ParsePublicKeyCredentialHints(s string) PublicKeyCredentialHints {
|
||||
switch s {
|
||||
case "security-key":
|
||||
return PublicKeyCredentialHintSecurityKey
|
||||
case "client-device":
|
||||
return PublicKeyCredentialHintClientDevice
|
||||
case "hybrid":
|
||||
return PublicKeyCredentialHintHybrid
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type AttestedCredentialData struct {
|
||||
AAGUID []byte `json:"aaguid"`
|
||||
CredentialID []byte `json:"credential_id"`
|
||||
|
||||
// The raw credential public key bytes received from the attestation data.
|
||||
CredentialPublicKey []byte `json:"public_key"`
|
||||
}
|
||||
|
||||
type ResidentKeyRequirement string
|
||||
|
||||
const (
|
||||
// ResidentKeyRequirementDiscouraged indicates the Relying Party prefers creating a server-side credential, but will
|
||||
// accept a client-side discoverable credential. This is the default.
|
||||
ResidentKeyRequirementDiscouraged ResidentKeyRequirement = "discouraged"
|
||||
|
||||
// ResidentKeyRequirementPreferred indicates to the client we would prefer a discoverable credential.
|
||||
ResidentKeyRequirementPreferred ResidentKeyRequirement = "preferred"
|
||||
|
||||
// ResidentKeyRequirementRequired indicates the Relying Party requires a client-side discoverable credential, and is
|
||||
// prepared to receive an error if a client-side discoverable credential cannot be created.
|
||||
ResidentKeyRequirementRequired ResidentKeyRequirement = "required"
|
||||
)
|
||||
|
||||
func ParseResidentKeyRequirement(s string) ResidentKeyRequirement {
|
||||
switch s {
|
||||
case "discouraged":
|
||||
return ResidentKeyRequirementDiscouraged
|
||||
case "preferred":
|
||||
return ResidentKeyRequirementPreferred
|
||||
default:
|
||||
return ResidentKeyRequirementRequired
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
AuthenticationExtensions map[string]any
|
||||
UserVerificationRequirement string
|
||||
)
|
||||
|
||||
const (
|
||||
// VerificationRequired User verification is required to create/release a credential
|
||||
VerificationRequired UserVerificationRequirement = "required"
|
||||
|
||||
// VerificationPreferred User verification is preferred to create/release a credential
|
||||
VerificationPreferred UserVerificationRequirement = "preferred" // This is the default
|
||||
|
||||
// VerificationDiscouraged The authenticator should not verify the user for the credential
|
||||
VerificationDiscouraged UserVerificationRequirement = "discouraged"
|
||||
)
|
||||
@@ -1,56 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
)
|
||||
|
||||
// NewCredential will return a credential pointer on successful validation of a registration response.
|
||||
func NewCredential(c *protocol.ParsedCredentialCreationData, origin, handle string) *Credential {
|
||||
return &Credential{
|
||||
Subject: handle,
|
||||
Origin: origin,
|
||||
AttestationType: c.Response.AttestationObject.Format,
|
||||
CredentialId: BytesToBase64(c.Response.AttestationObject.AuthData.AttData.CredentialID),
|
||||
PublicKey: BytesToBase64(c.Response.AttestationObject.AuthData.AttData.CredentialPublicKey),
|
||||
Transport: NormalizeTransports(c.Response.Transports),
|
||||
SignCount: uint(c.Response.AttestationObject.AuthData.Counter),
|
||||
UserPresent: c.Response.AttestationObject.AuthData.Flags.HasUserPresent(),
|
||||
UserVerified: c.Response.AttestationObject.AuthData.Flags.HasUserVerified(),
|
||||
BackupEligible: c.Response.AttestationObject.AuthData.Flags.HasBackupEligible(),
|
||||
BackupState: c.Response.AttestationObject.AuthData.Flags.HasAttestedCredentialData(),
|
||||
}
|
||||
}
|
||||
|
||||
func BytesToBase64(b []byte) string {
|
||||
return base64.RawURLEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
func Base64ToBytes(b string) ([]byte, error) {
|
||||
return base64.RawURLEncoding.DecodeString(b)
|
||||
}
|
||||
|
||||
// Descriptor converts a Credential into a protocol.CredentialDescriptor.
|
||||
func (c *Credential) Descriptor() protocol.CredentialDescriptor {
|
||||
id, err := base64.RawURLEncoding.DecodeString(c.CredentialId)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return protocol.CredentialDescriptor{
|
||||
Type: protocol.PublicKeyCredentialType,
|
||||
CredentialID: id,
|
||||
Transport: ConvertTransports(c.Transport),
|
||||
AttestationType: c.AttestationType,
|
||||
}
|
||||
}
|
||||
|
||||
// This is a signal that the authenticator may be cloned, see CloneWarning above for more information.
|
||||
func (a *Credential) UpdateCounter(authDataCount uint) {
|
||||
if authDataCount <= a.SignCount && (authDataCount != 0 || a.SignCount != 0) {
|
||||
a.CloneWarning = true
|
||||
return
|
||||
}
|
||||
|
||||
a.SignCount = authDataCount
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package didmethod
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DIDMethod string
|
||||
|
||||
const (
|
||||
Ipfs DIDMethod = "ipfs"
|
||||
Sonr DIDMethod = "sonr"
|
||||
Bitcoin DIDMethod = "bitcoin"
|
||||
Ethereum DIDMethod = "ethereum"
|
||||
Ibc DIDMethod = "ibc"
|
||||
Webauthn DIDMethod = "webauthn"
|
||||
Dwn DIDMethod = "dwn"
|
||||
Service DIDMethod = "service"
|
||||
)
|
||||
|
||||
// String returns the string representation of DIDMethod
|
||||
func (rcv DIDMethod) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(DIDMethod)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for DIDMethod.
|
||||
func (rcv *DIDMethod) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "ipfs":
|
||||
*rcv = Ipfs
|
||||
case "sonr":
|
||||
*rcv = Sonr
|
||||
case "bitcoin":
|
||||
*rcv = Bitcoin
|
||||
case "ethereum":
|
||||
*rcv = Ethereum
|
||||
case "ibc":
|
||||
*rcv = Ibc
|
||||
case "webauthn":
|
||||
*rcv = Webauthn
|
||||
case "dwn":
|
||||
*rcv = Dwn
|
||||
case "service":
|
||||
*rcv = Service
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid DIDMethod`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package orm
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
func init() {
|
||||
pkl.RegisterMapping("orm", Orm{})
|
||||
pkl.RegisterMapping("orm#Account", Account{})
|
||||
pkl.RegisterMapping("orm#Asset", Asset{})
|
||||
pkl.RegisterMapping("orm#Chain", Chain{})
|
||||
pkl.RegisterMapping("orm#Credential", Credential{})
|
||||
pkl.RegisterMapping("orm#JWK", JWK{})
|
||||
pkl.RegisterMapping("orm#Grant", Grant{})
|
||||
pkl.RegisterMapping("orm#Keyshare", Keyshare{})
|
||||
pkl.RegisterMapping("orm#PublicKey", PublicKey{})
|
||||
pkl.RegisterMapping("orm#Profile", Profile{})
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/go-webauthn/webauthn/protocol/webauthncose"
|
||||
)
|
||||
|
||||
func FormatEC2PublicKey(key *webauthncose.EC2PublicKeyData) (*JWK, error) {
|
||||
curve, err := GetCOSECurveName(key.Curve)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jwkMap := map[string]interface{}{
|
||||
"kty": "EC",
|
||||
"crv": curve,
|
||||
"x": base64.RawURLEncoding.EncodeToString(key.XCoord),
|
||||
"y": base64.RawURLEncoding.EncodeToString(key.YCoord),
|
||||
}
|
||||
|
||||
return MapToJWK(jwkMap)
|
||||
}
|
||||
|
||||
func FormatRSAPublicKey(key *webauthncose.RSAPublicKeyData) (*JWK, error) {
|
||||
jwkMap := map[string]interface{}{
|
||||
"kty": "RSA",
|
||||
"n": base64.RawURLEncoding.EncodeToString(key.Modulus),
|
||||
"e": base64.RawURLEncoding.EncodeToString(key.Exponent),
|
||||
}
|
||||
|
||||
return MapToJWK(jwkMap)
|
||||
}
|
||||
|
||||
func FormatOKPPublicKey(key *webauthncose.OKPPublicKeyData) (*JWK, error) {
|
||||
curve, err := GetOKPCurveName(key.Curve)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jwkMap := map[string]interface{}{
|
||||
"kty": "OKP",
|
||||
"crv": curve,
|
||||
"x": base64.RawURLEncoding.EncodeToString(key.XCoord),
|
||||
}
|
||||
|
||||
return MapToJWK(jwkMap)
|
||||
}
|
||||
|
||||
func MapToJWK(m map[string]interface{}) (*JWK, error) {
|
||||
jwk := &JWK{}
|
||||
for k, v := range m {
|
||||
switch k {
|
||||
case "kty":
|
||||
jwk.Kty = v.(string)
|
||||
case "crv":
|
||||
jwk.Crv = v.(string)
|
||||
case "x":
|
||||
jwk.X = v.(string)
|
||||
case "y":
|
||||
jwk.Y = v.(string)
|
||||
case "n":
|
||||
jwk.N = v.(string)
|
||||
case "e":
|
||||
jwk.E = v.(string)
|
||||
}
|
||||
}
|
||||
return jwk, nil
|
||||
}
|
||||
|
||||
func GetCOSECurveName(curveID int64) (string, error) {
|
||||
switch curveID {
|
||||
case int64(webauthncose.P256):
|
||||
return "P-256", nil
|
||||
case int64(webauthncose.P384):
|
||||
return "P-384", nil
|
||||
case int64(webauthncose.P521):
|
||||
return "P-521", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown curve ID: %d", curveID)
|
||||
}
|
||||
}
|
||||
|
||||
func GetOKPCurveName(curveID int64) (string, error) {
|
||||
switch curveID {
|
||||
case int64(webauthncose.Ed25519):
|
||||
return "Ed25519", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown OKP curve ID: %d", curveID)
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertTransports converts the transports from strings to protocol.AuthenticatorTransport
|
||||
func ConvertTransports(transports []string) []protocol.AuthenticatorTransport {
|
||||
tss := make([]protocol.AuthenticatorTransport, len(transports))
|
||||
for i, t := range transports {
|
||||
tss[i] = protocol.AuthenticatorTransport(t)
|
||||
}
|
||||
return tss
|
||||
}
|
||||
|
||||
// NormalizeTransports returns the transports as strings
|
||||
func NormalizeTransports(transports []protocol.AuthenticatorTransport) []string {
|
||||
tss := make([]string, len(transports))
|
||||
for i, t := range transports {
|
||||
tss[i] = string(t)
|
||||
}
|
||||
return tss
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package orm
|
||||
|
||||
import "github.com/onsonr/sonr/internal/orm/keyalgorithm"
|
||||
|
||||
type COSEAlgorithmIdentifier int
|
||||
|
||||
func GetCoseIdentifier(alg keyalgorithm.KeyAlgorithm) COSEAlgorithmIdentifier {
|
||||
switch alg {
|
||||
case keyalgorithm.Es256:
|
||||
return COSEAlgorithmIdentifier(-7)
|
||||
case keyalgorithm.Es384:
|
||||
return COSEAlgorithmIdentifier(-35)
|
||||
case keyalgorithm.Es512:
|
||||
return COSEAlgorithmIdentifier(-36)
|
||||
case keyalgorithm.Eddsa:
|
||||
return COSEAlgorithmIdentifier(-8)
|
||||
case keyalgorithm.Es256k:
|
||||
return COSEAlgorithmIdentifier(-10)
|
||||
default:
|
||||
return COSEAlgorithmIdentifier(0)
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keyalgorithm
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyAlgorithm string
|
||||
|
||||
const (
|
||||
Es256 KeyAlgorithm = "es256"
|
||||
Es384 KeyAlgorithm = "es384"
|
||||
Es512 KeyAlgorithm = "es512"
|
||||
Eddsa KeyAlgorithm = "eddsa"
|
||||
Es256k KeyAlgorithm = "es256k"
|
||||
Ecdsa KeyAlgorithm = "ecdsa"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyAlgorithm
|
||||
func (rcv KeyAlgorithm) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyAlgorithm)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyAlgorithm.
|
||||
func (rcv *KeyAlgorithm) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "es256":
|
||||
*rcv = Es256
|
||||
case "es384":
|
||||
*rcv = Es384
|
||||
case "es512":
|
||||
*rcv = Es512
|
||||
case "eddsa":
|
||||
*rcv = Eddsa
|
||||
case "es256k":
|
||||
*rcv = Es256k
|
||||
case "ecdsa":
|
||||
*rcv = Ecdsa
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyAlgorithm`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keycurve
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyCurve string
|
||||
|
||||
const (
|
||||
P256 KeyCurve = "p256"
|
||||
P384 KeyCurve = "p384"
|
||||
P521 KeyCurve = "p521"
|
||||
X25519 KeyCurve = "x25519"
|
||||
X448 KeyCurve = "x448"
|
||||
Ed25519 KeyCurve = "ed25519"
|
||||
Ed448 KeyCurve = "ed448"
|
||||
Secp256k1 KeyCurve = "secp256k1"
|
||||
Bls12381 KeyCurve = "bls12381"
|
||||
Keccak256 KeyCurve = "keccak256"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyCurve
|
||||
func (rcv KeyCurve) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyCurve)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyCurve.
|
||||
func (rcv *KeyCurve) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "p256":
|
||||
*rcv = P256
|
||||
case "p384":
|
||||
*rcv = P384
|
||||
case "p521":
|
||||
*rcv = P521
|
||||
case "x25519":
|
||||
*rcv = X25519
|
||||
case "x448":
|
||||
*rcv = X448
|
||||
case "ed25519":
|
||||
*rcv = Ed25519
|
||||
case "ed448":
|
||||
*rcv = Ed448
|
||||
case "secp256k1":
|
||||
*rcv = Secp256k1
|
||||
case "bls12381":
|
||||
*rcv = Bls12381
|
||||
case "keccak256":
|
||||
*rcv = Keccak256
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyCurve`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keyencoding
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyEncoding string
|
||||
|
||||
const (
|
||||
Raw KeyEncoding = "raw"
|
||||
Hex KeyEncoding = "hex"
|
||||
Multibase KeyEncoding = "multibase"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyEncoding
|
||||
func (rcv KeyEncoding) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyEncoding)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyEncoding.
|
||||
func (rcv *KeyEncoding) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "raw":
|
||||
*rcv = Raw
|
||||
case "hex":
|
||||
*rcv = Hex
|
||||
case "multibase":
|
||||
*rcv = Multibase
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyEncoding`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keyrole
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyRole string
|
||||
|
||||
const (
|
||||
Authentication KeyRole = "authentication"
|
||||
Assertion KeyRole = "assertion"
|
||||
Delegation KeyRole = "delegation"
|
||||
Invocation KeyRole = "invocation"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyRole
|
||||
func (rcv KeyRole) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyRole)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyRole.
|
||||
func (rcv *KeyRole) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "authentication":
|
||||
*rcv = Authentication
|
||||
case "assertion":
|
||||
*rcv = Assertion
|
||||
case "delegation":
|
||||
*rcv = Delegation
|
||||
case "invocation":
|
||||
*rcv = Invocation
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyRole`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keysharerole
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyShareRole string
|
||||
|
||||
const (
|
||||
User KeyShareRole = "user"
|
||||
Validator KeyShareRole = "validator"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyShareRole
|
||||
func (rcv KeyShareRole) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyShareRole)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyShareRole.
|
||||
func (rcv *KeyShareRole) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "user":
|
||||
*rcv = User
|
||||
case "validator":
|
||||
*rcv = Validator
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyShareRole`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package keytype
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type KeyType string
|
||||
|
||||
const (
|
||||
Octet KeyType = "octet"
|
||||
Elliptic KeyType = "elliptic"
|
||||
Rsa KeyType = "rsa"
|
||||
Symmetric KeyType = "symmetric"
|
||||
Hmac KeyType = "hmac"
|
||||
Mpc KeyType = "mpc"
|
||||
Zk KeyType = "zk"
|
||||
Webauthn KeyType = "webauthn"
|
||||
Bip32 KeyType = "bip32"
|
||||
)
|
||||
|
||||
// String returns the string representation of KeyType
|
||||
func (rcv KeyType) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(KeyType)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for KeyType.
|
||||
func (rcv *KeyType) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "octet":
|
||||
*rcv = Octet
|
||||
case "elliptic":
|
||||
*rcv = Elliptic
|
||||
case "rsa":
|
||||
*rcv = Rsa
|
||||
case "symmetric":
|
||||
*rcv = Symmetric
|
||||
case "hmac":
|
||||
*rcv = Hmac
|
||||
case "mpc":
|
||||
*rcv = Mpc
|
||||
case "zk":
|
||||
*rcv = Zk
|
||||
case "webauthn":
|
||||
*rcv = Webauthn
|
||||
case "bip32":
|
||||
*rcv = Bip32
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid KeyType`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package permissiongrant
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type PermissionGrant string
|
||||
|
||||
const (
|
||||
None PermissionGrant = "none"
|
||||
Read PermissionGrant = "read"
|
||||
Write PermissionGrant = "write"
|
||||
Verify PermissionGrant = "verify"
|
||||
Broadcast PermissionGrant = "broadcast"
|
||||
Admin PermissionGrant = "admin"
|
||||
)
|
||||
|
||||
// String returns the string representation of PermissionGrant
|
||||
func (rcv PermissionGrant) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(PermissionGrant)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for PermissionGrant.
|
||||
func (rcv *PermissionGrant) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "none":
|
||||
*rcv = None
|
||||
case "read":
|
||||
*rcv = Read
|
||||
case "write":
|
||||
*rcv = Write
|
||||
case "verify":
|
||||
*rcv = Verify
|
||||
case "broadcast":
|
||||
*rcv = Broadcast
|
||||
case "admin":
|
||||
*rcv = Admin
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid PermissionGrant`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// Code generated from Pkl module `orm`. DO NOT EDIT.
|
||||
package permissionscope
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type PermissionScope string
|
||||
|
||||
const (
|
||||
Profile PermissionScope = "profile"
|
||||
Metadata PermissionScope = "metadata"
|
||||
Permissions PermissionScope = "permissions"
|
||||
Wallets PermissionScope = "wallets"
|
||||
Transactions PermissionScope = "transactions"
|
||||
User PermissionScope = "user"
|
||||
Validator PermissionScope = "validator"
|
||||
)
|
||||
|
||||
// String returns the string representation of PermissionScope
|
||||
func (rcv PermissionScope) String() string {
|
||||
return string(rcv)
|
||||
}
|
||||
|
||||
var _ encoding.BinaryUnmarshaler = new(PermissionScope)
|
||||
|
||||
// UnmarshalBinary implements encoding.BinaryUnmarshaler for PermissionScope.
|
||||
func (rcv *PermissionScope) UnmarshalBinary(data []byte) error {
|
||||
switch str := string(data); str {
|
||||
case "profile":
|
||||
*rcv = Profile
|
||||
case "metadata":
|
||||
*rcv = Metadata
|
||||
case "permissions":
|
||||
*rcv = Permissions
|
||||
case "wallets":
|
||||
*rcv = Wallets
|
||||
case "transactions":
|
||||
*rcv = Transactions
|
||||
case "user":
|
||||
*rcv = User
|
||||
case "validator":
|
||||
*rcv = Validator
|
||||
default:
|
||||
return fmt.Errorf(`illegal: "%s" is not a valid PermissionScope`, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-webauthn/webauthn/protocol/webauthncose"
|
||||
)
|
||||
|
||||
// ExtractWebAuthnPublicKey parses the raw public key bytes and returns a JWK representation
|
||||
func ExtractWebAuthnPublicKey(keyBytes []byte) (*JWK, error) {
|
||||
key, err := webauthncose.ParsePublicKey(keyBytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse public key: %w", err)
|
||||
}
|
||||
|
||||
switch k := key.(type) {
|
||||
case *webauthncose.EC2PublicKeyData:
|
||||
return FormatEC2PublicKey(k)
|
||||
case *webauthncose.RSAPublicKeyData:
|
||||
return FormatRSAPublicKey(k)
|
||||
case *webauthncose.OKPPublicKeyData:
|
||||
return FormatOKPPublicKey(k)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported key type")
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
type Msg interface {
|
||||
GetTypeUrl() string
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidAllocateVault interface {
|
||||
Msg
|
||||
|
||||
GetAuthority() string
|
||||
|
||||
GetSubject() string
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidAllocateVault = (*MsgDidAllocateVaultImpl)(nil)
|
||||
|
||||
type MsgDidAllocateVaultImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Authority string `pkl:"authority"`
|
||||
|
||||
Subject string `pkl:"subject"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidAllocateVaultImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAllocateVaultImpl) GetAuthority() string {
|
||||
return rcv.Authority
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAllocateVaultImpl) GetSubject() string {
|
||||
return rcv.Subject
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAllocateVaultImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidAuthorize interface {
|
||||
Msg
|
||||
|
||||
GetAuthority() string
|
||||
|
||||
GetController() string
|
||||
|
||||
GetAddress() string
|
||||
|
||||
GetOrigin() string
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidAuthorize = (*MsgDidAuthorizeImpl)(nil)
|
||||
|
||||
type MsgDidAuthorizeImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Authority string `pkl:"authority"`
|
||||
|
||||
Controller string `pkl:"controller"`
|
||||
|
||||
Address string `pkl:"address"`
|
||||
|
||||
Origin string `pkl:"origin"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidAuthorizeImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAuthorizeImpl) GetAuthority() string {
|
||||
return rcv.Authority
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAuthorizeImpl) GetController() string {
|
||||
return rcv.Controller
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAuthorizeImpl) GetAddress() string {
|
||||
return rcv.Address
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAuthorizeImpl) GetOrigin() string {
|
||||
return rcv.Origin
|
||||
}
|
||||
|
||||
func (rcv *MsgDidAuthorizeImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidProveWitness interface {
|
||||
Msg
|
||||
|
||||
GetAuthority() string
|
||||
|
||||
GetProperty() string
|
||||
|
||||
GetWitness() []int
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidProveWitness = (*MsgDidProveWitnessImpl)(nil)
|
||||
|
||||
type MsgDidProveWitnessImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Authority string `pkl:"authority"`
|
||||
|
||||
Property string `pkl:"property"`
|
||||
|
||||
Witness []int `pkl:"witness"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidProveWitnessImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidProveWitnessImpl) GetAuthority() string {
|
||||
return rcv.Authority
|
||||
}
|
||||
|
||||
func (rcv *MsgDidProveWitnessImpl) GetProperty() string {
|
||||
return rcv.Property
|
||||
}
|
||||
|
||||
func (rcv *MsgDidProveWitnessImpl) GetWitness() []int {
|
||||
return rcv.Witness
|
||||
}
|
||||
|
||||
func (rcv *MsgDidProveWitnessImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidRegisterController interface {
|
||||
Msg
|
||||
|
||||
GetAuthority() string
|
||||
|
||||
GetCid() string
|
||||
|
||||
GetOrigin() string
|
||||
|
||||
GetAuthentication() []*pkl.Object
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidRegisterController = (*MsgDidRegisterControllerImpl)(nil)
|
||||
|
||||
type MsgDidRegisterControllerImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Authority string `pkl:"authority"`
|
||||
|
||||
Cid string `pkl:"cid"`
|
||||
|
||||
Origin string `pkl:"origin"`
|
||||
|
||||
Authentication []*pkl.Object `pkl:"authentication"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetAuthority() string {
|
||||
return rcv.Authority
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetCid() string {
|
||||
return rcv.Cid
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetOrigin() string {
|
||||
return rcv.Origin
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetAuthentication() []*pkl.Object {
|
||||
return rcv.Authentication
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterControllerImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidRegisterService interface {
|
||||
Msg
|
||||
|
||||
GetController() string
|
||||
|
||||
GetOriginUri() string
|
||||
|
||||
GetScopes() *pkl.Object
|
||||
|
||||
GetDescription() string
|
||||
|
||||
GetServiceEndpoints() map[string]string
|
||||
|
||||
GetMetadata() *pkl.Object
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidRegisterService = (*MsgDidRegisterServiceImpl)(nil)
|
||||
|
||||
type MsgDidRegisterServiceImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Controller string `pkl:"controller"`
|
||||
|
||||
OriginUri string `pkl:"originUri"`
|
||||
|
||||
Scopes *pkl.Object `pkl:"scopes"`
|
||||
|
||||
Description string `pkl:"description"`
|
||||
|
||||
ServiceEndpoints map[string]string `pkl:"serviceEndpoints"`
|
||||
|
||||
Metadata *pkl.Object `pkl:"metadata"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetController() string {
|
||||
return rcv.Controller
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetOriginUri() string {
|
||||
return rcv.OriginUri
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetScopes() *pkl.Object {
|
||||
return rcv.Scopes
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetDescription() string {
|
||||
return rcv.Description
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetServiceEndpoints() map[string]string {
|
||||
return rcv.ServiceEndpoints
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetMetadata() *pkl.Object {
|
||||
return rcv.Metadata
|
||||
}
|
||||
|
||||
func (rcv *MsgDidRegisterServiceImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidSyncVault interface {
|
||||
Msg
|
||||
|
||||
GetController() string
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidSyncVault = (*MsgDidSyncVaultImpl)(nil)
|
||||
|
||||
type MsgDidSyncVaultImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Controller string `pkl:"controller"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidSyncVaultImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidSyncVaultImpl) GetController() string {
|
||||
return rcv.Controller
|
||||
}
|
||||
|
||||
func (rcv *MsgDidSyncVaultImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgDidUpdateParams interface {
|
||||
Msg
|
||||
|
||||
GetAuthority() string
|
||||
|
||||
GetParams() *pkl.Object
|
||||
|
||||
GetToken() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgDidUpdateParams = (*MsgDidUpdateParamsImpl)(nil)
|
||||
|
||||
type MsgDidUpdateParamsImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Authority string `pkl:"authority"`
|
||||
|
||||
Params *pkl.Object `pkl:"params"`
|
||||
|
||||
Token *pkl.Object `pkl:"token"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgDidUpdateParamsImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgDidUpdateParamsImpl) GetAuthority() string {
|
||||
return rcv.Authority
|
||||
}
|
||||
|
||||
func (rcv *MsgDidUpdateParamsImpl) GetParams() *pkl.Object {
|
||||
return rcv.Params
|
||||
}
|
||||
|
||||
func (rcv *MsgDidUpdateParamsImpl) GetToken() *pkl.Object {
|
||||
return rcv.Token
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgGovDeposit interface {
|
||||
Msg
|
||||
|
||||
GetProposalId() int
|
||||
|
||||
GetDepositor() string
|
||||
|
||||
GetAmount() []*pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgGovDeposit = (*MsgGovDepositImpl)(nil)
|
||||
|
||||
type MsgGovDepositImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
ProposalId int `pkl:"proposalId"`
|
||||
|
||||
Depositor string `pkl:"depositor"`
|
||||
|
||||
Amount []*pkl.Object `pkl:"amount"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGovDepositImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGovDepositImpl) GetProposalId() int {
|
||||
return rcv.ProposalId
|
||||
}
|
||||
|
||||
func (rcv *MsgGovDepositImpl) GetDepositor() string {
|
||||
return rcv.Depositor
|
||||
}
|
||||
|
||||
func (rcv *MsgGovDepositImpl) GetAmount() []*pkl.Object {
|
||||
return rcv.Amount
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgGovSubmitProposal interface {
|
||||
Msg
|
||||
|
||||
GetContent() *Proposal
|
||||
|
||||
GetInitialDeposit() []*pkl.Object
|
||||
|
||||
GetProposer() string
|
||||
}
|
||||
|
||||
var _ MsgGovSubmitProposal = (*MsgGovSubmitProposalImpl)(nil)
|
||||
|
||||
// Gov module messages
|
||||
type MsgGovSubmitProposalImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Content *Proposal `pkl:"content"`
|
||||
|
||||
InitialDeposit []*pkl.Object `pkl:"initialDeposit"`
|
||||
|
||||
Proposer string `pkl:"proposer"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGovSubmitProposalImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGovSubmitProposalImpl) GetContent() *Proposal {
|
||||
return rcv.Content
|
||||
}
|
||||
|
||||
func (rcv *MsgGovSubmitProposalImpl) GetInitialDeposit() []*pkl.Object {
|
||||
return rcv.InitialDeposit
|
||||
}
|
||||
|
||||
func (rcv *MsgGovSubmitProposalImpl) GetProposer() string {
|
||||
return rcv.Proposer
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
type MsgGovVote interface {
|
||||
Msg
|
||||
|
||||
GetProposalId() int
|
||||
|
||||
GetVoter() string
|
||||
|
||||
GetOption() int
|
||||
}
|
||||
|
||||
var _ MsgGovVote = (*MsgGovVoteImpl)(nil)
|
||||
|
||||
type MsgGovVoteImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
ProposalId int `pkl:"proposalId"`
|
||||
|
||||
Voter string `pkl:"voter"`
|
||||
|
||||
Option int `pkl:"option"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGovVoteImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGovVoteImpl) GetProposalId() int {
|
||||
return rcv.ProposalId
|
||||
}
|
||||
|
||||
func (rcv *MsgGovVoteImpl) GetVoter() string {
|
||||
return rcv.Voter
|
||||
}
|
||||
|
||||
func (rcv *MsgGovVoteImpl) GetOption() int {
|
||||
return rcv.Option
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgGroupCreateGroup interface {
|
||||
Msg
|
||||
|
||||
GetAdmin() string
|
||||
|
||||
GetMembers() []*pkl.Object
|
||||
|
||||
GetMetadata() string
|
||||
}
|
||||
|
||||
var _ MsgGroupCreateGroup = (*MsgGroupCreateGroupImpl)(nil)
|
||||
|
||||
// Group module messages
|
||||
type MsgGroupCreateGroupImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Admin string `pkl:"admin"`
|
||||
|
||||
Members []*pkl.Object `pkl:"members"`
|
||||
|
||||
Metadata string `pkl:"metadata"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGroupCreateGroupImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupCreateGroupImpl) GetAdmin() string {
|
||||
return rcv.Admin
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupCreateGroupImpl) GetMembers() []*pkl.Object {
|
||||
return rcv.Members
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupCreateGroupImpl) GetMetadata() string {
|
||||
return rcv.Metadata
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgGroupSubmitProposal interface {
|
||||
Msg
|
||||
|
||||
GetGroupPolicyAddress() string
|
||||
|
||||
GetProposers() []string
|
||||
|
||||
GetMetadata() string
|
||||
|
||||
GetMessages() []*pkl.Object
|
||||
|
||||
GetExec() int
|
||||
}
|
||||
|
||||
var _ MsgGroupSubmitProposal = (*MsgGroupSubmitProposalImpl)(nil)
|
||||
|
||||
type MsgGroupSubmitProposalImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
GroupPolicyAddress string `pkl:"groupPolicyAddress"`
|
||||
|
||||
Proposers []string `pkl:"proposers"`
|
||||
|
||||
Metadata string `pkl:"metadata"`
|
||||
|
||||
Messages []*pkl.Object `pkl:"messages"`
|
||||
|
||||
Exec int `pkl:"exec"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetGroupPolicyAddress() string {
|
||||
return rcv.GroupPolicyAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetProposers() []string {
|
||||
return rcv.Proposers
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetMetadata() string {
|
||||
return rcv.Metadata
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetMessages() []*pkl.Object {
|
||||
return rcv.Messages
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupSubmitProposalImpl) GetExec() int {
|
||||
return rcv.Exec
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
type MsgGroupVote interface {
|
||||
Msg
|
||||
|
||||
GetProposalId() int
|
||||
|
||||
GetVoter() string
|
||||
|
||||
GetOption() int
|
||||
|
||||
GetMetadata() string
|
||||
|
||||
GetExec() int
|
||||
}
|
||||
|
||||
var _ MsgGroupVote = (*MsgGroupVoteImpl)(nil)
|
||||
|
||||
type MsgGroupVoteImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
ProposalId int `pkl:"proposalId"`
|
||||
|
||||
Voter string `pkl:"voter"`
|
||||
|
||||
Option int `pkl:"option"`
|
||||
|
||||
Metadata string `pkl:"metadata"`
|
||||
|
||||
Exec int `pkl:"exec"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgGroupVoteImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupVoteImpl) GetProposalId() int {
|
||||
return rcv.ProposalId
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupVoteImpl) GetVoter() string {
|
||||
return rcv.Voter
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupVoteImpl) GetOption() int {
|
||||
return rcv.Option
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupVoteImpl) GetMetadata() string {
|
||||
return rcv.Metadata
|
||||
}
|
||||
|
||||
func (rcv *MsgGroupVoteImpl) GetExec() int {
|
||||
return rcv.Exec
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgStakingBeginRedelegate interface {
|
||||
Msg
|
||||
|
||||
GetDelegatorAddress() string
|
||||
|
||||
GetValidatorSrcAddress() string
|
||||
|
||||
GetValidatorDstAddress() string
|
||||
|
||||
GetAmount() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgStakingBeginRedelegate = (*MsgStakingBeginRedelegateImpl)(nil)
|
||||
|
||||
type MsgStakingBeginRedelegateImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
DelegatorAddress string `pkl:"delegatorAddress"`
|
||||
|
||||
ValidatorSrcAddress string `pkl:"validatorSrcAddress"`
|
||||
|
||||
ValidatorDstAddress string `pkl:"validatorDstAddress"`
|
||||
|
||||
Amount *pkl.Object `pkl:"amount"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgStakingBeginRedelegateImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingBeginRedelegateImpl) GetDelegatorAddress() string {
|
||||
return rcv.DelegatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingBeginRedelegateImpl) GetValidatorSrcAddress() string {
|
||||
return rcv.ValidatorSrcAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingBeginRedelegateImpl) GetValidatorDstAddress() string {
|
||||
return rcv.ValidatorDstAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingBeginRedelegateImpl) GetAmount() *pkl.Object {
|
||||
return rcv.Amount
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgStakingCreateValidator interface {
|
||||
Msg
|
||||
|
||||
GetDescription() *pkl.Object
|
||||
|
||||
GetCommission() *pkl.Object
|
||||
|
||||
GetMinSelfDelegation() string
|
||||
|
||||
GetDelegatorAddress() string
|
||||
|
||||
GetValidatorAddress() string
|
||||
|
||||
GetPubkey() *pkl.Object
|
||||
|
||||
GetValue() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgStakingCreateValidator = (*MsgStakingCreateValidatorImpl)(nil)
|
||||
|
||||
// Staking module messages
|
||||
type MsgStakingCreateValidatorImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
Description *pkl.Object `pkl:"description"`
|
||||
|
||||
Commission *pkl.Object `pkl:"commission"`
|
||||
|
||||
MinSelfDelegation string `pkl:"minSelfDelegation"`
|
||||
|
||||
DelegatorAddress string `pkl:"delegatorAddress"`
|
||||
|
||||
ValidatorAddress string `pkl:"validatorAddress"`
|
||||
|
||||
Pubkey *pkl.Object `pkl:"pubkey"`
|
||||
|
||||
Value *pkl.Object `pkl:"value"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetDescription() *pkl.Object {
|
||||
return rcv.Description
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetCommission() *pkl.Object {
|
||||
return rcv.Commission
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetMinSelfDelegation() string {
|
||||
return rcv.MinSelfDelegation
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetDelegatorAddress() string {
|
||||
return rcv.DelegatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetValidatorAddress() string {
|
||||
return rcv.ValidatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetPubkey() *pkl.Object {
|
||||
return rcv.Pubkey
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingCreateValidatorImpl) GetValue() *pkl.Object {
|
||||
return rcv.Value
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgStakingDelegate interface {
|
||||
Msg
|
||||
|
||||
GetDelegatorAddress() string
|
||||
|
||||
GetValidatorAddress() string
|
||||
|
||||
GetAmount() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgStakingDelegate = (*MsgStakingDelegateImpl)(nil)
|
||||
|
||||
type MsgStakingDelegateImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
DelegatorAddress string `pkl:"delegatorAddress"`
|
||||
|
||||
ValidatorAddress string `pkl:"validatorAddress"`
|
||||
|
||||
Amount *pkl.Object `pkl:"amount"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgStakingDelegateImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingDelegateImpl) GetDelegatorAddress() string {
|
||||
return rcv.DelegatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingDelegateImpl) GetValidatorAddress() string {
|
||||
return rcv.ValidatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingDelegateImpl) GetAmount() *pkl.Object {
|
||||
return rcv.Amount
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
type MsgStakingUndelegate interface {
|
||||
Msg
|
||||
|
||||
GetDelegatorAddress() string
|
||||
|
||||
GetValidatorAddress() string
|
||||
|
||||
GetAmount() *pkl.Object
|
||||
}
|
||||
|
||||
var _ MsgStakingUndelegate = (*MsgStakingUndelegateImpl)(nil)
|
||||
|
||||
type MsgStakingUndelegateImpl struct {
|
||||
// The type URL for the message
|
||||
TypeUrl string `pkl:"typeUrl"`
|
||||
|
||||
DelegatorAddress string `pkl:"delegatorAddress"`
|
||||
|
||||
ValidatorAddress string `pkl:"validatorAddress"`
|
||||
|
||||
Amount *pkl.Object `pkl:"amount"`
|
||||
}
|
||||
|
||||
// The type URL for the message
|
||||
func (rcv *MsgStakingUndelegateImpl) GetTypeUrl() string {
|
||||
return rcv.TypeUrl
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingUndelegateImpl) GetDelegatorAddress() string {
|
||||
return rcv.DelegatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingUndelegateImpl) GetValidatorAddress() string {
|
||||
return rcv.ValidatorAddress
|
||||
}
|
||||
|
||||
func (rcv *MsgStakingUndelegateImpl) GetAmount() *pkl.Object {
|
||||
return rcv.Amount
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
// Base class for all proposals
|
||||
type Proposal struct {
|
||||
// The title of the proposal
|
||||
Title string `pkl:"title"`
|
||||
|
||||
// The description of the proposal
|
||||
Description string `pkl:"description"`
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/apple/pkl-go/pkl"
|
||||
)
|
||||
|
||||
type Transactions struct {
|
||||
}
|
||||
|
||||
// LoadFromPath loads the pkl module at the given path and evaluates it into a Transactions
|
||||
func LoadFromPath(ctx context.Context, path string) (ret *Transactions, err error) {
|
||||
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
cerr := evaluator.Close()
|
||||
if err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Transactions
|
||||
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Transactions, error) {
|
||||
var ret Transactions
|
||||
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
// Represents a transaction body
|
||||
type TxBody struct {
|
||||
Messages []Msg `pkl:"messages"`
|
||||
|
||||
Memo *string `pkl:"memo"`
|
||||
|
||||
TimeoutHeight *int `pkl:"timeoutHeight"`
|
||||
|
||||
ExtensionOptions *[]*pkl.Object `pkl:"extensionOptions"`
|
||||
|
||||
NonCriticalExtensionOptions *[]*pkl.Object `pkl:"nonCriticalExtensionOptions"`
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// Code generated from Pkl module `transactions`. DO NOT EDIT.
|
||||
package transactions
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
func init() {
|
||||
pkl.RegisterMapping("transactions", Transactions{})
|
||||
pkl.RegisterMapping("transactions#Proposal", Proposal{})
|
||||
pkl.RegisterMapping("transactions#MsgGovSubmitProposal", MsgGovSubmitProposalImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgGovVote", MsgGovVoteImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgGovDeposit", MsgGovDepositImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgGroupCreateGroup", MsgGroupCreateGroupImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgGroupSubmitProposal", MsgGroupSubmitProposalImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgGroupVote", MsgGroupVoteImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgStakingCreateValidator", MsgStakingCreateValidatorImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgStakingDelegate", MsgStakingDelegateImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgStakingUndelegate", MsgStakingUndelegateImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgStakingBeginRedelegate", MsgStakingBeginRedelegateImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidUpdateParams", MsgDidUpdateParamsImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidAllocateVault", MsgDidAllocateVaultImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidProveWitness", MsgDidProveWitnessImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidSyncVault", MsgDidSyncVaultImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidRegisterController", MsgDidRegisterControllerImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidAuthorize", MsgDidAuthorizeImpl{})
|
||||
pkl.RegisterMapping("transactions#MsgDidRegisterService", MsgDidRegisterServiceImpl{})
|
||||
pkl.RegisterMapping("transactions#TxBody", TxBody{})
|
||||
}
|
||||
Reference in New Issue
Block a user