Skip to content
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

Surface identity proof #11

Merged
merged 3 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ual-anchor",
"version": "0.5.0",
"version": "0.5.1",
"main": "dist/index.js",
"license": "MIT",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions src/Anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Anchor extends Authenticator {
// attempt to restore any existing session for this app
const session = await this.link.restoreSession(this.appName);
if (session) {
this.users = [new AnchorUser(this.rpc, session)]
this.users = [new AnchorUser(this.rpc, { session })]
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ export class Anchor extends Authenticator {
// some changes to UAL are going to be required to support multiple users
if (this.users.length === 0) {
const identity = await this.link.login(this.appName)
this.users = [new AnchorUser(this.rpc, identity.session)]
this.users = [new AnchorUser(this.rpc, identity)]
}
} catch (e) {
throw new UALAnchorError(
Expand Down
25 changes: 17 additions & 8 deletions src/AnchorUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ import { UALAnchorError } from './UALAnchorError'
export class AnchorUser extends User {
public rpc: JsonRpc
public session: any
private signatureProvider: any

public signerKey?: string
public signerProof?: string
public signerRequest?: any

private signatureProvider: any
private chainId: string
private accountName: string = ''
private requestPermission: string = ''

constructor(rpc, session) {
constructor(rpc, identity) {
super()
this.chainId = session.link.chainId
const { session } = identity
this.accountName = session.auth.actor
this.chainId = session.link.chainId
if (identity.signatures) {
[this.signerProof] = identity.signatures
}
if (identity.signerKey) {
this.signerKey = identity.signerKey
}
if (identity.serializedTransaction) {
this.signerRequest = identity.serializedTransaction
}
this.requestPermission = session.auth.permission
this.session = session
this.rpc = rpc
Expand All @@ -38,15 +52,13 @@ export class AnchorUser extends User {
}

async signArbitrary(publicKey: string, data: string, _: string): Promise<string> {
console.log("signArbitrary", publicKey, data)
throw new UALAnchorError(
`Anchor does not currently support signArbitrary`,
UALErrorType.Unsupported,
null)
}

async verifyKeyOwnership(challenge: string): Promise<boolean> {
console.log("verifyKeyOwnership", challenge)
throw new UALAnchorError(
`Anchor does not currently support verifyKeyOwnership`,
UALErrorType.Unsupported,
Expand All @@ -62,7 +74,6 @@ export class AnchorUser extends User {
}

async getKeys() {
console.log("getKeys")
try {
const keys = await this.signatureProvider.getAvailableKeys(this.requestPermission)
return keys
Expand All @@ -76,7 +87,6 @@ export class AnchorUser extends User {
}

async isAccountValid() {
console.log("isAccountValid")
try {
const account = this.rpc && await this.rpc.get_account(this.accountName)
const actualKeys = this.extractAccountKeys(account)
Expand All @@ -98,7 +108,6 @@ export class AnchorUser extends User {
}

extractAccountKeys(account) {
console.log("extractAccountKeys", account)
const keySubsets = account.permissions.map((permission) => permission.required_auth.keys.map((key) => key.key))
let keys = []
for (const keySubset of keySubsets) {
Expand Down