@greymass/account-creation
Advanced tools
Comparing version 0.0.1 to 0.0.2
/** | ||
* @greymass/account-creation v0.0.1 | ||
* @greymass/account-creation v0.0.2 | ||
* https://github.com/greymass/account-creation-lib | ||
@@ -36,27 +36,23 @@ * | ||
*/ | ||
import { NameType, Struct, Bytes } from '@greymass/eosio'; | ||
import { IdentityProof } from 'eosio-signing-request'; | ||
import { NameType, Struct, Name, Bytes, VarUInt } from '@greymass/eosio'; | ||
import { ChainIdType, CallbackPayload, SigningRequest } from 'eosio-signing-request'; | ||
interface AccountCreationOptions { | ||
scope: NameType; | ||
supportedChains?: Record<string, string>; | ||
supportedChains?: ChainIdType[]; | ||
whalesplainerUrl?: string; | ||
returnUrl?: string; | ||
} | ||
interface AccountCreationResponse { | ||
actor?: NameType; | ||
network?: string; | ||
identityProof?: IdentityProof; | ||
error?: string; | ||
interface AccountCreationErrorResponse { | ||
error: string; | ||
} | ||
declare type AccountCreationResponse = CallbackPayload | AccountCreationErrorResponse; | ||
declare class AccountCreator { | ||
readonly options: AccountCreationOptions; | ||
/** Package version. */ | ||
static version: string; | ||
private popupWindow?; | ||
private scope; | ||
private supportedChains?; | ||
private whalesplainerUrl?; | ||
private returnUrl?; | ||
private scope?; | ||
private supportedChains; | ||
private whalesplainerUrl; | ||
private returnUrl; | ||
constructor(options: AccountCreationOptions); | ||
@@ -73,20 +69,37 @@ createAccount(): Promise<AccountCreationResponse>; | ||
declare type CreateRequestType = string | { | ||
declare type CreateRequestType = CreateRequest | string | { | ||
code: string; | ||
login_url?: string; | ||
return_url?: string; | ||
scope?: string; | ||
login_scope?: NameType; | ||
return_path?: string; | ||
}; | ||
declare class CreateRequestInfo extends Struct { | ||
key: VarUInt; | ||
data: Bytes; | ||
} | ||
declare class CreateRequest extends Struct { | ||
static version: number; | ||
/** The sextant account creation code. */ | ||
code: string; | ||
/** Optional URL to post a ESR callback payload with a id proof after the account has been created. */ | ||
login_url?: string; | ||
return_url?: string; | ||
scope?: string; | ||
/** Extra metadata attached to the request. */ | ||
info: CreateRequestInfo[]; | ||
static from(value: CreateRequestType): CreateRequest; | ||
static fromString(value: string): CreateRequest; | ||
/** Login scope, only valid if login_url is set. */ | ||
get login_scope(): Name; | ||
set login_scope(value: NameType); | ||
/** Return path, where Anchor should redirect once done, use only for same-device requests. */ | ||
get return_path(): string; | ||
set return_path(value: string); | ||
/** ESR to sign once account has been created. */ | ||
get loginRequest(): SigningRequest | null; | ||
encode(): Bytes; | ||
toString(includeProtocol?: boolean): string; | ||
private setInfo; | ||
private getInfo; | ||
private removeInfo; | ||
} | ||
export { AccountCreationOptions, AccountCreationResponse, AccountCreator, CreateRequest, CreateRequestType }; | ||
export { AccountCreationErrorResponse, AccountCreationOptions, AccountCreationResponse, AccountCreator, CreateRequest, CreateRequestType }; |
/** | ||
* @greymass/account-creation v0.0.1 | ||
* @greymass/account-creation v0.0.2 | ||
* https://github.com/greymass/account-creation-lib | ||
@@ -118,9 +118,10 @@ * | ||
const accountCreationUrl = 'https://create.anchor.link'; | ||
class AccountCreator { | ||
constructor(options) { | ||
this.options = options; | ||
this.supportedChains = options.supportedChains; | ||
this.scope = options.scope; | ||
this.whalesplainerUrl = options.whalesplainerUrl || accountCreationUrl; | ||
this.supportedChains = (options.supportedChains || []).map((id) => eosioSigningRequest.ChainId.from(id)); | ||
if (options.scope) { | ||
this.scope = eosio.Name.from(options.scope); | ||
} | ||
this.whalesplainerUrl = options.whalesplainerUrl || 'https://create.anchor.link'; | ||
this.returnUrl = options.returnUrl || generateReturnUrl(); | ||
@@ -130,6 +131,12 @@ } | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const supportedChains = this.supportedChains && | ||
`supported_chains=${Object.keys(this.supportedChains).join(',')}`; | ||
const popupWindowUrl = `${this.whalesplainerUrl}/create?${`supported_chains=${supportedChains || ''}`}${`&scope=${this.scope}`}${`&return_url=${this.returnUrl || ''}`}`; | ||
this.popupWindow = window.open(popupWindowUrl, 'targetWindow', `toolbar=no, | ||
const qs = new URLSearchParams(); | ||
qs.set('return_url', this.returnUrl); | ||
if (this.supportedChains.length > 0) { | ||
qs.set('supported_chains', this.supportedChains.map(String).join(',')); | ||
} | ||
if (this.scope) { | ||
qs.set('scope', String(this.scope)); | ||
} | ||
const url = `${this.whalesplainerUrl}/create?${qs}`; | ||
this.popupWindow = window.open(url, 'targetWindow', `toolbar=no, | ||
location=no, | ||
@@ -143,19 +150,9 @@ status=no, | ||
return new Promise((resolve) => { | ||
window.addEventListener('message', (event) => { | ||
const listener = (event) => { | ||
var _a; | ||
if (event.data.status === 'success') { | ||
resolve({ | ||
actor: event.data.actor, | ||
network: event.data.network, | ||
identityProof: event.data.identity_proof, | ||
}); | ||
} | ||
else { | ||
resolve({ | ||
error: event.data.error || | ||
'An error occurred during the account creation process.', | ||
}); | ||
} | ||
window.removeEventListener('message', listener); | ||
(_a = this.popupWindow) === null || _a === void 0 ? void 0 : _a.close(); | ||
}, false); | ||
resolve(event.data); | ||
}; | ||
window.addEventListener('message', listener); | ||
}); | ||
@@ -169,4 +166,2 @@ }); | ||
} | ||
/** Package version. */ | ||
AccountCreator.version = '__ver'; // replaced by build script | ||
@@ -179,2 +174,18 @@ /** | ||
var CreateRequest_1; | ||
var CreateInfoKey; | ||
(function (CreateInfoKey) { | ||
CreateInfoKey[CreateInfoKey["login_scope"] = 1] = "login_scope"; | ||
CreateInfoKey[CreateInfoKey["return_path"] = 2] = "return_path"; | ||
})(CreateInfoKey || (CreateInfoKey = {})); | ||
let CreateRequestInfo = class CreateRequestInfo extends eosio.Struct { | ||
}; | ||
tslib.__decorate([ | ||
eosio.Struct.field('varuint32') | ||
], CreateRequestInfo.prototype, "key", void 0); | ||
tslib.__decorate([ | ||
eosio.Struct.field('bytes') | ||
], CreateRequestInfo.prototype, "data", void 0); | ||
CreateRequestInfo = tslib.__decorate([ | ||
eosio.Struct.type('create_request_info') | ||
], CreateRequestInfo); | ||
exports.CreateRequest = CreateRequest_1 = class CreateRequest extends eosio.Struct { | ||
@@ -186,3 +197,10 @@ static from(value) { | ||
else { | ||
return super.from(value); | ||
const rv = super.from(value); | ||
if (value.login_scope) { | ||
rv.login_scope = value.login_scope; | ||
} | ||
if (value.return_path) { | ||
rv.return_path = value.return_path; | ||
} | ||
return rv; | ||
} | ||
@@ -204,2 +222,35 @@ } | ||
} | ||
/** Login scope, only valid if login_url is set. */ | ||
get login_scope() { | ||
return this.getInfo(CreateInfoKey.login_scope, eosio.Name) || eosio.Name.from(''); | ||
} | ||
set login_scope(value) { | ||
this.setInfo(CreateInfoKey.login_scope, eosio.Name.from(value)); | ||
} | ||
/** Return path, where Anchor should redirect once done, use only for same-device requests. */ | ||
get return_path() { | ||
return this.getInfo(CreateInfoKey.return_path) || ''; | ||
} | ||
set return_path(value) { | ||
if (value) { | ||
this.setInfo(CreateInfoKey.return_path, value); | ||
} | ||
else { | ||
this.removeInfo(CreateInfoKey.return_path); | ||
} | ||
} | ||
/** ESR to sign once account has been created. */ | ||
get loginRequest() { | ||
if (!this.login_url) { | ||
return null; | ||
} | ||
return eosioSigningRequest.SigningRequest.createSync({ | ||
identity: { scope: this.login_scope }, | ||
chainId: null, | ||
callback: { url: this.login_url, background: true }, | ||
info: { | ||
return_path: this.return_path, | ||
}, | ||
}); | ||
} | ||
encode() { | ||
@@ -216,2 +267,36 @@ const data = eosio.Serializer.encode({ object: this }); | ||
} | ||
setInfo(key, value, type) { | ||
let data; | ||
if (typeof value === 'string' && !type) { | ||
data = eosio.Bytes.from(value, 'utf8'); | ||
} | ||
else if (eosio.isInstanceOf(value, eosio.Bytes) && !type) { | ||
data = value; | ||
} | ||
else { | ||
data = eosio.Serializer.encode({ object: value, type }); | ||
} | ||
const existing = this.info.find((i) => Number(i.key) === key); | ||
if (existing) { | ||
existing.data = data; | ||
} | ||
else { | ||
this.info.push(CreateRequestInfo.from({ key, data })); | ||
} | ||
} | ||
getInfo(key, type) { | ||
var _a; | ||
const info = (_a = this.info) === null || _a === void 0 ? void 0 : _a.find((info) => Number(info.key) === key); | ||
if (info) { | ||
if (type) { | ||
return eosio.Serializer.decode({ data: info.data, type }); | ||
} | ||
else { | ||
return info.data.utf8String; | ||
} | ||
} | ||
} | ||
removeInfo(key) { | ||
this.info = this.info.filter((info) => Number(info.key) !== key); | ||
} | ||
}; | ||
@@ -226,9 +311,6 @@ exports.CreateRequest.version = 1; | ||
tslib.__decorate([ | ||
eosio.Struct.field('string$') | ||
], exports.CreateRequest.prototype, "return_url", void 0); | ||
tslib.__decorate([ | ||
eosio.Struct.field('string$') | ||
], exports.CreateRequest.prototype, "scope", void 0); | ||
eosio.Struct.field(CreateRequestInfo, { array: true, extension: true }) | ||
], exports.CreateRequest.prototype, "info", void 0); | ||
exports.CreateRequest = CreateRequest_1 = tslib.__decorate([ | ||
eosio.Struct.type('create_payload') | ||
eosio.Struct.type('create_request') | ||
], exports.CreateRequest); | ||
@@ -235,0 +317,0 @@ |
/** | ||
* @greymass/account-creation v0.0.1 | ||
* @greymass/account-creation v0.0.2 | ||
* https://github.com/greymass/account-creation-lib | ||
@@ -36,5 +36,5 @@ * | ||
*/ | ||
import { Name, Struct, Serializer, Bytes, isInstanceOf } from '@greymass/eosio'; | ||
import { ChainId, Base64u, SigningRequest } from 'eosio-signing-request'; | ||
import { __decorate } from 'tslib'; | ||
import { Struct, Serializer, Bytes } from '@greymass/eosio'; | ||
import { Base64u } from 'eosio-signing-request'; | ||
@@ -115,16 +115,23 @@ /** Generate a return url that Anchor will redirect back to w/o reload. */ | ||
const accountCreationUrl = 'https://create.anchor.link'; | ||
class AccountCreator { | ||
constructor(options) { | ||
this.options = options; | ||
this.supportedChains = options.supportedChains; | ||
this.scope = options.scope; | ||
this.whalesplainerUrl = options.whalesplainerUrl || accountCreationUrl; | ||
this.supportedChains = (options.supportedChains || []).map((id) => ChainId.from(id)); | ||
if (options.scope) { | ||
this.scope = Name.from(options.scope); | ||
} | ||
this.whalesplainerUrl = options.whalesplainerUrl || 'https://create.anchor.link'; | ||
this.returnUrl = options.returnUrl || generateReturnUrl(); | ||
} | ||
async createAccount() { | ||
const supportedChains = this.supportedChains && | ||
`supported_chains=${Object.keys(this.supportedChains).join(',')}`; | ||
const popupWindowUrl = `${this.whalesplainerUrl}/create?${`supported_chains=${supportedChains || ''}`}${`&scope=${this.scope}`}${`&return_url=${this.returnUrl || ''}`}`; | ||
this.popupWindow = window.open(popupWindowUrl, 'targetWindow', `toolbar=no, | ||
const qs = new URLSearchParams(); | ||
qs.set('return_url', this.returnUrl); | ||
if (this.supportedChains.length > 0) { | ||
qs.set('supported_chains', this.supportedChains.map(String).join(',')); | ||
} | ||
if (this.scope) { | ||
qs.set('scope', String(this.scope)); | ||
} | ||
const url = `${this.whalesplainerUrl}/create?${qs}`; | ||
this.popupWindow = window.open(url, 'targetWindow', `toolbar=no, | ||
location=no, | ||
@@ -138,18 +145,8 @@ status=no, | ||
return new Promise((resolve) => { | ||
window.addEventListener('message', (event) => { | ||
if (event.data.status === 'success') { | ||
resolve({ | ||
actor: event.data.actor, | ||
network: event.data.network, | ||
identityProof: event.data.identity_proof, | ||
}); | ||
} | ||
else { | ||
resolve({ | ||
error: event.data.error || | ||
'An error occurred during the account creation process.', | ||
}); | ||
} | ||
const listener = (event) => { | ||
window.removeEventListener('message', listener); | ||
this.popupWindow?.close(); | ||
}, false); | ||
resolve(event.data); | ||
}; | ||
window.addEventListener('message', listener); | ||
}); | ||
@@ -161,4 +158,2 @@ } | ||
} | ||
/** Package version. */ | ||
AccountCreator.version = '__ver'; // replaced by build script | ||
@@ -171,2 +166,18 @@ /** | ||
var CreateRequest_1; | ||
var CreateInfoKey; | ||
(function (CreateInfoKey) { | ||
CreateInfoKey[CreateInfoKey["login_scope"] = 1] = "login_scope"; | ||
CreateInfoKey[CreateInfoKey["return_path"] = 2] = "return_path"; | ||
})(CreateInfoKey || (CreateInfoKey = {})); | ||
let CreateRequestInfo = class CreateRequestInfo extends Struct { | ||
}; | ||
__decorate([ | ||
Struct.field('varuint32') | ||
], CreateRequestInfo.prototype, "key", void 0); | ||
__decorate([ | ||
Struct.field('bytes') | ||
], CreateRequestInfo.prototype, "data", void 0); | ||
CreateRequestInfo = __decorate([ | ||
Struct.type('create_request_info') | ||
], CreateRequestInfo); | ||
let CreateRequest = CreateRequest_1 = class CreateRequest extends Struct { | ||
@@ -178,3 +189,10 @@ static from(value) { | ||
else { | ||
return super.from(value); | ||
const rv = super.from(value); | ||
if (value.login_scope) { | ||
rv.login_scope = value.login_scope; | ||
} | ||
if (value.return_path) { | ||
rv.return_path = value.return_path; | ||
} | ||
return rv; | ||
} | ||
@@ -196,2 +214,35 @@ } | ||
} | ||
/** Login scope, only valid if login_url is set. */ | ||
get login_scope() { | ||
return this.getInfo(CreateInfoKey.login_scope, Name) || Name.from(''); | ||
} | ||
set login_scope(value) { | ||
this.setInfo(CreateInfoKey.login_scope, Name.from(value)); | ||
} | ||
/** Return path, where Anchor should redirect once done, use only for same-device requests. */ | ||
get return_path() { | ||
return this.getInfo(CreateInfoKey.return_path) || ''; | ||
} | ||
set return_path(value) { | ||
if (value) { | ||
this.setInfo(CreateInfoKey.return_path, value); | ||
} | ||
else { | ||
this.removeInfo(CreateInfoKey.return_path); | ||
} | ||
} | ||
/** ESR to sign once account has been created. */ | ||
get loginRequest() { | ||
if (!this.login_url) { | ||
return null; | ||
} | ||
return SigningRequest.createSync({ | ||
identity: { scope: this.login_scope }, | ||
chainId: null, | ||
callback: { url: this.login_url, background: true }, | ||
info: { | ||
return_path: this.return_path, | ||
}, | ||
}); | ||
} | ||
encode() { | ||
@@ -208,2 +259,35 @@ const data = Serializer.encode({ object: this }); | ||
} | ||
setInfo(key, value, type) { | ||
let data; | ||
if (typeof value === 'string' && !type) { | ||
data = Bytes.from(value, 'utf8'); | ||
} | ||
else if (isInstanceOf(value, Bytes) && !type) { | ||
data = value; | ||
} | ||
else { | ||
data = Serializer.encode({ object: value, type }); | ||
} | ||
const existing = this.info.find((i) => Number(i.key) === key); | ||
if (existing) { | ||
existing.data = data; | ||
} | ||
else { | ||
this.info.push(CreateRequestInfo.from({ key, data })); | ||
} | ||
} | ||
getInfo(key, type) { | ||
const info = this.info?.find((info) => Number(info.key) === key); | ||
if (info) { | ||
if (type) { | ||
return Serializer.decode({ data: info.data, type }); | ||
} | ||
else { | ||
return info.data.utf8String; | ||
} | ||
} | ||
} | ||
removeInfo(key) { | ||
this.info = this.info.filter((info) => Number(info.key) !== key); | ||
} | ||
}; | ||
@@ -218,9 +302,6 @@ CreateRequest.version = 1; | ||
__decorate([ | ||
Struct.field('string$') | ||
], CreateRequest.prototype, "return_url", void 0); | ||
__decorate([ | ||
Struct.field('string$') | ||
], CreateRequest.prototype, "scope", void 0); | ||
Struct.field(CreateRequestInfo, { array: true, extension: true }) | ||
], CreateRequest.prototype, "info", void 0); | ||
CreateRequest = CreateRequest_1 = __decorate([ | ||
Struct.type('create_payload') | ||
Struct.type('create_request') | ||
], CreateRequest); | ||
@@ -227,0 +308,0 @@ |
{ | ||
"name": "@greymass/account-creation", | ||
"description": "An account creation library for EOSIO chains that leverages Anchor.", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/greymass/account-creation-lib", | ||
@@ -18,4 +18,7 @@ "license": "BSD-3-Clause", | ||
}, | ||
"resolutions": { | ||
"@greymass/eosio": "^0.6.0" | ||
}, | ||
"dependencies": { | ||
"@greymass/eosio": "^0.5.2", | ||
"@greymass/eosio": "^0.6.0", | ||
"eosio-signing-request": "^2.3.1", | ||
@@ -31,2 +34,3 @@ "tslib": "^2.1.0" | ||
"@rollup/plugin-virtual": "^2.0.3", | ||
"@types/chai": "^4.3.1", | ||
"@types/mocha": "^9.0.0", | ||
@@ -33,0 +37,0 @@ "@types/node": "^16.4.0", |
@@ -1,24 +0,20 @@ | ||
import { NameType } from '@greymass/eosio' | ||
import { Name } from '@greymass/eosio' | ||
import { ChainId } from 'eosio-signing-request' | ||
import { generateReturnUrl } from './utils' | ||
import { AccountCreationOptions, AccountCreationResponse } from './types' | ||
const accountCreationUrl = 'https://create.anchor.link' | ||
export class AccountCreator { | ||
/** Package version. */ | ||
static version = '__ver' // replaced by build script | ||
private popupWindow?: Window | ||
private scope?: Name | ||
private supportedChains: ChainId[] | ||
private whalesplainerUrl: string | ||
private returnUrl: string | ||
private scope: NameType | ||
private supportedChains?: Record<string, string> | ||
private whalesplainerUrl?: string | ||
private returnUrl?: string | ||
constructor(public readonly options: AccountCreationOptions) { | ||
this.supportedChains = options.supportedChains | ||
this.scope = options.scope | ||
this.whalesplainerUrl = options.whalesplainerUrl || accountCreationUrl | ||
this.supportedChains = (options.supportedChains || []).map((id) => ChainId.from(id)) | ||
if (options.scope) { | ||
this.scope = Name.from(options.scope) | ||
} | ||
this.whalesplainerUrl = options.whalesplainerUrl || 'https://create.anchor.link' | ||
this.returnUrl = options.returnUrl || generateReturnUrl() | ||
@@ -28,11 +24,13 @@ } | ||
async createAccount(): Promise<AccountCreationResponse> { | ||
const supportedChains = | ||
this.supportedChains && | ||
`supported_chains=${Object.keys(this.supportedChains).join(',')}` | ||
const popupWindowUrl = `${this.whalesplainerUrl}/create?${`supported_chains=${ | ||
supportedChains || '' | ||
}`}${`&scope=${this.scope}`}${`&return_url=${this.returnUrl || ''}`}` | ||
const qs = new URLSearchParams() | ||
qs.set('return_url', this.returnUrl) | ||
if (this.supportedChains.length > 0) { | ||
qs.set('supported_chains', this.supportedChains.map(String).join(',')) | ||
} | ||
if (this.scope) { | ||
qs.set('scope', String(this.scope)) | ||
} | ||
const url = `${this.whalesplainerUrl}/create?${qs}` | ||
this.popupWindow = window.open( | ||
popupWindowUrl, | ||
url, | ||
'targetWindow', | ||
@@ -50,23 +48,8 @@ `toolbar=no, | ||
return new Promise((resolve) => { | ||
window.addEventListener( | ||
'message', | ||
(event) => { | ||
if (event.data.status === 'success') { | ||
resolve({ | ||
actor: event.data.actor, | ||
network: event.data.network, | ||
identityProof: event.data.identity_proof, | ||
}) | ||
} else { | ||
resolve({ | ||
error: | ||
event.data.error || | ||
'An error occurred during the account creation process.', | ||
}) | ||
} | ||
this.popupWindow?.close() | ||
}, | ||
false | ||
) | ||
const listener = (event: MessageEvent) => { | ||
window.removeEventListener('message', listener) | ||
this.popupWindow?.close() | ||
resolve(event.data) | ||
} | ||
window.addEventListener('message', listener) | ||
}) | ||
@@ -73,0 +56,0 @@ } |
@@ -7,6 +7,18 @@ /** | ||
import { Bytes, Serializer, Struct } from '@greymass/eosio' | ||
import { Base64u } from 'eosio-signing-request' | ||
import { | ||
ABISerializable, | ||
ABISerializableConstructor, | ||
ABISerializableType, | ||
Bytes, | ||
isInstanceOf, | ||
Name, | ||
NameType, | ||
Serializer, | ||
Struct, | ||
VarUInt, | ||
} from '@greymass/eosio' | ||
import { Base64u, SigningRequest } from 'eosio-signing-request' | ||
export type CreateRequestType = | ||
| CreateRequest | ||
| string | ||
@@ -16,15 +28,30 @@ | { | ||
login_url?: string | ||
return_url?: string | ||
scope?: string | ||
login_scope?: NameType | ||
return_path?: string | ||
} | ||
@Struct.type('create_payload') | ||
enum CreateInfoKey { | ||
login_scope = 1, | ||
return_path = 2, | ||
} | ||
@Struct.type('create_request_info') | ||
class CreateRequestInfo extends Struct { | ||
@Struct.field('varuint32') declare key: VarUInt | ||
@Struct.field('bytes') declare data: Bytes | ||
} | ||
@Struct.type('create_request') | ||
export class CreateRequest extends Struct { | ||
static version = 1 | ||
/** The sextant account creation code. */ | ||
@Struct.field('string') declare code: string | ||
/** Optional URL to post a ESR callback payload with a id proof after the account has been created. */ | ||
@Struct.field('string?') declare login_url?: string | ||
@Struct.field('string$') declare return_url?: string | ||
@Struct.field('string$') declare scope?: string | ||
/** Extra metadata attached to the request. */ | ||
@Struct.field(CreateRequestInfo, { array: true, extension: true }) | ||
declare info: CreateRequestInfo[] | ||
static from(value: CreateRequestType): CreateRequest { | ||
@@ -34,3 +61,10 @@ if (typeof value === 'string') { | ||
} else { | ||
return super.from(value) as CreateRequest | ||
const rv = super.from(value) as CreateRequest | ||
if (value.login_scope) { | ||
rv.login_scope = value.login_scope | ||
} | ||
if (value.return_path) { | ||
rv.return_path = value.return_path | ||
} | ||
return rv | ||
} | ||
@@ -54,2 +88,37 @@ } | ||
/** Login scope, only valid if login_url is set. */ | ||
get login_scope(): Name { | ||
return this.getInfo(CreateInfoKey.login_scope, Name) || Name.from('') | ||
} | ||
set login_scope(value: NameType) { | ||
this.setInfo(CreateInfoKey.login_scope, Name.from(value)) | ||
} | ||
/** Return path, where Anchor should redirect once done, use only for same-device requests. */ | ||
get return_path(): string { | ||
return this.getInfo(CreateInfoKey.return_path) || '' | ||
} | ||
set return_path(value: string) { | ||
if (value) { | ||
this.setInfo(CreateInfoKey.return_path, value) | ||
} else { | ||
this.removeInfo(CreateInfoKey.return_path) | ||
} | ||
} | ||
/** ESR to sign once account has been created. */ | ||
get loginRequest(): SigningRequest | null { | ||
if (!this.login_url) { | ||
return null | ||
} | ||
return SigningRequest.createSync({ | ||
identity: { scope: this.login_scope }, | ||
chainId: null, | ||
callback: { url: this.login_url, background: true }, | ||
info: { | ||
return_path: this.return_path, | ||
}, | ||
}) | ||
} | ||
encode() { | ||
@@ -67,2 +136,40 @@ const data = Serializer.encode({ object: this }) | ||
} | ||
private setInfo(key: CreateInfoKey, value: ABISerializable, type?: ABISerializableType) { | ||
let data: Bytes | ||
if (typeof value === 'string' && !type) { | ||
data = Bytes.from(value, 'utf8') | ||
} else if (isInstanceOf(value, Bytes) && !type) { | ||
data = value | ||
} else { | ||
data = Serializer.encode({ object: value, type }) | ||
} | ||
const existing = this.info.find((i) => Number(i.key) === key) | ||
if (existing) { | ||
existing.data = data | ||
} else { | ||
this.info.push(CreateRequestInfo.from({ key, data })) | ||
} | ||
} | ||
private getInfo(key: CreateInfoKey): string | ||
private getInfo<T extends ABISerializableConstructor>( | ||
key: CreateInfoKey, | ||
type: T | ||
): InstanceType<T> | ||
private getInfo(key: CreateInfoKey, type: ABISerializableType): any | ||
private getInfo(key: CreateInfoKey, type?: ABISerializableType): any { | ||
const info = this.info?.find((info) => Number(info.key) === key) | ||
if (info) { | ||
if (type) { | ||
return Serializer.decode({ data: info.data, type }) | ||
} else { | ||
return info.data.utf8String | ||
} | ||
} | ||
} | ||
private removeInfo(key: CreateInfoKey) { | ||
this.info = this.info.filter((info) => Number(info.key) !== key) | ||
} | ||
} |
export * from './account-creator' | ||
export * from './create-request' | ||
export * from './types' |
import { NameType } from '@greymass/eosio' | ||
import { IdentityProof } from 'eosio-signing-request' | ||
import type { CallbackPayload, ChainIdType } from 'eosio-signing-request' | ||
export interface AccountCreationOptions { | ||
scope: NameType | ||
supportedChains?: Record<string, string> | ||
supportedChains?: ChainIdType[] | ||
whalesplainerUrl?: string | ||
returnUrl?: string | ||
} | ||
export interface AccountCreationResponse { | ||
actor?: NameType | ||
export interface AccountCreationErrorResponse { | ||
error: string | ||
} | ||
network?: string | ||
identityProof?: IdentityProof | ||
error?: string | ||
} | ||
export type AccountCreationResponse = CallbackPayload | AccountCreationErrorResponse |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57030
993
26
- Removed@greymass/eosio@0.5.5(transitive)
Updated@greymass/eosio@^0.6.0