@exodus/solana-lib 1.2.27 → 1.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/encode.js +43 -0
- package/src/helpers/metadata-schema.js +93 -0
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.29",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"@exodus/buffer-layout": "^1.2.0-exodus1",
|
|
20
20
|
"@exodus/models": "^8.4.0",
|
|
21
21
|
"bn.js": "^4.11.0",
|
|
22
|
+
"borsh": "^0.7.0",
|
|
22
23
|
"bs58": "^4.0.1",
|
|
23
24
|
"create-hash": "^1.1.3",
|
|
24
25
|
"lodash": "^4.17.11",
|
|
25
26
|
"tweetnacl": "^1.0.3"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "69134d5324df0b3977a84b39e1098876a5ebffe7"
|
|
28
29
|
}
|
package/src/encode.js
CHANGED
|
@@ -5,6 +5,23 @@ import { SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID, TOKEN_PROGRAM_ID, SEED } from
|
|
|
5
5
|
import { getPublicKey, getKeyPairFromPrivateKey } from './keypair'
|
|
6
6
|
import bs58 from 'bs58'
|
|
7
7
|
import BN from 'bn.js'
|
|
8
|
+
import { Metadata, METADATA_SCHEMA } from './helpers/metadata-schema'
|
|
9
|
+
import { deserializeUnchecked } from 'borsh'
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
const { BinaryReader, BinaryWriter, deserializeUnchecked } = require('borsh')
|
|
13
|
+
|
|
14
|
+
BinaryReader.prototype.readPubkeyAsString = function () {
|
|
15
|
+
const reader = this
|
|
16
|
+
const array = reader.readFixedArray(32)
|
|
17
|
+
return bs58.encode(array)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
BinaryWriter.prototype.writePubkeyAsString = function (value) {
|
|
21
|
+
const writer = this
|
|
22
|
+
writer.writeFixedArray(bs58.decode(value))
|
|
23
|
+
}
|
|
24
|
+
*/
|
|
8
25
|
|
|
9
26
|
export function getAddressFromPublicKey(publicKey: string | Buffer): string {
|
|
10
27
|
return bs58.encode(Buffer.from(publicKey, 'hex'))
|
|
@@ -67,3 +84,29 @@ export function createStakeAddress(walletAddress: string, seed = SEED): string {
|
|
|
67
84
|
|
|
68
85
|
return newAccountPubkey.toBase58()
|
|
69
86
|
}
|
|
87
|
+
|
|
88
|
+
// get Metaplex Metadata account
|
|
89
|
+
export function getMetadataAccount(tokenMintAddress: string): string {
|
|
90
|
+
const METADATA_PROGRAM_ID = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
|
|
91
|
+
const METADATA_PREFIX = 'metadata'
|
|
92
|
+
|
|
93
|
+
return PublicKey.findProgramAddress(
|
|
94
|
+
[
|
|
95
|
+
Buffer.from(METADATA_PREFIX),
|
|
96
|
+
new PublicKey(METADATA_PROGRAM_ID).toBuffer(),
|
|
97
|
+
new PublicKey(tokenMintAddress).toBuffer(),
|
|
98
|
+
],
|
|
99
|
+
new PublicKey(METADATA_PROGRAM_ID)
|
|
100
|
+
)[0].toBase58() // returns encoded PublicKey
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function deserializeMetaplexMetadata(rawData: Buffer) {
|
|
104
|
+
const metadata = deserializeUnchecked(METADATA_SCHEMA, Metadata, rawData)
|
|
105
|
+
|
|
106
|
+
// eslint-disable-next-line no-control-regex
|
|
107
|
+
const METADATA_REPLACE = new RegExp('\u0000', 'g')
|
|
108
|
+
metadata.data.name = metadata.data.name.replace(METADATA_REPLACE, '')
|
|
109
|
+
metadata.data.uri = metadata.data.uri.replace(METADATA_REPLACE, '')
|
|
110
|
+
metadata.data.symbol = metadata.data.symbol.replace(METADATA_REPLACE, '')
|
|
111
|
+
return metadata.data
|
|
112
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// metadata structs: https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/common/src/actions/metadata.ts
|
|
2
|
+
|
|
3
|
+
import bs58 from 'bs58'
|
|
4
|
+
import { BinaryReader, BinaryWriter } from 'borsh'
|
|
5
|
+
|
|
6
|
+
BinaryReader.prototype.readPubkeyAsString = function () {
|
|
7
|
+
const reader = this
|
|
8
|
+
const array = reader.readFixedArray(32)
|
|
9
|
+
return bs58.encode(array)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
BinaryWriter.prototype.writePubkeyAsString = function (value) {
|
|
13
|
+
const writer = this
|
|
14
|
+
writer.writeFixedArray(bs58.decode(value))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class Data {
|
|
18
|
+
constructor(args) {
|
|
19
|
+
this.name = args.name;
|
|
20
|
+
this.symbol = args.symbol;
|
|
21
|
+
this.uri = args.uri;
|
|
22
|
+
this.sellerFeeBasisPoints = args.sellerFeeBasisPoints;
|
|
23
|
+
this.creators = args.creators;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Creator {
|
|
28
|
+
constructor(args) {
|
|
29
|
+
this.address = args.address;
|
|
30
|
+
this.verified = args.verified;
|
|
31
|
+
this.share = args.share;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class Metadata {
|
|
36
|
+
constructor(args) {
|
|
37
|
+
this.key = '' // MetadataKey.MetadataV1;
|
|
38
|
+
this.updateAuthority = args.updateAuthority;
|
|
39
|
+
this.mint = args.mint;
|
|
40
|
+
this.data = args.data;
|
|
41
|
+
this.primarySaleHappened = args.primarySaleHappened;
|
|
42
|
+
this.isMutable = args.isMutable;
|
|
43
|
+
this.editionNonce = args.editionNonce || null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const METADATA_SCHEMA = new Map([
|
|
48
|
+
[
|
|
49
|
+
Data,
|
|
50
|
+
{
|
|
51
|
+
kind: 'struct',
|
|
52
|
+
fields: [
|
|
53
|
+
['name', 'string'],
|
|
54
|
+
['symbol', 'string'],
|
|
55
|
+
['uri', 'string'],
|
|
56
|
+
['sellerFeeBasisPoints', 'u16'],
|
|
57
|
+
['creators', { kind: 'option', type: [Creator] }],
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
Creator,
|
|
63
|
+
{
|
|
64
|
+
kind: 'struct',
|
|
65
|
+
fields: [
|
|
66
|
+
['address', 'pubkeyAsString'],
|
|
67
|
+
['verified', 'u8'],
|
|
68
|
+
['share', 'u8'],
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
Metadata,
|
|
74
|
+
{
|
|
75
|
+
kind: 'struct',
|
|
76
|
+
fields: [
|
|
77
|
+
['key', 'u8'],
|
|
78
|
+
['updateAuthority', 'pubkeyAsString'],
|
|
79
|
+
['mint', 'pubkeyAsString'],
|
|
80
|
+
['data', Data],
|
|
81
|
+
['primarySaleHappened', 'u8'], // bool
|
|
82
|
+
['isMutable', 'u8'], // bool
|
|
83
|
+
['editionNonce', { kind: 'option', type: 'u8' }],
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
METADATA_SCHEMA,
|
|
92
|
+
Metadata
|
|
93
|
+
}
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,6 @@ export * from './constants'
|
|
|
4
4
|
export * from './encode'
|
|
5
5
|
export * from './keypair'
|
|
6
6
|
export * from './tx'
|
|
7
|
-
export { StakeInstruction, PublicKey } from './vendor'
|
|
7
|
+
export { StakeInstruction, PublicKey, Transaction as SolanaWeb3Transaction, Message as SolanaWeb3Message } from './vendor'
|
|
8
8
|
export { default as tokens } from './tokens'
|
|
9
9
|
export { default as Transaction } from './transaction'
|