@solana-mobile/dapp-store-publishing-tools 0.15.0 → 0.16.1
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/lib/CoreUtils.js +0 -3
- package/lib/index.js +1 -0
- package/lib/portal/attestation.js +189 -0
- package/lib/portal/compat.js +3 -0
- package/lib/portal/index.js +5 -0
- package/lib/portal/signer.js +432 -0
- package/lib/portal/types.js +1 -0
- package/lib/portal/workflow/contracts.js +1 -0
- package/lib/portal/workflow/execution.js +493 -0
- package/lib/portal/workflow/ingestion.js +265 -0
- package/lib/portal/workflow/lifecycle.js +616 -0
- package/lib/portal/workflow/logging.js +8 -0
- package/lib/portal/workflow/source/files.js +304 -0
- package/lib/portal/workflow/source/preparation.js +318 -0
- package/lib/portal/workflow/state/bundle.js +260 -0
- package/lib/portal/workflow/state/checkpoints.js +53 -0
- package/lib/portal/workflow/state/session.js +100 -0
- package/lib/portal/workflow.js +1 -0
- package/lib/publish/PublishCoreAttestation.js +18 -17
- package/lib/publish/PublishCoreRemove.js +7 -89
- package/lib/publish/PublishCoreSubmit.js +7 -117
- package/lib/publish/PublishCoreSupport.js +7 -86
- package/lib/publish/PublishCoreUpdate.js +7 -117
- package/lib/publish/index.js +1 -0
- package/package.json +2 -4
- package/src/CoreUtils.ts +0 -6
- package/src/index.ts +1 -0
- package/src/portal/attestation.ts +76 -0
- package/src/portal/compat.ts +5 -0
- package/src/portal/index.ts +5 -0
- package/src/portal/signer.ts +327 -0
- package/src/portal/types.ts +447 -0
- package/src/portal/workflow/contracts.ts +108 -0
- package/src/portal/workflow/execution.ts +412 -0
- package/src/portal/workflow/ingestion.ts +187 -0
- package/src/portal/workflow/lifecycle.ts +435 -0
- package/src/portal/workflow/logging.ts +17 -0
- package/src/portal/workflow/source/files.ts +49 -0
- package/src/portal/workflow/source/preparation.ts +189 -0
- package/src/portal/workflow/state/bundle.ts +193 -0
- package/src/portal/workflow/state/checkpoints.ts +70 -0
- package/src/portal/workflow/state/session.ts +87 -0
- package/src/portal/workflow.ts +9 -0
- package/src/publish/PublishCoreAttestation.ts +21 -26
- package/src/publish/PublishCoreRemove.ts +13 -109
- package/src/publish/PublishCoreSubmit.ts +18 -150
- package/src/publish/PublishCoreSupport.ts +13 -102
- package/src/publish/PublishCoreUpdate.ts +17 -155
- package/src/publish/index.ts +2 -1
- package/lib/publish/dapp_publisher_portal.js +0 -206
- package/src/publish/dapp_publisher_portal.ts +0 -81
package/lib/CoreUtils.js
CHANGED
|
@@ -181,9 +181,6 @@ export var Constants = function Constants() {
|
|
|
181
181
|
_class_call_check(this, Constants);
|
|
182
182
|
};
|
|
183
183
|
_define_property(Constants, "PUBLISHING_SCHEMA_VER", "0.4.0");
|
|
184
|
-
export var truncateAddress = function(address) {
|
|
185
|
-
return "".concat(address.slice(0, 4), "...").concat(address.slice(address.length - 4, address.length));
|
|
186
|
-
};
|
|
187
184
|
export var mintNft = function(metaplex, json, createNftInput, priorityFeeLamports) {
|
|
188
185
|
return _async_to_generator(function() {
|
|
189
186
|
var uri, computeBudget, txBuilder, microLamportsPerCU;
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
+
return this;
|
|
42
|
+
}), g;
|
|
43
|
+
function verb(n) {
|
|
44
|
+
return function(v) {
|
|
45
|
+
return step([
|
|
46
|
+
n,
|
|
47
|
+
v
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function step(op) {
|
|
52
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
+
if (y = 0, t) op = [
|
|
56
|
+
op[0] & 2,
|
|
57
|
+
t.value
|
|
58
|
+
];
|
|
59
|
+
switch(op[0]){
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [
|
|
107
|
+
6,
|
|
108
|
+
e
|
|
109
|
+
];
|
|
110
|
+
y = 0;
|
|
111
|
+
} finally{
|
|
112
|
+
f = t = 0;
|
|
113
|
+
}
|
|
114
|
+
if (op[0] & 5) throw op[1];
|
|
115
|
+
return {
|
|
116
|
+
value: op[0] ? op[1] : void 0,
|
|
117
|
+
done: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export var createRequestUniqueId = function() {
|
|
122
|
+
var requestUniqueIdLength = 32;
|
|
123
|
+
var charset = '0123456789';
|
|
124
|
+
return Array(requestUniqueIdLength).fill(undefined).map(function() {
|
|
125
|
+
return charset.charAt(Math.floor(Math.random() * charset.length));
|
|
126
|
+
}).join('');
|
|
127
|
+
};
|
|
128
|
+
export var createAttestationPayload = function(blockData, signer) {
|
|
129
|
+
return _async_to_generator(function() {
|
|
130
|
+
var requestUniqueId, attestation, attestationBuffer, signedMessageFromSigner, signedMessageBuffer, signature;
|
|
131
|
+
return _ts_generator(this, function(_state) {
|
|
132
|
+
switch(_state.label){
|
|
133
|
+
case 0:
|
|
134
|
+
requestUniqueId = createRequestUniqueId();
|
|
135
|
+
attestation = {
|
|
136
|
+
slot_number: blockData.slot,
|
|
137
|
+
blockhash: blockData.blockhash,
|
|
138
|
+
request_unique_id: requestUniqueId
|
|
139
|
+
};
|
|
140
|
+
attestationBuffer = new TextEncoder().encode(JSON.stringify(attestation));
|
|
141
|
+
return [
|
|
142
|
+
4,
|
|
143
|
+
signer.signMessage(attestationBuffer)
|
|
144
|
+
];
|
|
145
|
+
case 1:
|
|
146
|
+
signedMessageFromSigner = _state.sent();
|
|
147
|
+
signedMessageBuffer = signedMessageFromSigner.length === 64 ? function() {
|
|
148
|
+
var payload = new Uint8Array(64 + attestationBuffer.length);
|
|
149
|
+
payload.set(signedMessageFromSigner, 0);
|
|
150
|
+
payload.set(attestationBuffer, 64);
|
|
151
|
+
return payload;
|
|
152
|
+
}() : signedMessageFromSigner;
|
|
153
|
+
signature = signedMessageBuffer.slice(0, 64);
|
|
154
|
+
if (signature.length !== 64) {
|
|
155
|
+
throw new Error("Invalid signature length: expected 64, got ".concat(signature.length));
|
|
156
|
+
}
|
|
157
|
+
return [
|
|
158
|
+
2,
|
|
159
|
+
{
|
|
160
|
+
payload: Buffer.from(signedMessageBuffer).toString('base64'),
|
|
161
|
+
attestationPayload: Buffer.from(signedMessageBuffer).toString('base64'),
|
|
162
|
+
requestUniqueId: requestUniqueId,
|
|
163
|
+
attestation: attestation
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
})();
|
|
169
|
+
};
|
|
170
|
+
export var createAttestationPayloadFromClient = function(client, signer) {
|
|
171
|
+
return _async_to_generator(function() {
|
|
172
|
+
var blockData;
|
|
173
|
+
return _ts_generator(this, function(_state) {
|
|
174
|
+
switch(_state.label){
|
|
175
|
+
case 0:
|
|
176
|
+
return [
|
|
177
|
+
4,
|
|
178
|
+
client.getBlockData()
|
|
179
|
+
];
|
|
180
|
+
case 1:
|
|
181
|
+
blockData = _state.sent();
|
|
182
|
+
return [
|
|
183
|
+
2,
|
|
184
|
+
createAttestationPayload(blockData, signer)
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
})();
|
|
189
|
+
};
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
|
+
try {
|
|
14
|
+
var info = gen[key](arg);
|
|
15
|
+
var value = info.value;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
reject(error);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (info.done) {
|
|
21
|
+
resolve(value);
|
|
22
|
+
} else {
|
|
23
|
+
Promise.resolve(value).then(_next, _throw);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _async_to_generator(fn) {
|
|
27
|
+
return function() {
|
|
28
|
+
var self = this, args = arguments;
|
|
29
|
+
return new Promise(function(resolve, reject) {
|
|
30
|
+
var gen = fn.apply(self, args);
|
|
31
|
+
function _next(value) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
33
|
+
}
|
|
34
|
+
function _throw(err) {
|
|
35
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
36
|
+
}
|
|
37
|
+
_next(undefined);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function _iterable_to_array(iter) {
|
|
42
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
43
|
+
}
|
|
44
|
+
function _iterable_to_array_limit(arr, i) {
|
|
45
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
46
|
+
if (_i == null) return;
|
|
47
|
+
var _arr = [];
|
|
48
|
+
var _n = true;
|
|
49
|
+
var _d = false;
|
|
50
|
+
var _s, _e;
|
|
51
|
+
try {
|
|
52
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
53
|
+
_arr.push(_s.value);
|
|
54
|
+
if (i && _arr.length === i) break;
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
_d = true;
|
|
58
|
+
_e = err;
|
|
59
|
+
} finally{
|
|
60
|
+
try {
|
|
61
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
62
|
+
} finally{
|
|
63
|
+
if (_d) throw _e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return _arr;
|
|
67
|
+
}
|
|
68
|
+
function _non_iterable_rest() {
|
|
69
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
|
+
}
|
|
71
|
+
function _non_iterable_spread() {
|
|
72
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
|
+
}
|
|
74
|
+
function _sliced_to_array(arr, i) {
|
|
75
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
76
|
+
}
|
|
77
|
+
function _to_consumable_array(arr) {
|
|
78
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
79
|
+
}
|
|
80
|
+
function _type_of(obj) {
|
|
81
|
+
"@swc/helpers - typeof";
|
|
82
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
83
|
+
}
|
|
84
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
85
|
+
if (!o) return;
|
|
86
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
87
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
88
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
89
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
90
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
91
|
+
}
|
|
92
|
+
function _ts_generator(thisArg, body) {
|
|
93
|
+
var f, y, t, _ = {
|
|
94
|
+
label: 0,
|
|
95
|
+
sent: function() {
|
|
96
|
+
if (t[0] & 1) throw t[1];
|
|
97
|
+
return t[1];
|
|
98
|
+
},
|
|
99
|
+
trys: [],
|
|
100
|
+
ops: []
|
|
101
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
102
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
103
|
+
return this;
|
|
104
|
+
}), g;
|
|
105
|
+
function verb(n) {
|
|
106
|
+
return function(v) {
|
|
107
|
+
return step([
|
|
108
|
+
n,
|
|
109
|
+
v
|
|
110
|
+
]);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function step(op) {
|
|
114
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
115
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
116
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
117
|
+
if (y = 0, t) op = [
|
|
118
|
+
op[0] & 2,
|
|
119
|
+
t.value
|
|
120
|
+
];
|
|
121
|
+
switch(op[0]){
|
|
122
|
+
case 0:
|
|
123
|
+
case 1:
|
|
124
|
+
t = op;
|
|
125
|
+
break;
|
|
126
|
+
case 4:
|
|
127
|
+
_.label++;
|
|
128
|
+
return {
|
|
129
|
+
value: op[1],
|
|
130
|
+
done: false
|
|
131
|
+
};
|
|
132
|
+
case 5:
|
|
133
|
+
_.label++;
|
|
134
|
+
y = op[1];
|
|
135
|
+
op = [
|
|
136
|
+
0
|
|
137
|
+
];
|
|
138
|
+
continue;
|
|
139
|
+
case 7:
|
|
140
|
+
op = _.ops.pop();
|
|
141
|
+
_.trys.pop();
|
|
142
|
+
continue;
|
|
143
|
+
default:
|
|
144
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
145
|
+
_ = 0;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
149
|
+
_.label = op[1];
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
153
|
+
_.label = t[1];
|
|
154
|
+
t = op;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (t && _.label < t[2]) {
|
|
158
|
+
_.label = t[2];
|
|
159
|
+
_.ops.push(op);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (t[2]) _.ops.pop();
|
|
163
|
+
_.trys.pop();
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
op = body.call(thisArg, _);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
op = [
|
|
169
|
+
6,
|
|
170
|
+
e
|
|
171
|
+
];
|
|
172
|
+
y = 0;
|
|
173
|
+
} finally{
|
|
174
|
+
f = t = 0;
|
|
175
|
+
}
|
|
176
|
+
if (op[0] & 5) throw op[1];
|
|
177
|
+
return {
|
|
178
|
+
value: op[0] ? op[1] : void 0,
|
|
179
|
+
done: true
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
import { createPublicKey, verify } from "node:crypto";
|
|
184
|
+
import { CreateStruct, createInstructionDiscriminator, isCreateArgsV1 } from "@metaplex-foundation/mpl-token-metadata";
|
|
185
|
+
import { ComputeBudgetProgram, PublicKey, Transaction } from "@solana/web3.js";
|
|
186
|
+
var TOKEN_METADATA_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
187
|
+
var TOKEN_METADATA_SEED = Buffer.from("metadata");
|
|
188
|
+
var TOKEN_METADATA_EDITION_SEED = Buffer.from("edition");
|
|
189
|
+
var ALLOWED_PUBLICATION_PROGRAM_IDS = new Set([
|
|
190
|
+
ComputeBudgetProgram.programId.toBase58(),
|
|
191
|
+
TOKEN_METADATA_PROGRAM_ID.toBase58()
|
|
192
|
+
]);
|
|
193
|
+
var ED25519_SPKI_PREFIX = Buffer.from("302a300506032b6570032100", "hex");
|
|
194
|
+
export var createPublicationSigner = function(adapter) {
|
|
195
|
+
return {
|
|
196
|
+
publicKey: adapter.publicKey,
|
|
197
|
+
signTransaction: adapter.signTransaction,
|
|
198
|
+
signMessage: adapter.signMessage
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export var isPublicationSigner = function(value) {
|
|
202
|
+
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && value !== null && "publicKey" in value && "signTransaction" in value && "signMessage" in value;
|
|
203
|
+
};
|
|
204
|
+
function assertExactAddressSet(actual, expected, label) {
|
|
205
|
+
var normalizedActual = _to_consumable_array(new Set(actual)).sort();
|
|
206
|
+
var normalizedExpected = _to_consumable_array(new Set(expected)).sort();
|
|
207
|
+
if (normalizedActual.length !== normalizedExpected.length || normalizedActual.some(function(value, index) {
|
|
208
|
+
return value !== normalizedExpected[index];
|
|
209
|
+
})) {
|
|
210
|
+
throw new Error("".concat(label, " signer set mismatch. Expected ").concat(normalizedExpected.join(", "), "; received ").concat(normalizedActual.join(", ") || "[none]", "."));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function assertAccountsPresent(accountAddresses, expectedAddresses) {
|
|
214
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
215
|
+
try {
|
|
216
|
+
for(var _iterator = expectedAddresses[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
217
|
+
var _step_value = _sliced_to_array(_step.value, 2), label = _step_value[0], address = _step_value[1];
|
|
218
|
+
if (!accountAddresses.includes(address)) {
|
|
219
|
+
throw new Error("Portal transaction is missing the expected ".concat(label, " account: ").concat(address));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} catch (err) {
|
|
223
|
+
_didIteratorError = true;
|
|
224
|
+
_iteratorError = err;
|
|
225
|
+
} finally{
|
|
226
|
+
try {
|
|
227
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
228
|
+
_iterator.return();
|
|
229
|
+
}
|
|
230
|
+
} finally{
|
|
231
|
+
if (_didIteratorError) {
|
|
232
|
+
throw _iteratorError;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function assertExistingSignaturesValid(transaction) {
|
|
238
|
+
var signedEntries = transaction.signatures.filter(function(param) {
|
|
239
|
+
var signature = param.signature;
|
|
240
|
+
return signature !== null;
|
|
241
|
+
});
|
|
242
|
+
if (signedEntries.length === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
var message = transaction.serializeMessage();
|
|
246
|
+
var invalidSigners = signedEntries.filter(function(param) {
|
|
247
|
+
var publicKey = param.publicKey, signature = param.signature;
|
|
248
|
+
return !verify(null, message, createPublicKey({
|
|
249
|
+
key: Buffer.concat([
|
|
250
|
+
ED25519_SPKI_PREFIX,
|
|
251
|
+
Buffer.from(publicKey.toBytes())
|
|
252
|
+
]),
|
|
253
|
+
format: "der",
|
|
254
|
+
type: "spki"
|
|
255
|
+
}), signature);
|
|
256
|
+
}).map(function(param) {
|
|
257
|
+
var publicKey = param.publicKey;
|
|
258
|
+
return publicKey.toBase58();
|
|
259
|
+
});
|
|
260
|
+
if (invalidSigners.length > 0) {
|
|
261
|
+
throw new Error("Portal transaction contains invalid existing signatures for ".concat(invalidSigners.join(", "), " and may have been modified in transit."));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function getTokenMetadataCreateCollectionAddress(transaction) {
|
|
265
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
266
|
+
try {
|
|
267
|
+
for(var _iterator = transaction.instructions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
268
|
+
var instruction = _step.value;
|
|
269
|
+
if (!instruction.programId.equals(TOKEN_METADATA_PROGRAM_ID)) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (instruction.data.length === 0 || instruction.data[0] !== createInstructionDiscriminator) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
var _decodedInstruction_createArgs_assetData_collection;
|
|
277
|
+
var _CreateStruct_deserialize = _sliced_to_array(CreateStruct.deserialize(instruction.data), 1), decodedInstruction = _CreateStruct_deserialize[0];
|
|
278
|
+
if (!isCreateArgsV1(decodedInstruction.createArgs)) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
var _decodedInstruction_createArgs_assetData_collection_key_toBase58;
|
|
282
|
+
return (_decodedInstruction_createArgs_assetData_collection_key_toBase58 = (_decodedInstruction_createArgs_assetData_collection = decodedInstruction.createArgs.assetData.collection) === null || _decodedInstruction_createArgs_assetData_collection === void 0 ? void 0 : _decodedInstruction_createArgs_assetData_collection.key.toBase58()) !== null && _decodedInstruction_createArgs_assetData_collection_key_toBase58 !== void 0 ? _decodedInstruction_createArgs_assetData_collection_key_toBase58 : null;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
throw new Error("Portal transaction contains an invalid token metadata create instruction.");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
_didIteratorError = true;
|
|
289
|
+
_iteratorError = err;
|
|
290
|
+
} finally{
|
|
291
|
+
try {
|
|
292
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
293
|
+
_iterator.return();
|
|
294
|
+
}
|
|
295
|
+
} finally{
|
|
296
|
+
if (_didIteratorError) {
|
|
297
|
+
throw _iteratorError;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
function getMetadataPdaAddress(mintAddress) {
|
|
304
|
+
return PublicKey.findProgramAddressSync([
|
|
305
|
+
TOKEN_METADATA_SEED,
|
|
306
|
+
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
|
|
307
|
+
new PublicKey(mintAddress).toBuffer()
|
|
308
|
+
], TOKEN_METADATA_PROGRAM_ID)[0].toBase58();
|
|
309
|
+
}
|
|
310
|
+
function getMasterEditionPdaAddress(mintAddress) {
|
|
311
|
+
return PublicKey.findProgramAddressSync([
|
|
312
|
+
TOKEN_METADATA_SEED,
|
|
313
|
+
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
|
|
314
|
+
new PublicKey(mintAddress).toBuffer(),
|
|
315
|
+
TOKEN_METADATA_EDITION_SEED
|
|
316
|
+
], TOKEN_METADATA_PROGRAM_ID)[0].toBase58();
|
|
317
|
+
}
|
|
318
|
+
function validatePublicationTransaction(signer, transaction, validation) {
|
|
319
|
+
var _transaction_feePayer;
|
|
320
|
+
if (transaction.recentBlockhash !== validation.expectedBlockhash) {
|
|
321
|
+
throw new Error("Portal transaction blockhash mismatch. Expected ".concat(validation.expectedBlockhash, "; received ").concat(transaction.recentBlockhash, "."));
|
|
322
|
+
}
|
|
323
|
+
var feePayerAddress = (_transaction_feePayer = transaction.feePayer) === null || _transaction_feePayer === void 0 ? void 0 : _transaction_feePayer.toBase58();
|
|
324
|
+
if (!feePayerAddress) {
|
|
325
|
+
throw new Error("Portal transaction is missing a fee payer.");
|
|
326
|
+
}
|
|
327
|
+
if (feePayerAddress !== validation.expectedFeePayerAddress) {
|
|
328
|
+
throw new Error("Portal transaction fee payer mismatch. Expected ".concat(validation.expectedFeePayerAddress, "; received ").concat(feePayerAddress, "."));
|
|
329
|
+
}
|
|
330
|
+
if (signer.publicKey !== validation.expectedSignerAddress) {
|
|
331
|
+
throw new Error("Publication signer mismatch. Expected ".concat(validation.expectedSignerAddress, "; received ").concat(signer.publicKey, "."));
|
|
332
|
+
}
|
|
333
|
+
assertExistingSignaturesValid(transaction);
|
|
334
|
+
var compiledMessage = transaction.compileMessage();
|
|
335
|
+
var accountAddresses = compiledMessage.accountKeys.map(function(key) {
|
|
336
|
+
return key.toBase58();
|
|
337
|
+
});
|
|
338
|
+
var requiredSignerAddresses = compiledMessage.accountKeys.slice(0, compiledMessage.header.numRequiredSignatures).map(function(key) {
|
|
339
|
+
return key.toBase58();
|
|
340
|
+
});
|
|
341
|
+
if (!requiredSignerAddresses.includes(signer.publicKey)) {
|
|
342
|
+
throw new Error("Portal transaction does not require the local signer ".concat(signer.publicKey, "."));
|
|
343
|
+
}
|
|
344
|
+
var unexpectedPrograms = transaction.instructions.map(function(instruction) {
|
|
345
|
+
return instruction.programId.toBase58();
|
|
346
|
+
}).filter(function(programId) {
|
|
347
|
+
return !ALLOWED_PUBLICATION_PROGRAM_IDS.has(programId);
|
|
348
|
+
});
|
|
349
|
+
if (unexpectedPrograms.length > 0) {
|
|
350
|
+
throw new Error("Portal transaction includes unexpected program ids: ".concat(_to_consumable_array(new Set(unexpectedPrograms)).join(", ")));
|
|
351
|
+
}
|
|
352
|
+
if (!transaction.instructions.some(function(instruction) {
|
|
353
|
+
return instruction.programId.equals(TOKEN_METADATA_PROGRAM_ID);
|
|
354
|
+
})) {
|
|
355
|
+
throw new Error("Portal transaction is missing the expected token metadata instruction.");
|
|
356
|
+
}
|
|
357
|
+
if (validation.kind === "release-mint") {
|
|
358
|
+
var _transaction_signatures_find;
|
|
359
|
+
assertExactAddressSet(requiredSignerAddresses, [
|
|
360
|
+
validation.expectedFeePayerAddress,
|
|
361
|
+
validation.expectedMintAddress
|
|
362
|
+
], "Release mint transaction");
|
|
363
|
+
assertAccountsPresent(accountAddresses, [
|
|
364
|
+
[
|
|
365
|
+
"release mint",
|
|
366
|
+
validation.expectedMintAddress
|
|
367
|
+
]
|
|
368
|
+
]);
|
|
369
|
+
var actualCollectionMintAddress = getTokenMetadataCreateCollectionAddress(transaction);
|
|
370
|
+
if (actualCollectionMintAddress !== validation.expectedAppMintAddress) {
|
|
371
|
+
throw new Error("Portal transaction token metadata collection mismatch. Expected ".concat(validation.expectedAppMintAddress, "; received ").concat(actualCollectionMintAddress !== null && actualCollectionMintAddress !== void 0 ? actualCollectionMintAddress : "[none]", "."));
|
|
372
|
+
}
|
|
373
|
+
var mintSignature = (_transaction_signatures_find = transaction.signatures.find(function(param) {
|
|
374
|
+
var publicKey = param.publicKey;
|
|
375
|
+
return publicKey.equals(new PublicKey(validation.expectedMintAddress));
|
|
376
|
+
})) === null || _transaction_signatures_find === void 0 ? void 0 : _transaction_signatures_find.signature;
|
|
377
|
+
if (!mintSignature) {
|
|
378
|
+
throw new Error("Release mint transaction is missing the pre-signed mint signature.");
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
assertExactAddressSet(requiredSignerAddresses, [
|
|
383
|
+
validation.expectedFeePayerAddress,
|
|
384
|
+
validation.expectedCollectionAuthority
|
|
385
|
+
], "Collection verification transaction");
|
|
386
|
+
assertAccountsPresent(accountAddresses, [
|
|
387
|
+
[
|
|
388
|
+
"release metadata",
|
|
389
|
+
getMetadataPdaAddress(validation.expectedNftMintAddress)
|
|
390
|
+
],
|
|
391
|
+
[
|
|
392
|
+
"app collection mint",
|
|
393
|
+
validation.expectedCollectionMintAddress
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
"app collection metadata",
|
|
397
|
+
getMetadataPdaAddress(validation.expectedCollectionMintAddress)
|
|
398
|
+
],
|
|
399
|
+
[
|
|
400
|
+
"app collection master edition",
|
|
401
|
+
getMasterEditionPdaAddress(validation.expectedCollectionMintAddress)
|
|
402
|
+
],
|
|
403
|
+
[
|
|
404
|
+
"collection authority",
|
|
405
|
+
validation.expectedCollectionAuthority
|
|
406
|
+
]
|
|
407
|
+
]);
|
|
408
|
+
}
|
|
409
|
+
export var signSerializedTransaction = function(signer, serializedTransaction, validation) {
|
|
410
|
+
return _async_to_generator(function() {
|
|
411
|
+
var transaction, signedTransaction;
|
|
412
|
+
return _ts_generator(this, function(_state) {
|
|
413
|
+
switch(_state.label){
|
|
414
|
+
case 0:
|
|
415
|
+
transaction = Transaction.from(Buffer.from(serializedTransaction, "base64"));
|
|
416
|
+
if (validation) {
|
|
417
|
+
validatePublicationTransaction(signer, transaction, validation);
|
|
418
|
+
}
|
|
419
|
+
return [
|
|
420
|
+
4,
|
|
421
|
+
signer.signTransaction(transaction)
|
|
422
|
+
];
|
|
423
|
+
case 1:
|
|
424
|
+
signedTransaction = _state.sent();
|
|
425
|
+
return [
|
|
426
|
+
2,
|
|
427
|
+
signedTransaction.serialize().toString("base64")
|
|
428
|
+
];
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
})();
|
|
432
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|