Skip to content

Commit

Permalink
Surface identity proof (#11)
Browse files Browse the repository at this point in the history
* Upon initial login, expose the identity proof values.

* Removed debug strings

* Update package.json
  • Loading branch information
aaroncox authored Aug 10, 2020
1 parent 05cef81 commit dd9b340
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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

0 comments on commit dd9b340

Please sign in to comment.