Skip to content

Storage layer for multiple accounts #3059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
763a372
basic memory and struct setup
LXIF Apr 29, 2025
fdb13bd
add lookup application with origin functionality and origin hashing
LXIF Apr 29, 2025
aa2ad50
add lookup_or_insert functionality
LXIF Apr 30, 2025
95a507b
many improvements, add list_accounts and further transformations
LXIF Apr 30, 2025
d5a4375
First test passing
lmuntaner May 5, 2025
44a4d98
Clean up and add list_accounts test
lmuntaner May 5, 2025
608ef71
Improve comment
lmuntaner May 5, 2025
7f860ab
Fix formatting
lmuntaner May 5, 2025
17eabcf
Fix clippy
lmuntaner May 5, 2025
7a85129
Fix format
lmuntaner May 5, 2025
bf6c93e
Revert recover test
lmuntaner May 5, 2025
2f2c21e
Fix comments
lmuntaner May 5, 2025
c78c244
Improve comments
lmuntaner May 5, 2025
fbeadce
Use Account from did
lmuntaner May 5, 2025
30c204a
Rename to avoid confusion
lmuntaner May 5, 2025
781cd96
Rename back to InternalAccount
lmuntaner May 5, 2025
52a4fab
Fix format
lmuntaner May 5, 2025
2b18794
Use `new` of InternalAccount
lmuntaner May 5, 2025
0cbb5a1
Remove anchor number from Account
lmuntaner May 5, 2025
86a6ff5
Cleaning and improving comments
lmuntaner May 6, 2025
ddef620
Tests passing with new logic
lmuntaner May 7, 2025
3658317
Revert main and implement update_account
lmuntaner May 7, 2025
2684764
Fix format
lmuntaner May 7, 2025
01bc773
Refactor types
lmuntaner May 7, 2025
1faeaff
Rename types
lmuntaner May 7, 2025
f964d68
Clean up and move some code
lmuntaner May 7, 2025
f4550b2
Refactor read_account
lmuntaner May 7, 2025
d09aea5
Change OriginHash hashing strategy
lmuntaner May 7, 2025
6c892a8
Add and fix a test
lmuntaner May 7, 2025
76abb45
Formatting
lmuntaner May 7, 2025
71173aa
Fix clippy
lmuntaner May 7, 2025
d7984e8
Generate declarations
lmuntaner May 7, 2025
8d867f7
Refactor tests and fix type issue
lmuntaner May 7, 2025
edac898
Clean up comments and minor refactor
lmuntaner May 7, 2025
55a65aa
Formatting
lmuntaner May 7, 2025
cc4c98a
Revert some unnecessary changes
lmuntaner May 7, 2025
0d7908b
Revert
lmuntaner May 7, 2025
9943d98
Refactor types
lmuntaner May 7, 2025
fbb8381
Add counters and a test for the counters
lmuntaner May 8, 2025
87bda1a
Fix formatting
lmuntaner May 8, 2025
8ebd671
Fix clippy
lmuntaner May 8, 2025
e2dd951
Fix clippy
lmuntaner May 8, 2025
476fba3
fix test issues
lmuntaner May 8, 2025
e83a539
fix formatting
lmuntaner May 8, 2025
4f54e1f
Fix bug in update_counters
lmuntaner May 9, 2025
ddca986
Fix test
lmuntaner May 9, 2025
dabdaac
Fix test
lmuntaner May 9, 2025
759414d
Update counters first
lmuntaner May 12, 2025
25773de
Fix format
lmuntaner May 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/frontend/src/lib/generated/internet_identity_idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const idlFactory = ({ IDL }) => {
});
const FrontendHostname = IDL.Text;
const AccountNumber = IDL.Nat64;
const Account = IDL.Record({
const AccountInfo = IDL.Record({
'name' : IDL.Opt(IDL.Text),
'origin' : IDL.Text,
'account_number' : IDL.Opt(AccountNumber),
Expand Down Expand Up @@ -519,7 +519,7 @@ export const idlFactory = ({ IDL }) => {
'config' : IDL.Func([], [InternetIdentityInit], ['query']),
'create_account' : IDL.Func(
[UserNumber, FrontendHostname, IDL.Text],
[IDL.Variant({ 'Ok' : Account, 'Err' : CreateAccountError })],
[IDL.Variant({ 'Ok' : AccountInfo, 'Err' : CreateAccountError })],
[],
),
'create_challenge' : IDL.Func([], [Challenge], []),
Expand All @@ -534,7 +534,7 @@ export const idlFactory = ({ IDL }) => {
),
'get_accounts' : IDL.Func(
[UserNumber, FrontendHostname],
[IDL.Vec(Account)],
[IDL.Vec(AccountInfo)],
['query'],
),
'get_anchor_credentials' : IDL.Func(
Expand Down Expand Up @@ -664,7 +664,7 @@ export const idlFactory = ({ IDL }) => {
'update' : IDL.Func([UserNumber, DeviceKey, DeviceData], [], []),
'update_account' : IDL.Func(
[UserNumber, FrontendHostname, IDL.Opt(AccountNumber), AccountUpdate],
[IDL.Variant({ 'Ok' : Account, 'Err' : UpdateAccountError })],
[IDL.Variant({ 'Ok' : AccountInfo, 'Err' : UpdateAccountError })],
[],
),
'verify_tentative_device' : IDL.Func(
Expand Down
11 changes: 7 additions & 4 deletions src/frontend/src/lib/generated/internet_identity_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface Account {
export interface AccountInfo {
'name' : [] | [string],
'origin' : string,
'account_number' : [] | [AccountNumber],
Expand Down Expand Up @@ -423,7 +423,7 @@ export interface _SERVICE {
'config' : ActorMethod<[], InternetIdentityInit>,
'create_account' : ActorMethod<
[UserNumber, FrontendHostname, string],
{ 'Ok' : Account } |
{ 'Ok' : AccountInfo } |
{ 'Err' : CreateAccountError }
>,
'create_challenge' : ActorMethod<[], Challenge>,
Expand All @@ -435,7 +435,10 @@ export interface _SERVICE {
[UserNumber, FrontendHostname, AccountNumber, SessionKey, Timestamp],
GetDelegationResponse
>,
'get_accounts' : ActorMethod<[UserNumber, FrontendHostname], Array<Account>>,
'get_accounts' : ActorMethod<
[UserNumber, FrontendHostname],
Array<AccountInfo>
>,
'get_anchor_credentials' : ActorMethod<[UserNumber], AnchorCredentials>,
'get_anchor_info' : ActorMethod<[UserNumber], IdentityAnchorInfo>,
'get_delegation' : ActorMethod<
Expand Down Expand Up @@ -535,7 +538,7 @@ export interface _SERVICE {
'update' : ActorMethod<[UserNumber, DeviceKey, DeviceData], undefined>,
'update_account' : ActorMethod<
[UserNumber, FrontendHostname, [] | [AccountNumber], AccountUpdate],
{ 'Ok' : Account } |
{ 'Ok' : AccountInfo } |
{ 'Err' : UpdateAccountError }
>,
'verify_tentative_device' : ActorMethod<
Expand Down
8 changes: 4 additions & 4 deletions src/internet_identity/internet_identity.did
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ type IdRegFinishError = variant {
StorageError : text;
};

type Account = record {
type AccountInfo = record {
// Null is unreserved default account
account_number : opt AccountNumber;
origin : text;
Expand Down Expand Up @@ -843,20 +843,20 @@ service : (opt InternetIdentityInit) -> {
get_accounts : (
anchor_number : UserNumber,
origin : FrontendHostname,
) -> (vec Account) query;
) -> (vec AccountInfo) query;

create_account : (
anchor_number : UserNumber,
origin : FrontendHostname,
name : text
) -> (variant { Ok : Account; Err: CreateAccountError });
) -> (variant { Ok : AccountInfo; Err: CreateAccountError });

update_account : (
anchor_number : UserNumber,
origin : FrontendHostname,
account_number : opt AccountNumber, // Null is unreserved default account
update : AccountUpdate
) -> (variant { Ok : Account; Err: UpdateAccountError });
) -> (variant { Ok : AccountInfo; Err: UpdateAccountError });

prepare_account_delegation : (
anchor_number : UserNumber,
Expand Down
14 changes: 7 additions & 7 deletions src/internet_identity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ fn get_delegation(
}

#[query]
fn get_accounts(_anchor_number: AnchorNumber, _origin: FrontendHostname) -> Vec<Account> {
fn get_accounts(_anchor_number: AnchorNumber, _origin: FrontendHostname) -> Vec<AccountInfo> {
vec![
Account {
AccountInfo {
account_number: None,
origin: "example.com".to_string(),
last_used: Some(0u64),
name: Some("Default Mock Account".to_string()),
},
Account {
AccountInfo {
account_number: Some(1),
origin: "example.com".to_string(),
last_used: Some(0u64),
Expand All @@ -320,8 +320,8 @@ fn create_account(
_anchor_number: AnchorNumber,
_origin: FrontendHostname,
name: String,
) -> Result<Account, CreateAccountError> {
Ok(Account {
) -> Result<AccountInfo, CreateAccountError> {
Ok(AccountInfo {
account_number: Some(ic_cdk::api::time()),
origin: "example.com".to_string(),
last_used: None,
Expand All @@ -335,8 +335,8 @@ fn update_account(
_origin: FrontendHostname,
_account_number: Option<AccountNumber>,
_update: AccountUpdate,
) -> Result<Account, UpdateAccountError> {
Ok(Account {
) -> Result<AccountInfo, UpdateAccountError> {
Ok(AccountInfo {
account_number: None,
origin: "example.com".to_string(),
last_used: Some(0u64),
Expand Down
Loading
Loading