Skip to content

Instantly share code, notes, and snippets.

import { base64url } from '@scure/base';
import { entropyToMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
// Function to convert Base64URL string to Uint8Array
function base64UrlToUint8Array(b64url: string): Uint8Array {
return base64url.decode(b64url + '='.repeat((4 - (b64url.length % 4)) % 4));
}
// Function to convert the private key to a BIP39 mnemonic
  1. In a clean folder, copy connect.ts and recover.ts
  2. Set a password in connect.ts
  3. Run tsx connect.ts and let it run. It'll hang at the sync, let it sit for a 10 sec or so then kill it.
  4. Copy the recovery phrase that prints out, and make note of the did identities it created.
  5. Delete the DATA folder, paste the recovery phrase into recover.ts and run tsx recover.ts

Note You'll need to checkout this branch on our repo and build locally: https://github.com/FormFree/web5-js/tree/api/web5-recover Then you'll need to start a new npm project and run npm install /path/to/FormFree/web5-js/clone/api/web5-recover/branch

@csuwildcat
csuwildcat / dweb.js
Last active September 13, 2024 16:01
import { Web5 } from '@web5/api';
import { DidJwk, DidDht, BearerDid } from '@web5/dids';
import { DwnRegistrar } from '@web5/agent';
import { Web5UserAgent } from '@web5/user-agent';
let initialize;
const instances = {};
const didLabelRegex = /(?:[^@]*@)?(did:[a-z0-9]+:[a-zA-Z0-9-]+)/;
const storage = {
@aelij
aelij / -Usage.cs
Last active March 29, 2024 14:26
IAsyncEnumerable Bridge for Service Fabric Reliable Collections
class MyService : StatefulService
{
private Task<IReliableDictionary<int, string>> AccountNames => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountNames");
private Task<IReliableDictionary<int, string>> AccountData => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountData");
public async Task<List<Account>> SearchAccountsByNameAsync(string name)
{
using (var txn = StateManager.CreateTransaction())
{
var accountNames = await AccountNames;