Skip to content

Commit

Permalink
Attempt at creating sub-org; not working because of dependency on cry…
Browse files Browse the repository at this point in the history
…pto libs
  • Loading branch information
r-n-o committed Feb 5, 2024
1 parent a57e708 commit 35560d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
46 changes: 40 additions & 6 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { StatusBar } from 'expo-status-bar';
import { Button, StyleSheet, Text, View } from 'react-native';
import { PasskeyStamper, createPasskey, isSupported } from "@turnkey/react-native-passkey-stamper";
import {TURNKEY_ORGANIZATION_ID, TURNKEY_API_PUBLIC_KEY, TURNKEY_API_PRIVATE_KEY} from "@env"
import { ApiKeyStamper } from "@turnkey/api-key-stamper";
import { TurnkeyClient } from "@turnkey/http";

// Polyfill `btoa` for API stamper to work
import 'core-js/actual/btoa';

const RPID = "passkeyapp.tkhqlabs.xyz"

Expand Down Expand Up @@ -47,21 +52,50 @@ async function onPasskeyCreate() {
},
})
console.log("passkey registration succeeded: ", authenticatorParams);
// Now let's use the authenticator params to create a new sub-organization on the Turnkey side
// TODO: do it.
// console.log(TURNKEY_API_PRIVATE_KEY, TURNKEY_API_PUBLIC_KEY, TURNKEY_ORGANIZATION_ID);
const response = await createSubOrganization(authenticatorParams);
console.log("created sub-org", response)
} catch(e) {
console.error("error during passkey creation", e);
}
}

async function onPasskeySignature() {
try {
const result = await new PasskeyStamper({
const stamper = await new PasskeyStamper({
rpId: RPID,
}).stamp(`{"organizationId": "${TURNKEY_ORGANIZATION_ID}"}`)
console.log("passkey authentication succeeded: ", result);
});
const client = new TurnkeyClient({baseUrl: "https://api.turnkey.com"}, stamper);
const getWhoamiResult = client.getWhoami({
organizationId: TURNKEY_ORGANIZATION_ID
})
console.log("passkey authentication succeeded: ", getWhoamiResult);
} catch(e) {
console.error("error during passkey signature", e);
}
}

async function createSubOrganization(authenticatorParams) {
const stamper = new ApiKeyStamper({
apiPublicKey: TURNKEY_API_PUBLIC_KEY,
apiPrivateKey: TURNKEY_API_PRIVATE_KEY,
});
const client = new TurnkeyClient({baseUrl: "https://api.turnkey.com"}, stamper);

const data = await client.createSubOrganization({
type: "ACTIVITY_TYPE_CREATE_SUB_ORGANIZATION_V4",
timestampMs: String(Date.now()),
organizationId: TURNKEY_ORGANIZATION_ID,
parameters: {
subOrganizationName: `Sub-organization at ${String(Date.now())}`,
rootQuorumThreshold: 1,
rootUsers: [
{
userName: "Root end-user",
apiKeys: [],
authenticators: [authenticatorParams],
},
],
}
});
return data
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"web": "expo start --web"
},
"dependencies": {
"@turnkey/api-key-stamper": "^0.3.1",
"@turnkey/http": "^2.6.2",
"@turnkey/react-native-passkey-stamper": "https://pkg.csb.dev/tkhq/sdk/commit/dfa66a3e/@turnkey/react-native-passkey-stamper",
"@types/react": "~18.2.45",
"core-js": "^3.35.1",
"expo": "~50.0.5",
"expo-status-bar": "~1.11.1",
"react": "18.2.0",
Expand Down

0 comments on commit 35560d6

Please sign in to comment.