Corey d33a9ee4a4 Merge pull request #15 from pubky/recovery-file
feat: add create_recovery_file decrypt_recovery_file
2024-10-03 08:51:32 -04:00
2024-09-20 12:42:01 -04:00
2024-09-11 22:03:27 -04:00
2024-09-21 16:35:14 -04:00
2024-09-15 12:35:12 -04:00
2024-09-11 22:03:27 -04:00
2024-09-11 22:03:27 -04:00
2024-09-24 20:19:28 -04:00
2024-09-15 12:38:04 -04:00
2024-09-15 12:35:12 -04:00
2024-09-11 22:03:27 -04:00
2024-09-15 12:35:12 -04:00
2024-09-11 22:03:27 -04:00
2024-09-20 12:42:01 -04:00

react-native-pubky

React Native implementation of pubky

Installation

npm install @synonymdev/react-native-pubky

Implementation Status

Implemented Methods

Methods to be Implemented

  • getProfile: Retrieve the profile of a user.
  • editProfile: Submit changes to the specified profile.

Usage

Auth

import { auth } from '@synonymdev/react-native-pubky';

const authRes = await auth(
  'pubkyauth:///?caps=/pub/pubky.app/:rw,/pub/foo.bar/file:r&secret=U55XnoH6vsMCpx1pxHtt8fReVg4Brvu9C0gUBuw-Jkw&relay=http://167.86.102.121:4173/',
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
);
if (authRes.isErr()) {
  console.log(authRes.error.message);
  return;
}
console.log(authRes.value);

parseAuthUrl

import { parseAuthUrl } from '@synonymdev/react-native-pubky';

const pubkyAuthUrl = 'pubkyauth:///?relay=https://demo.httprelay.io/link&capabilities=/pub/pubky.app:rw,/pub/example.com/nested:rw&secret=FyzJ3gJ1W7boyFZC1Do9fYrRmDNgCLNRwEu_gaBgPUA';
const parseRes = await parseAuthUrl(pubkyAuthUrl);
if (parseRes.isErr()) {
  console.log(parseRes.error.message);
  return;
}
console.log(parseRes.value);

publish

import { publish } from '@synonymdev/react-native-pubky';

const publishRes = await publish(
  'recordnametest',
  'recordcontenttest',
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
);
if (publishRes.isErr()) {
  console.log(publishRes.error.message);
  return;
}
console.log(publishRes.value);

resolve

import { resolve } from '@synonymdev/react-native-pubky';

const resolveRes = await resolve(
  'z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty'
);
if (resolveRes.isErr()) {
  console.log(resolveRes.error.message);
  return;
}
console.log(resolveRes.value);

publishHttps

import { publishHttps } from '@synonymdev/react-native-pubky';

const publishHttpsRes = await publishHttps(
  'example.com', // Record Name
  'target.example.com', // Target
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
);
if (publishHttpsRes.isErr()) {
  console.log(publishHttpsRes.error.message);
  return;
}
console.log(publishHttpsRes.value);

resolveHttps

import { resolveHttps } from '@synonymdev/react-native-pubky';

const resolveHttpsRes = await resolveHttps(
  'z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty' // Public key
);
if (resolveHttpsRes.isErr()) {
  console.log(resolveHttpsRes.error.message);
  return;
}
console.log(resolveHttpsRes.value);

put

import { put } from '@synonymdev/react-native-pubky';

const putRes = await put(
  'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/synonym.to', // URL
  { data: 'test content' }, // Content
);
if (putRes.isErr()) {
  console.log(putRes.error.message);
  return;
}
console.log(putRes.value);

get

import { get } from '@synonymdev/react-native-pubky';

const getRes = await get(
  'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/synonym.to' // URL
);
if (getRes.isErr()) {
  console.log(getRes.error.message);
  return;
}
console.log(getRes.value);

list

import { list } from '@synonymdev/react-native-pubky';

const listRes = await list(
  'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/' // URL
);
if (listRes.isErr()) {
  console.log(listRes.error.message);
  return;
}
console.log(listRes.value);

generateSecretKey

import { generateSecretKey } from '@synonymdev/react-native-pubky';

const generateSecretKeyRes = await generateSecretKey();
if (generateSecretKeyRes.isErr()) {
  console.log(generateSecretKeyRes.error.message);
  return;
}
console.log(generateSecretKeyRes.value);

getPublicKeyFromSecretKey

import { getPublicKeyFromSecretKey } from '@synonymdev/react-native-pubky';

const getPublicKeyFromSecretKeyRes = await getPublicKeyFromSecretKey('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
if (getPublicKeyFromSecretKeyRes.isErr()) {
  console.log(getPublicKeyFromSecretKeyRes.error.message);
  return;
}
console.log(getPublicKeyFromSecretKeyRes.value);

signUp

import { signUp } from '@synonymdev/react-native-pubky';

const signUpRes = await signUp(
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret
  'pubky://8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo', // Homeserver
);
if (signUpRes.isErr()) {
  console.log(signUpRes.error.message);
  return;
}
console.log(signUpRes.value);

signIn

import { signIn } from '@synonymdev/react-native-pubky';

const signInRes = await signIn(
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
);
if (signInRes.isErr()) {
  console.log(signInRes.error.message);
  return;
}
console.log(signInRes.value);

signIn

import { signOut } from '@synonymdev/react-native-pubky';

const signOutRes = await signOut(
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
);
if (signOutRes.isErr()) {
  console.log(signOutRes.error.message);
  return;
}
console.log(signOutRes.value);

createRecoveryFile

import { createRecoveryFile } from '@synonymdev/react-native-pubky';

const createRecoveryFileRes = await createRecoveryFile(
  'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret Key
  'passphrase', // Passphrase
);
if (createRecoveryFileRes.isErr()) {
  console.log(createRecoveryFileRes.error.message);
  return;
}
console.log(createRecoveryFileRes.value);

decryptRecoveryFile

import { decryptRecoveryFile } from '@synonymdev/react-native-pubky';

const decryptRecoveryFileRes = await decryptRecoveryFile(
  'cHVia3kub3JnL3JlY292ZXJ5CkZRt1NHIjxyTo0whSSgTgNrH56MPpGrSxvAQSE0x5FeklVJpNJqcNP4zjdwW/OpdBOsEC1qZ5MI/mcEUKFKVAEZwikdclsLZg==', // Recovery File
  'passphrase', // Passphrase
);
if (decryptRecoveryFileRes.isErr()) {
  console.log(decryptRecoveryFileRes.error.message);
  return;
}
console.log(decryptRecoveryFileRes.value);

Local Installation

  1. Clone & npm install:
git clone git@github.com:pubky/react-native-pubky.git && cd react-native-pubky && npm i
  1. Delete the rust/pubky directory to prevent a memory error (This step will be removed once pubky is public).
  2. Yarn add it to your project:
yarn add path/to/react-native-pubky

Update Bindings

After making changes to any of the Rust files, the bindings will need to be updated. To do this, run the following command:

npm run update-bindings

Finally, ensure that PubkyModule.kt, Pubky.swift, Pubky.mm & src/index.tsx are updated accordingly based on the changes made to the Rust files.

License

MIT


Resources

Description
No description provided
Readme MIT 451 MiB
Languages
Kotlin 38.3%
Swift 23%
C 12.7%
TypeScript 10.7%
JavaScript 9.5%
Other 5.8%