Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@staratlas/player-profile

Package Overview
Dependencies
Maintainers
4
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@staratlas/player-profile - npm Package Compare versions

Comparing version 0.1.21 to 0.2.0

6

dist/src/index.d.ts

@@ -1,4 +0,4 @@

import { ExtractArrayType, AnchorTypes, ListenProgram } from '@staratlas/data-source';
import { ExtractArrayType, AnchorTypes, ListenProgram, ProgramMethods } from '@staratlas/data-source';
import { PlayerProfileIDL } from '@staratlas/idls';
import { Program, Coder } from '@project-serum/anchor';
import { Coder } from '@project-serum/anchor';
import { PlayerProfile } from './playerProfile';

@@ -19,3 +19,3 @@ import { PlayerName } from './playerName';

export declare const playerProfileErrorMap: import("@staratlas/data-source").ErrorMap<PlayerProfileIDL>;
export declare type PlayerProfileIDLProgram = Program<PlayerProfileIDL>;
export declare type PlayerProfileIDLProgram = ProgramMethods<PlayerProfileIDL>;
export declare type PlayerProfileAccounts = {

@@ -22,0 +22,0 @@ profile: PlayerProfile;

@@ -9,3 +9,3 @@ import { KeyedAccountInfo, PublicKey } from '@solana/web3.js';

private _name;
static readonly ACCOUNT_NAME = "PlayerName";
static readonly ACCOUNT_NAME = "playerName";
static readonly MIN_DATA_SIZE: number;

@@ -12,0 +12,0 @@ constructor(_data: PlayerNameData, _key: PublicKey, _name: string);

@@ -16,3 +16,2 @@ "use strict";

const data_source_1 = require("@staratlas/data-source");
const anchor_1 = require("@project-serum/anchor");
function playerNameDataEquals(playerName1, playerName2) {

@@ -42,34 +41,6 @@ return (playerName1.version === playerName2.version &&

static decodeData(account, program) {
if (!account.accountInfo.owner.equals(program.programId)) {
return {
type: 'error',
key: account.accountId,
error: 'not owned by program',
};
}
else if (!account.accountInfo.data
.subarray(0, 8)
.equals(anchor_1.BorshAccountsCoder.accountDiscriminator('PlayerName'))) {
return {
type: 'error',
key: account.accountId,
error: 'discriminator mismatch',
};
}
else {
try {
const data = program.coder.accounts.decode('playerName', account.accountInfo.data);
return {
type: 'ok',
key: account.accountId,
data: new PlayerName_1(data, account.accountId, new TextDecoder().decode(account.accountInfo.data.subarray(PlayerName_1.MIN_DATA_SIZE))),
};
}
catch (e) {
return { type: 'error', key: account.accountId, error: 'data invalid' };
}
}
return (0, data_source_1.decodeAccountWithRemaining)(account, program, PlayerName_1, (remainingData) => new TextDecoder().decode(remainingData));
}
};
PlayerName.ACCOUNT_NAME = 'PlayerName';
PlayerName.ACCOUNT_NAME = 'playerName';
PlayerName.MIN_DATA_SIZE = 8 + // discriminator

@@ -76,0 +47,0 @@ 1 + // version

@@ -102,3 +102,3 @@ /// <reference types="bn.js" />

private _profileKeys;
static readonly ACCOUNT_NAME = "Profile";
static readonly ACCOUNT_NAME = "profile";
static readonly MIN_DATA_SIZE: number;

@@ -110,3 +110,3 @@ constructor(_data: PlayerProfileData, _key: PublicKey, _profileKeys: ProfileKey[]);

static findProfileSigner(program: PlayerProfileIDLProgram, profile: PublicKey): [PublicKey, number];
static createProfile(program: PlayerProfileIDLProgram, funder: AsyncSigner, profile: AsyncSigner, keys: {
static createProfile(program: PlayerProfileIDLProgram, profile: AsyncSigner, keys: {
key: PublicKey | AsyncSigner;

@@ -116,15 +116,15 @@ expireTime: BN | null;

permissionKey: PublicKey;
}[], faction: Faction, keyThreshold: number): Promise<{
}[], faction: Faction, keyThreshold: number): {
profileSigner: [PublicKey, number];
instructions: InstructionReturn[];
}>;
static setName(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, funder: AsyncSigner, name: string): Promise<{
instructions: InstructionReturn[];
instructions: InstructionReturn;
};
static setName(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, name: string): {
instructions: InstructionReturn;
name: [PublicKey, number];
}>;
static addKeys<T extends PermissionTypeStatic<U>, U extends PermissionType<U>>(program: PlayerProfileIDLProgram, key: AsyncSigner, funder: AsyncSigner, profile: PlayerProfile, permissionsClass: T, permissionKey: PublicKey, keys: {
};
static addKeys<T extends PermissionTypeStatic<U>, U extends PermissionType<U>>(program: PlayerProfileIDLProgram, key: AsyncSigner, profile: PlayerProfile, permissionsClass: T, permissionKey: PublicKey, keys: {
key: PublicKey;
expireTime: BN | null;
permissions: U;
}[]): Promise<InstructionReturn[]>;
}[]): InstructionReturn;
/**

@@ -137,5 +137,5 @@ * Removes keys from a profile.

*/
static removeKeys(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, fundsTo: PublicKey, keysRange: [number, number]): Promise<InstructionReturn>;
static changeFaction(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, faction: Faction): Promise<InstructionReturn>;
static adjustAuth(program: PlayerProfileIDLProgram, keyInputs: ProfileKeyInput<ProfilePermissions, AsyncSigner>[], funder: AsyncSigner, addKeys: (<R>(cont: <U extends PermissionType<U>>(key: {
static removeKeys(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, fundsTo: PublicKey | 'funder', keysRange: [number, number]): InstructionReturn;
static changeFaction(program: PlayerProfileIDLProgram, keyInput: ProfileKeyInput<ProfilePermissions, AsyncSigner>, faction: Faction): InstructionReturn;
static adjustAuth(program: PlayerProfileIDLProgram, keyInputs: ProfileKeyInput<ProfilePermissions, AsyncSigner>[], addKeys: (<R>(cont: <U extends PermissionType<U>>(key: {
key: PublicKey;

@@ -145,5 +145,5 @@ expireTime: BN | null;

permissions: PermissionType<U>;
}) => R) => R)[], removeRange: [number, number], newKeyThreshold: number): Promise<InstructionReturn>;
}) => R) => R)[], removeRange: [number, number], newKeyThreshold: number): InstructionReturn;
static decodeData(account: KeyedAccountInfo, program: PlayerProfileIDLProgram): DecodedAccountData<PlayerProfile>;
}
//# sourceMappingURL=playerProfile.d.ts.map

@@ -185,65 +185,63 @@ "use strict";

}
static createProfile(program, funder, profile, keys, faction, keyThreshold) {
return __awaiter(this, void 0, void 0, function* () {
const profileSigner = PlayerProfile_1.findProfileSigner(program, profile.publicKey());
return {
profileSigner,
instructions: [
{
instruction: yield program.methods
.createProfile(keys.map((key) => {
if (key.expireTime !== null && key.expireTime.lt(new anchor_1.BN(0))) {
throw new Error('expire time will result in negation. Use explicitly null instead');
}
static createProfile(program, profile, keys, faction, keyThreshold) {
const profileSigner = PlayerProfile_1.findProfileSigner(program, profile.publicKey());
return {
profileSigner,
instructions: (funder) => __awaiter(this, void 0, void 0, function* () {
return ({
instruction: yield program.methods
.createProfile(keys.map((key) => {
if (key.expireTime !== null && key.expireTime.lt(new anchor_1.BN(0))) {
throw new Error('expire time will result in negation. Use explicitly null instead');
}
return {
permissionKey: key.permissionKey,
expireTime: key.expireTime === null ? new anchor_1.BN(-1) : key.expireTime,
permissions: key.permissions.getPermissions(),
};
}), profileSigner[1], (0, data_source_1.getAnchorEnum)(Faction, faction), keyThreshold)
.accountsStrict({
funder: funder.publicKey(),
profile: profile.publicKey(),
profileSigner: profileSigner[0],
systemProgram: web3_js_1.SystemProgram.programId,
})
.remainingAccounts(keys.map((key) => {
if (key.key instanceof web3_js_1.PublicKey) {
return {
permissionKey: key.permissionKey,
expireTime: key.expireTime === null ? new anchor_1.BN(-1) : key.expireTime,
permissions: key.permissions.getPermissions(),
pubkey: key.key,
isSigner: false,
isWritable: false,
};
}), profileSigner[1], (0, data_source_1.getAnchorEnum)(Faction, faction), keyThreshold)
.accountsStrict({
funder: funder.publicKey(),
profile: profile.publicKey(),
profileSigner: profileSigner[0],
systemProgram: web3_js_1.SystemProgram.programId,
})
.remainingAccounts(keys.map((key) => {
if (key.key instanceof web3_js_1.PublicKey) {
return {
pubkey: key.key,
isSigner: false,
isWritable: false,
};
}
else {
return {
pubkey: key.key.publicKey(),
isSigner: true,
isWritable: false,
};
}
}))
.instruction(),
signers: [
funder,
profile,
...keys
.map((key) => key.key)
.filter((key) => !(key instanceof web3_js_1.PublicKey)),
],
},
],
};
});
}
else {
return {
pubkey: key.key.publicKey(),
isSigner: true,
isWritable: false,
};
}
}))
.instruction(),
signers: [
funder,
profile,
...keys
.map((key) => key.key)
.filter((key) => !(key instanceof web3_js_1.PublicKey)),
],
});
}),
};
}
static setName(program, keyInput, funder, name) {
return __awaiter(this, void 0, void 0, function* () {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.changeName()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
const nameAccount = playerName_1.PlayerName.findAddress(program, profileKey);
return {
instructions: [
static setName(program, keyInput, name) {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.changeName()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
const nameAccount = playerName_1.PlayerName.findAddress(program, profileKey);
return {
instructions: (funder) => __awaiter(this, void 0, void 0, function* () {
return [
{

@@ -262,37 +260,37 @@ instruction: yield program.methods

},
],
name: nameAccount,
};
});
];
}),
name: nameAccount,
};
}
static addKeys(program, key, funder, profile, permissionsClass, permissionKey, keys) {
return __awaiter(this, void 0, void 0, function* () {
const neededPermissions = keys.reduce((acc, key) => acc.or(key.permissions), permissionsClass.empty());
const { addKeyIndex, permissionsKeyIndex } = profile.profileKeys.reduce((indexes, profileKey, index) => {
if (indexes.addKeyIndex !== null &&
indexes.permissionsKeyIndex !== null) {
return indexes;
}
if (profileKey.key.equals(key.publicKey())) {
if (profileKey.permissionKey.equals(program.programId)) {
const profilePermissions = ProfilePermissions.fromPermissions(profileKey.permissions);
if (profilePermissions.auth) {
return { addKeyIndex: index, permissionsKeyIndex: index };
}
else if (profilePermissions.addKeys) {
indexes.addKeyIndex = index;
}
static addKeys(program, key, profile, permissionsClass, permissionKey, keys) {
const neededPermissions = keys.reduce((acc, key) => acc.or(key.permissions), permissionsClass.empty());
const { addKeyIndex, permissionsKeyIndex } = profile.profileKeys.reduce((indexes, profileKey, index) => {
if (indexes.addKeyIndex !== null &&
indexes.permissionsKeyIndex !== null) {
return indexes;
}
if (profileKey.key.equals(key.publicKey())) {
if (profileKey.permissionKey.equals(program.programId)) {
const profilePermissions = ProfilePermissions.fromPermissions(profileKey.permissions);
if (profilePermissions.auth) {
return { addKeyIndex: index, permissionsKeyIndex: index };
}
if (permissionKey.equals(profileKey.permissionKey) &&
neededPermissions
.and(permissionsClass.fromPermissions(profileKey.permissions))
.eq(neededPermissions)) {
indexes.permissionsKeyIndex = index;
else if (profilePermissions.addKeys) {
indexes.addKeyIndex = index;
}
}
return indexes;
}, { addKeyIndex: null, permissionsKeyIndex: null });
if (addKeyIndex === null || permissionsKeyIndex === null) {
throw new Error('key does not have permissions to add given keys');
if (permissionKey.equals(profileKey.permissionKey) &&
neededPermissions
.and(permissionsClass.fromPermissions(profileKey.permissions))
.eq(neededPermissions)) {
indexes.permissionsKeyIndex = index;
}
}
return indexes;
}, { addKeyIndex: null, permissionsKeyIndex: null });
if (addKeyIndex === null || permissionsKeyIndex === null) {
throw new Error('key does not have permissions to add given keys');
}
return (funder) => __awaiter(this, void 0, void 0, function* () {
return [

@@ -331,13 +329,13 @@ {

static removeKeys(program, keyInput, fundsTo, keysRange) {
return __awaiter(this, void 0, void 0, function* () {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.removeKeys()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
return {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.removeKeys()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
return (funder) => __awaiter(this, void 0, void 0, function* () {
return ({
instruction: yield program.methods
.removeKeys(keyIndex, keysRange)
.accountsStrict({
funder: fundsTo,
funder: fundsTo === 'funder' ? funder.publicKey() : fundsTo,
key: key.publicKey(),

@@ -349,13 +347,13 @@ profile: profileKey,

signers: [key],
};
});
});
}
static changeFaction(program, keyInput, faction) {
return __awaiter(this, void 0, void 0, function* () {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.auth()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
return {
const foundKey = findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.auth()), ProfilePermissions);
if ('error' in foundKey) {
throw foundKey.error;
}
const { profileKey, key, keyIndex } = foundKey;
return () => __awaiter(this, void 0, void 0, function* () {
return ({
instruction: yield program.methods

@@ -370,44 +368,44 @@ .chooseFaction(keyIndex, faction)

signers: [key],
};
});
});
}
static adjustAuth(program, keyInputs, funder, addKeys, removeRange, newKeyThreshold) {
return __awaiter(this, void 0, void 0, function* () {
if (keyInputs.length === 0) {
throw new Error('no keys provided');
static adjustAuth(program, keyInputs, addKeys, removeRange, newKeyThreshold) {
if (keyInputs.length === 0) {
throw new Error('no keys provided');
}
const foundKeys = keyInputs.map((keyInput) => findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.auth()), ProfilePermissions));
const errors = foundKeys.filter((key) => 'error' in key);
if (errors.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throw errors[0].error;
}
const keys = foundKeys;
let profileKey = null;
for (const key of keys) {
if (profileKey === null) {
profileKey = key.profileKey;
}
const foundKeys = keyInputs.map((keyInput) => findKeyInProfile(profileKeyInputToFindKeyInput(keyInput, [program.programId], ProfilePermissions.auth()), ProfilePermissions));
const errors = foundKeys.filter((key) => 'error' in key);
if (errors.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throw errors[0].error;
else if (!profileKey.equals(key.profileKey)) {
throw new Error('keys are not from the same profile');
}
const keys = foundKeys;
let profileKey = null;
for (const key of keys) {
if (profileKey === null) {
profileKey = key.profileKey;
}
else if (!profileKey.equals(key.profileKey)) {
throw new Error('keys are not from the same profile');
}
}
if (profileKey === null) {
// This error should be caught earlier
throw new Error('no keys provided after profile key');
}
const keyInputsCalc = addKeys.map((addKeyCont) => addKeyCont(({ key, expireTime, permissionKey, permissions }) => {
if (expireTime !== null && expireTime.lt(new anchor_1.BN(0))) {
throw new Error('expire time will result in negation. Use explicitly null instead');
}
if (profileKey === null) {
// This error should be caught earlier
throw new Error('no keys provided after profile key');
}
const keyInputsCalc = addKeys.map((addKeyCont) => addKeyCont(({ key, expireTime, permissionKey, permissions }) => {
if (expireTime !== null && expireTime.lt(new anchor_1.BN(0))) {
throw new Error('expire time will result in negation. Use explicitly null instead');
}
return [
{
permissionKey,
expireTime: expireTime === null ? new anchor_1.BN(-1) : expireTime,
permissions: permissions.getPermissions(),
},
key,
];
}));
return {
return [
{
permissionKey,
expireTime: expireTime === null ? new anchor_1.BN(-1) : expireTime,
permissions: permissions.getPermissions(),
},
key,
];
}));
return (funder) => __awaiter(this, void 0, void 0, function* () {
return ({
instruction: yield program.methods

@@ -417,2 +415,4 @@ .adjustAuth(keys.map((key) => key.keyIndex), keyInputsCalc.map(([keyInput]) => keyInput), removeRange, newKeyThreshold)

funder: funder.publicKey(),
// Safe because profile key is not used since check
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
profile: profileKey,

@@ -436,43 +436,17 @@ systemProgram: web3_js_1.SystemProgram.programId,

signers: [funder, ...keys.map((key) => key.key)],
};
});
});
}
static decodeData(account, program) {
if (!account.accountInfo.owner.equals(program.programId)) {
return {
type: 'error',
key: account.accountId,
error: 'not owned by program',
};
}
else if (!account.accountInfo.data
.subarray(0, 8)
.equals(anchor_1.BorshAccountsCoder.accountDiscriminator('Profile'))) {
return {
type: 'error',
key: account.accountId,
error: 'discriminator mismatch',
};
}
else {
try {
const data = program.coder.accounts.decode('profile', account.accountInfo.data);
return {
type: 'ok',
key: account.accountId,
data: new PlayerProfile_1(data, account.accountId, Array(data.numKeys)
.fill(0)
.map((_, index) => program.coder.types.decode('ProfileKey', account.accountInfo.data
.subarray(PlayerProfile_1.MIN_DATA_SIZE +
exports.PROFILE_KEY_MIN_DATA_SIZE * index)
.subarray(0, exports.PROFILE_KEY_MIN_DATA_SIZE)))),
};
}
catch (e) {
return { type: 'error', key: account.accountId, error: 'data invalid' };
}
}
return (0, data_source_1.decodeAccountWithRemaining)(account, program, PlayerProfile_1, (remainingData, data) => {
console.log('length: ', remainingData.length);
return Array(data.numKeys)
.fill(0)
.map((_, index) => program.coder.types.decode('ProfileKey', remainingData
.subarray(exports.PROFILE_KEY_MIN_DATA_SIZE * index)
.subarray(0, exports.PROFILE_KEY_MIN_DATA_SIZE)));
});
}
};
PlayerProfile.ACCOUNT_NAME = 'Profile';
PlayerProfile.ACCOUNT_NAME = 'profile';
PlayerProfile.MIN_DATA_SIZE = 8 + // discriminator

@@ -479,0 +453,0 @@ 1 + // version

{
"name": "@staratlas/player-profile",
"version": "0.1.21",
"version": "0.2.0",
"description": "> TODO: description",

@@ -22,6 +22,6 @@ "author": "Brett Etter <brett.etter@staratlas.com>",

"@solana/web3.js": "^1.66.2",
"@staratlas/data-source": "^0.1.13",
"@staratlas/idls": "^0.1.11"
"@staratlas/data-source": "^0.2.0",
"@staratlas/idls": "^0.2.0"
},
"gitHead": "0cd1e8fac2133c24580d0a0bd1f8777c19fb167f"
"gitHead": "7835a1674a83fb9fba28ed3f82f11820a284d3df"
}

@@ -8,2 +8,3 @@ {

"checkJs": true,
"strict": true,
"declaration": true,

@@ -10,0 +11,0 @@ "declarationMap": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc