Testnet Mode — switch back to Production in the menuheader when you're done.
VarnirOnboard extends PostProcessEvent
Onboard a brand-new key as an L2 identity (or re-derive an already-onboarded one's stream id).
{
"$selfsign": true,
"$sigs": {
"otk": "<base64 signature of $tx, signed with the new key's own private key>"
},
"$tx": {
"$contract": "<Varnir.Onboard's deployed contract id>",
"$namespace": "varnir",
"$i": {
"otk": {
"publicKey": "<new key's public key hex>",
"type": "secp256k1"
}
}
}
}/**
* Voting round: accepts every transaction (no checks; the 2FA settings
* this once validated are gone).
*
* @returns {Promise<boolean>}
* @memberof VarnirOnboard
*/ public vote(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
// >>> owner-gate
// `$i.otk.extraIdentities` (any value) is refused. commit() would copy it onto the new identity verbatim, with
// any stake and any label, so a raw transaction could be born with a stake-9000 key or two keys that add up to
// the owner. No client in the repo sends it (docs/contracts/owner-only-gates.md); further keys are added with
// Varnir.Keys after onboarding, which sets the stake itself. The copy branch in commit() is then unreachable.
const otk = this.transactions.$i && this.transactions.$i.otk;
if (otk && otk.extraIdentities !== undefined) {
return reject("Onboard - extraIdentities is not accepted; add further keys with Varnir.Keys after onboarding");
}
// <<< owner-gate
// Auto Approve (Left over from when this did 2fa security settings)
return resolve(true);
});
}/**
* Commit round: creates the `identity` stream keyed by
* `$i.otk.publicKey`, with that key as a stake-100 authority plus any
* `extraIdentities`, and state `{type: "identity", address: {}, keys: []}`.
* Emits `user-onboarded` (stream, publicKey, when).
*
* @returns {Promise<any>}
* @memberof VarnirOnboard
*/ public commit(): Promise<any> {
return new Promise<any>(async (resolve, reject) => {
const identity = this.transactions.$i.otk;
// Deterministic: the same public key always onboards to the same
// stream id (newActivityStream's 2nd param is hashed to derive the
// id) - lets a wallet re-derive its own L2 identity purely from a
// recovered key/phrase, no separately-stored identity needed.
const newActiveIdentity = this.newActivityStream("identity", identity.publicKey);
if (identity.extraIdentities && identity.extraIdentities.length) { // Purposly not doing .?
newActiveIdentity.setAuthorities([{ public: identity.publicKey, type: identity.type, stake: 100 }, ...identity.extraIdentities]);
} else {
newActiveIdentity.setAuthorities([{ public: identity.publicKey, type: identity.type, stake: 100 }]);
}
// In the future will have more granular permissions
newActiveIdentity.setState({
type: "identity",
address: {},
keys: []
});
// Lets minigate's own SSE listener push this into the scanner's
// users table - see apps/minigate/src/index.ts and the wallet-assigned
// event this mirrors (apps/contracts/testnet/Varnir.AssignOwner.ts).
this.event.emit('user-onboarded', {
stream: newActiveIdentity.getId(),
publicKey: identity.publicKey,
when: this.cDate,
});
resolve(true);
});
} public postProcess(territoriality: boolean, who: string): Promise<any> {
return new Promise<any>((resolve) => resolve(true));
}