Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update token auth rules types #72

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export * from './dataV2';
export * from './delegateArgs';
export * from './escrowAuthority';
export * from './key';
export * from './leafInfo';
export * from './lockArgs';
export * from './metadataDelegateRole';
export * from './migrationType';
Expand All @@ -32,6 +31,7 @@ export * from './payloadType';
export * from './printArgs';
export * from './printSupply';
export * from './programmableConfig';
export * from './proofInfo';
export * from './reservation';
export * from './reservationV1';
export * from './revokeArgs';
Expand Down
28 changes: 0 additions & 28 deletions clients/js/src/generated/types/leafInfo.ts

This file was deleted.

12 changes: 6 additions & 6 deletions clients/js/src/generated/types/payloadType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ import {
u64,
} from '@metaplex-foundation/umi/serializers';
import {
LeafInfo,
LeafInfoArgs,
ProofInfo,
ProofInfoArgs,
SeedsVec,
SeedsVecArgs,
getLeafInfoSerializer,
getProofInfoSerializer,
getSeedsVecSerializer,
} from '.';

export type PayloadType =
| { __kind: 'Pubkey'; fields: [PublicKey] }
| { __kind: 'Seeds'; fields: [SeedsVec] }
| { __kind: 'MerkleProof'; fields: [LeafInfo] }
| { __kind: 'MerkleProof'; fields: [ProofInfo] }
| { __kind: 'Number'; fields: [bigint] };

export type PayloadTypeArgs =
| { __kind: 'Pubkey'; fields: [PublicKey] }
| { __kind: 'Seeds'; fields: [SeedsVecArgs] }
| { __kind: 'MerkleProof'; fields: [LeafInfoArgs] }
| { __kind: 'MerkleProof'; fields: [ProofInfoArgs] }
| { __kind: 'Number'; fields: [number | bigint] };

export function getPayloadTypeSerializer(): Serializer<
Expand All @@ -59,7 +59,7 @@ export function getPayloadTypeSerializer(): Serializer<
[
'MerkleProof',
struct<GetDataEnumKindContent<PayloadType, 'MerkleProof'>>([
['fields', tuple([getLeafInfoSerializer()])],
['fields', tuple([getProofInfoSerializer()])],
]),
],
[
Expand Down
24 changes: 24 additions & 0 deletions clients/js/src/generated/types/proofInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
Serializer,
array,
bytes,
struct,
} from '@metaplex-foundation/umi/serializers';

export type ProofInfo = { proof: Array<Uint8Array> };

export type ProofInfoArgs = ProofInfo;

export function getProofInfoSerializer(): Serializer<ProofInfoArgs, ProofInfo> {
return struct<ProofInfo>([['proof', array(bytes({ size: 32 }))]], {
description: 'ProofInfo',
}) as Serializer<ProofInfoArgs, ProofInfo>;
}
4 changes: 2 additions & 2 deletions clients/rust/src/generated/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub(crate) mod r#data_v2;
pub(crate) mod r#delegate_args;
pub(crate) mod r#escrow_authority;
pub(crate) mod r#key;
pub(crate) mod r#leaf_info;
pub(crate) mod r#lock_args;
pub(crate) mod r#metadata_delegate_role;
pub(crate) mod r#migration_type;
Expand All @@ -31,6 +30,7 @@ pub(crate) mod r#payload_type;
pub(crate) mod r#print_args;
pub(crate) mod r#print_supply;
pub(crate) mod r#programmable_config;
pub(crate) mod r#proof_info;
pub(crate) mod r#reservation;
pub(crate) mod r#reservation_v1;
pub(crate) mod r#revoke_args;
Expand Down Expand Up @@ -63,7 +63,6 @@ pub use self::r#data_v2::*;
pub use self::r#delegate_args::*;
pub use self::r#escrow_authority::*;
pub use self::r#key::*;
pub use self::r#leaf_info::*;
pub use self::r#lock_args::*;
pub use self::r#metadata_delegate_role::*;
pub use self::r#migration_type::*;
Expand All @@ -75,6 +74,7 @@ pub use self::r#payload_type::*;
pub use self::r#print_args::*;
pub use self::r#print_supply::*;
pub use self::r#programmable_config::*;
pub use self::r#proof_info::*;
pub use self::r#reservation::*;
pub use self::r#reservation_v1::*;
pub use self::r#revoke_args::*;
Expand Down
4 changes: 2 additions & 2 deletions clients/rust/src/generated/types/payload_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!

use crate::generated::types::LeafInfo;
use crate::generated::types::ProofInfo;
use crate::generated::types::SeedsVec;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
Expand All @@ -16,6 +16,6 @@ use solana_program::pubkey::Pubkey;
pub enum PayloadType {
Pubkey(Pubkey),
Seeds(SeedsVec),
MerkleProof(LeafInfo),
MerkleProof(ProofInfo),
Number(u64),
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use borsh::BorshSerialize;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LeafInfo {
pub leaf: [u8; 32],
pub struct ProofInfo {
pub proof: Vec<[u8; 32]>,
}
13 changes: 2 additions & 11 deletions idls/token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5508,19 +5508,10 @@
}
},
{
"name": "LeafInfo",
"name": "ProofInfo",
"type": {
"kind": "struct",
"fields": [
{
"name": "leaf",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "proof",
"type": {
Expand Down Expand Up @@ -6727,7 +6718,7 @@
"name": "MerkleProof",
"fields": [
{
"defined": "LeafInfo"
"defined": "ProofInfo"
}
]
},
Expand Down
25 changes: 18 additions & 7 deletions programs/token-metadata/program/src/state/token_auth_payload.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// These types exist to give Shank a way to create the Payload type as it
/// cannnot create it from the remote type from mpl-token-auth-rules.
/// Care will need to be taken to ensure they stay synced with any changes in
/// mpl-token-auth-rules.
//! These types exist to give Shank a way to create the Payload type as it
//! cannnot create it from the remote type from mpl-token-auth-rules.
//! Care will need to be taken to ensure they stay synced with any changes in
//! mpl-token-auth-rules.

use std::collections::HashMap;

use borsh::{BorshDeserialize, BorshSerialize};
Expand All @@ -12,31 +13,41 @@ use solana_program::pubkey::Pubkey;
#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
/// A seed path type used by the `DerivedKeyMatch` rule.
struct SeedsVec {
/// The vector of derivation seeds.
seeds: Vec<Vec<u8>>,
}

#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
struct LeafInfo {
leaf: [u8; 32],
/// A proof type used by the `PubkeyTreeMatch` rule.
struct ProofInfo {
/// The merkle proof.
proof: Vec<[u8; 32]>,
}

#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
/// Variants representing the different types represented in a payload.
enum PayloadType {
/// A plain `Pubkey`.
Pubkey(Pubkey),
/// PDA derivation seeds.
Seeds(SeedsVec),
MerkleProof(LeafInfo),
/// A merkle proof.
MerkleProof(ProofInfo),
/// A plain `u64` used for `Amount`.
Number(u64),
}

#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone, Default)]
/// A wrapper type for the payload hashmap.
struct Payload {
/// The payload hashmap.
map: HashMap<String, PayloadType>,
}
Loading