-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
690 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// NOTE: All of these keys should be considered compromised!!!! | ||
// NOTE: Only used for demo purposes | ||
|
||
const keys: { [key: string]: { [key: string]: string } } = { | ||
nonRootUser: { | ||
publicKey: | ||
"03178b1cb727bd1ab23c3c5725d633f9ad3c7c0502efda2371e4e4bd88aea8a94d", | ||
privateKey: | ||
"26e53957146d5d5b5612f09518b8bb40deddcf28d378270101227cb0a231969e", | ||
}, | ||
}; | ||
|
||
export default keys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
type TurnkeyServerClient, | ||
TurnkeyActivityError, | ||
} from "@turnkey/sdk-server"; | ||
|
||
import { refineNonNull } from "../utils"; | ||
|
||
export default async function createPolicy( | ||
turnkeyClient: TurnkeyServerClient, | ||
policyName: string, | ||
effect: "EFFECT_ALLOW" | "EFFECT_DENY", | ||
consensus: string, | ||
condition: string, | ||
notes: "" | ||
): Promise<string> { | ||
try { | ||
const { policyId } = await turnkeyClient.createPolicy({ | ||
policyName, | ||
condition, | ||
consensus, | ||
effect, | ||
notes, | ||
}); | ||
|
||
const newPolicyId = refineNonNull(policyId); | ||
|
||
// Success! | ||
console.log( | ||
[ | ||
`New policy created!`, | ||
`- Name: ${policyName}`, | ||
`- Policy ID: ${newPolicyId}`, | ||
`- Effect: ${effect}`, | ||
`- Consensus: ${consensus}`, | ||
`- Condition: ${condition}`, | ||
``, | ||
].join("\n") | ||
); | ||
|
||
return newPolicyId; | ||
} catch (error) { | ||
// If needed, you can read from `TurnkeyActivityError` to find out why the activity didn't succeed | ||
if (error instanceof TurnkeyActivityError) { | ||
throw error; | ||
} | ||
|
||
throw new TurnkeyActivityError({ | ||
message: "Failed to create a new policy", | ||
cause: error as Error, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
type TurnkeyServerClient, | ||
TurnkeyActivityError, | ||
} from "@turnkey/sdk-server"; | ||
|
||
import { refineNonNull } from "../utils"; | ||
|
||
export default async function createUser( | ||
turnkeyClient: TurnkeyServerClient, | ||
userName: string, | ||
apiKeyName: string, | ||
publicKey: string | ||
): Promise<string> { | ||
let userTags: string[] = new Array(); | ||
try { | ||
const { userIds } = await turnkeyClient.createApiOnlyUsers({ | ||
apiOnlyUsers: [ | ||
{ | ||
userName, | ||
userTags, | ||
apiKeys: [ | ||
{ | ||
apiKeyName, | ||
publicKey, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
const userId = refineNonNull(userIds?.[0]); | ||
|
||
// Success! | ||
console.log( | ||
[ | ||
`New user created!`, | ||
`- Name: ${userName}`, | ||
`- User ID: ${userId}`, | ||
``, | ||
].join("\n") | ||
); | ||
|
||
return userId; | ||
} catch (error) { | ||
// If needed, you can read from `TurnkeyActivityError` to find out why the activity didn't succeed | ||
if (error instanceof TurnkeyActivityError) { | ||
throw error; | ||
} | ||
|
||
throw new TurnkeyActivityError({ | ||
message: "Failed to create a new user", | ||
cause: error as Error, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as createUser } from "./createUser"; | ||
export { default as createPolicy } from "./createPolicy"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.