@contentauth/c2pa-node 0.1.0 → 0.1.2
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/dist/Builder.js +199 -0
- package/dist/Builder.spec.js +308 -0
- package/dist/IdentityAssertion.js +94 -0
- package/dist/IdentityAssertion.spec.js +177 -0
- package/dist/Reader.js +108 -0
- package/dist/Reader.spec.js +244 -0
- package/dist/Signer.js +117 -0
- package/dist/Signer.spec.js +132 -0
- package/dist/Trustmark.js +79 -0
- package/dist/Trustmark.spec.js +184 -0
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +22 -0
- package/dist/types/Builder.spec.d.ts +1 -0
- package/dist/types/IdentityAssertion.d.ts +17 -0
- package/dist/types/IdentityAssertion.spec.d.ts +1 -0
- package/dist/types/Reader.d.ts +14 -0
- package/dist/types/Reader.spec.d.ts +1 -0
- package/dist/types/Signer.d.ts +23 -0
- package/dist/types/Signer.spec.d.ts +1 -0
- package/dist/types/Trustmark.d.ts +8 -0
- package/dist/types/Trustmark.spec.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.node.d.ts +16 -0
- package/dist/types/types.d.ts +893 -0
- package/package.json +16 -19
package/dist/Builder.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
// This file is licensed to you under the Apache License,
|
|
4
|
+
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
5
|
+
// or the MIT license (http://opensource.org/licenses/MIT),
|
|
6
|
+
// at your option.
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.Builder = void 0;
|
|
51
|
+
// Unless required by applicable law or agreed to in writing,
|
|
52
|
+
// this software is distributed on an "AS IS" BASIS, WITHOUT
|
|
53
|
+
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
54
|
+
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
55
|
+
// specific language governing permissions and limitations under
|
|
56
|
+
// each license.
|
|
57
|
+
const neon = __importStar(require("index.node"));
|
|
58
|
+
class Builder {
|
|
59
|
+
constructor(builder) {
|
|
60
|
+
this.builder = builder;
|
|
61
|
+
}
|
|
62
|
+
static new() {
|
|
63
|
+
const builder = neon.builderNew();
|
|
64
|
+
return new Builder(builder);
|
|
65
|
+
}
|
|
66
|
+
static withJson(json) {
|
|
67
|
+
let jsonString;
|
|
68
|
+
try {
|
|
69
|
+
jsonString = JSON.stringify(json);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// TODO: errors should be standardized across JS and Node
|
|
73
|
+
if (error instanceof Error) {
|
|
74
|
+
throw new Error(`Failed to stringify JSON Manifest Definition: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Failed to stringify JSON Manifest Definition: Unknown error');
|
|
77
|
+
}
|
|
78
|
+
const builder = neon.builderWithJson(jsonString);
|
|
79
|
+
return new Builder(builder);
|
|
80
|
+
}
|
|
81
|
+
setNoEmbed(noEmbed = true) {
|
|
82
|
+
neon.builderSetNoEmbed.call(this.builder, noEmbed);
|
|
83
|
+
}
|
|
84
|
+
setRemoteUrl(remoteUrl) {
|
|
85
|
+
neon.builderSetRemoteUrl.call(this.builder, remoteUrl);
|
|
86
|
+
}
|
|
87
|
+
addAssertion(label, assertion, assertionKind) {
|
|
88
|
+
return neon.builderAddAssertion.call(this.builder, label, assertion, assertionKind);
|
|
89
|
+
}
|
|
90
|
+
addResource(uri, resource) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
return neon.builderAddResource.call(this.builder, uri, resource);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
addIngredient(ingredientJson, ingredient) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return neon.builderAddIngredient.call(this.builder, ingredientJson, ingredient);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
toArchive(asset) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return neon.builderToArchive.call(this.builder, asset);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static fromArchive(asset) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
return new Builder(yield neon.builderFromArchive(asset));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
sign(signer, input, output) {
|
|
111
|
+
return neon.builderSign.call(this.builder, signer.signer(), input, output);
|
|
112
|
+
}
|
|
113
|
+
signFile(signer, filePath, output) {
|
|
114
|
+
const input = { path: filePath };
|
|
115
|
+
return neon.builderSign.call(this.builder, signer.signer(), input, output);
|
|
116
|
+
}
|
|
117
|
+
signConfigAsync(callback, signerConfig, input, output) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return neon.builderSignConfigAsync
|
|
120
|
+
.call(this.builder, callback, signerConfig, input, output)
|
|
121
|
+
.then((result) => {
|
|
122
|
+
// output is a buffer and result is the manifest and the signed asset.
|
|
123
|
+
if ('buffer' in output) {
|
|
124
|
+
if ('signedAsset' in result && 'manifest' in result) {
|
|
125
|
+
output.buffer = result.signedAsset;
|
|
126
|
+
return result.manifest;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw new Error('Unexpected result for DestinationBuffer');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// output is a file and result is the bytes of the manifest.
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
.catch((error) => {
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
signAsync(signer, input, output) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
return neon.builderSignAsync
|
|
145
|
+
.call(this.builder, signer.signer(), input, output)
|
|
146
|
+
.then((result) => {
|
|
147
|
+
// output is a buffer and result is the manifest and the signed asset.
|
|
148
|
+
if ('buffer' in output) {
|
|
149
|
+
if ('signedAsset' in result && 'manifest' in result) {
|
|
150
|
+
output.buffer = result.signedAsset;
|
|
151
|
+
return result.manifest;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
throw new Error('Unexpected result for DestinationBuffer');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// output is a file and result is the bytes of the manifest.
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
.catch((error) => {
|
|
163
|
+
throw error;
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
identitySignAsync(signer, input, output) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return neon.builderIdentitySignAsync
|
|
170
|
+
.call(this.builder, signer.signer(), input, output)
|
|
171
|
+
.then((result) => {
|
|
172
|
+
// output is a buffer and result is the manifest and the signed asset.
|
|
173
|
+
if ('buffer' in output) {
|
|
174
|
+
if ('signedAsset' in result && 'manifest' in result) {
|
|
175
|
+
output.buffer = result.signedAsset;
|
|
176
|
+
return result.manifest;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new Error('Unexpected result for DestinationBuffer');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// output is a file and result is the bytes of the manifest.
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
.catch((error) => {
|
|
188
|
+
throw error;
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
getManifestDefinition() {
|
|
193
|
+
return JSON.parse(neon.builderManifestDefinition.call(this.builder));
|
|
194
|
+
}
|
|
195
|
+
updateManifestProperty(property, value) {
|
|
196
|
+
neon.builderUpdateManifestProperty.call(this.builder, property, value);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.Builder = Builder;
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
// This file is licensed to you under the Apache License,
|
|
4
|
+
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
5
|
+
// or the MIT license (http://opensource.org/licenses/MIT),
|
|
6
|
+
// at your option.
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
// Unless required by applicable law or agreed to in writing,
|
|
54
|
+
// this software is distributed on an "AS IS" BASIS, WITHOUT
|
|
55
|
+
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
56
|
+
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
57
|
+
// specific language governing permissions and limitations under
|
|
58
|
+
// each license.
|
|
59
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
60
|
+
const index_1 = require("./index");
|
|
61
|
+
const fs = __importStar(require("fs-extra"));
|
|
62
|
+
const path_1 = __importDefault(require("path"));
|
|
63
|
+
const crypto = __importStar(require("crypto"));
|
|
64
|
+
const tempDir = path_1.default.join(__dirname, 'tmp');
|
|
65
|
+
class TestSigner {
|
|
66
|
+
constructor(privateKey) {
|
|
67
|
+
this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const sign = crypto.createSign('SHA256');
|
|
69
|
+
sign.update(bytes);
|
|
70
|
+
sign.end();
|
|
71
|
+
const signature = sign.sign(this.privateKey);
|
|
72
|
+
return signature;
|
|
73
|
+
});
|
|
74
|
+
this.privateKey = crypto.createPrivateKey({
|
|
75
|
+
key: privateKey,
|
|
76
|
+
format: 'pem',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
describe('TestSigner', () => {
|
|
81
|
+
it('should sign data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const signer = new TestSigner(yield fs.readFile('./tests/fixtures/certs/es256.pem'));
|
|
83
|
+
const bytes = Buffer.from('Hello, World!');
|
|
84
|
+
const signature = yield signer.sign(bytes);
|
|
85
|
+
expect(signature.length).toBeGreaterThan(0);
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
describe('Builder', () => {
|
|
89
|
+
const parent_json = `{
|
|
90
|
+
"title": "c2pa-bindings Test",
|
|
91
|
+
"format": "image/jpeg",
|
|
92
|
+
"instance_id": "12345",
|
|
93
|
+
"relationship": "parentOf"
|
|
94
|
+
}`;
|
|
95
|
+
const thumbnail_ref = {
|
|
96
|
+
format: 'ingredient/jpeg',
|
|
97
|
+
identifier: '5678',
|
|
98
|
+
};
|
|
99
|
+
const manifestDefinition = {
|
|
100
|
+
vendor: 'test',
|
|
101
|
+
claim_generator_info: [
|
|
102
|
+
{
|
|
103
|
+
name: 'c2pa_test',
|
|
104
|
+
version: '1.0.0',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
metadata: [
|
|
108
|
+
{
|
|
109
|
+
dateTime: '1985-04-12T23:20:50.52Z',
|
|
110
|
+
my_custom_metadata: 'my custom metatdata value',
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
title: 'Test_Manifest',
|
|
114
|
+
format: 'image/tiff',
|
|
115
|
+
instance_id: '1234',
|
|
116
|
+
thumbnail: {
|
|
117
|
+
format: 'image/jpeg',
|
|
118
|
+
identifier: 'thumbnail.jpg',
|
|
119
|
+
},
|
|
120
|
+
ingredients: [
|
|
121
|
+
{
|
|
122
|
+
title: 'Test',
|
|
123
|
+
format: 'image/jpeg',
|
|
124
|
+
instance_id: '12345',
|
|
125
|
+
relationship: 'componentOf',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
assertions: [
|
|
129
|
+
{
|
|
130
|
+
label: 'org.test.assertion',
|
|
131
|
+
data: 'assertion',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
let testAssertion;
|
|
136
|
+
let testThumbnail;
|
|
137
|
+
let source;
|
|
138
|
+
let publicKey;
|
|
139
|
+
let privateKey;
|
|
140
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
+
yield fs.ensureDir(tempDir);
|
|
142
|
+
// Read all test files once
|
|
143
|
+
source = {
|
|
144
|
+
buffer: yield fs.readFile('./tests/fixtures/CA.jpg'),
|
|
145
|
+
mimeType: 'jpeg',
|
|
146
|
+
};
|
|
147
|
+
testThumbnail = yield fs.readFile('./tests/fixtures/thumbnail.jpg');
|
|
148
|
+
publicKey = yield fs.readFile('./tests/fixtures/certs/es256.pub');
|
|
149
|
+
privateKey = yield fs.readFile('./tests/fixtures/certs/es256.pem');
|
|
150
|
+
testAssertion = JSON.stringify({ answer: 42 });
|
|
151
|
+
}));
|
|
152
|
+
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
+
yield fs.remove(tempDir);
|
|
154
|
+
}));
|
|
155
|
+
it('should build a manifest store', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const test_definition = {
|
|
157
|
+
claim_generator_info: [
|
|
158
|
+
{
|
|
159
|
+
name: 'c2pa-js tests',
|
|
160
|
+
version: '1.0.0',
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
format: 'image/tiff',
|
|
164
|
+
instance_id: '1234',
|
|
165
|
+
title: 'builder-test-manifest',
|
|
166
|
+
vendor: 'test',
|
|
167
|
+
thumbnail: thumbnail_ref,
|
|
168
|
+
label: 'ABCDE',
|
|
169
|
+
};
|
|
170
|
+
const builder = index_1.Builder.withJson(test_definition);
|
|
171
|
+
yield builder.addIngredient(parent_json, source);
|
|
172
|
+
builder.addAssertion('org.test.assertion', 'assertion');
|
|
173
|
+
yield builder.addResource(thumbnail_ref.identifier, {
|
|
174
|
+
buffer: Buffer.from('12345'),
|
|
175
|
+
mimeType: 'jpeg',
|
|
176
|
+
});
|
|
177
|
+
// Wait for any pending async operations
|
|
178
|
+
yield Promise.resolve();
|
|
179
|
+
const definition = builder.getManifestDefinition();
|
|
180
|
+
expect(definition.vendor).toBe('test');
|
|
181
|
+
expect(definition.title).toBe('builder-test-manifest');
|
|
182
|
+
expect(definition.format).toBe('image/tiff');
|
|
183
|
+
expect(definition.instance_id).toBe('1234');
|
|
184
|
+
expect(definition.ingredients[0].title).toStrictEqual('c2pa-bindings Test');
|
|
185
|
+
expect(definition.assertions[0].label).toBe('org.test.assertion');
|
|
186
|
+
expect(definition.label).toBe('ABCDE');
|
|
187
|
+
}));
|
|
188
|
+
describe('Sign and Archive', () => {
|
|
189
|
+
let builder;
|
|
190
|
+
beforeEach(() => {
|
|
191
|
+
builder = index_1.Builder.withJson(manifestDefinition);
|
|
192
|
+
builder.updateManifestProperty('claim_version', 1);
|
|
193
|
+
});
|
|
194
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
|
+
// Add ingredients and resources after builder is initialized
|
|
196
|
+
yield builder.addIngredient(parent_json, source);
|
|
197
|
+
yield builder.addResource('thumbnail.jpg', {
|
|
198
|
+
mimeType: 'jpeg',
|
|
199
|
+
buffer: testThumbnail,
|
|
200
|
+
});
|
|
201
|
+
yield builder.addResource('prompt.txt', {
|
|
202
|
+
buffer: Buffer.from('a random prompt'),
|
|
203
|
+
mimeType: 'text/plain',
|
|
204
|
+
});
|
|
205
|
+
builder.addAssertion('org.life.meaning', testAssertion);
|
|
206
|
+
builder.addAssertion('org.life.meaning.json', testAssertion, 'Json');
|
|
207
|
+
// Wait for any pending operations
|
|
208
|
+
yield Promise.resolve();
|
|
209
|
+
}));
|
|
210
|
+
it('should sign data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
const dest = { path: path_1.default.join(tempDir, 'signed.jpg') };
|
|
212
|
+
const signer = index_1.LocalSigner.newSigner(publicKey, privateKey, 'es256');
|
|
213
|
+
const bytes = builder.sign(signer, source, dest);
|
|
214
|
+
expect(bytes.length).toBeGreaterThan(0);
|
|
215
|
+
const reader = yield index_1.Reader.fromAsset(dest);
|
|
216
|
+
const manifestStore = reader.json();
|
|
217
|
+
const activeManifest = reader.getActive();
|
|
218
|
+
expect(manifestStore.validation_status).toBeUndefined();
|
|
219
|
+
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
220
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
|
|
221
|
+
}));
|
|
222
|
+
it('should archive and construct from archive', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
+
const dest = {
|
|
224
|
+
buffer: null,
|
|
225
|
+
};
|
|
226
|
+
const signer = index_1.LocalSigner.newSigner(publicKey, privateKey, 'es256');
|
|
227
|
+
const outputPath = path_1.default.join(tempDir, 'archive.zip');
|
|
228
|
+
const archive = { path: outputPath };
|
|
229
|
+
yield builder.toArchive(archive);
|
|
230
|
+
const builder2 = yield index_1.Builder.fromArchive(archive);
|
|
231
|
+
builder2.sign(signer, source, dest);
|
|
232
|
+
const reader = yield index_1.Reader.fromAsset({
|
|
233
|
+
buffer: dest.buffer,
|
|
234
|
+
mimeType: 'jpeg',
|
|
235
|
+
});
|
|
236
|
+
const manifestStore = reader.json();
|
|
237
|
+
const activeManifest = reader.getActive();
|
|
238
|
+
expect(manifestStore.validation_status).toBeUndefined();
|
|
239
|
+
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
240
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
|
|
241
|
+
}));
|
|
242
|
+
it('should sign data with callback to file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
+
const dest = { path: path_1.default.join(tempDir, 'callback_signed.jpg') };
|
|
244
|
+
const signerConfig = {
|
|
245
|
+
alg: 'es256',
|
|
246
|
+
certs: [publicKey],
|
|
247
|
+
reserveSize: 10000,
|
|
248
|
+
tsaUrl: undefined,
|
|
249
|
+
};
|
|
250
|
+
const signer = new TestSigner(privateKey);
|
|
251
|
+
const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
|
|
252
|
+
expect(bytes.length).toBeGreaterThan(0);
|
|
253
|
+
const reader = yield index_1.Reader.fromAsset(dest);
|
|
254
|
+
const manifestStore = reader.json();
|
|
255
|
+
const activeManifest = reader.getActive();
|
|
256
|
+
expect(manifestStore.validation_status).toBeUndefined();
|
|
257
|
+
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
258
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
|
|
259
|
+
}));
|
|
260
|
+
it('should sign data with callback to buffer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
261
|
+
const dest = {
|
|
262
|
+
buffer: null,
|
|
263
|
+
};
|
|
264
|
+
const signerConfig = {
|
|
265
|
+
alg: 'es256',
|
|
266
|
+
certs: [publicKey],
|
|
267
|
+
reserveSize: 10000,
|
|
268
|
+
tsaUrl: undefined,
|
|
269
|
+
};
|
|
270
|
+
const signer = new TestSigner(privateKey);
|
|
271
|
+
const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
|
|
272
|
+
expect(bytes.length).toBeGreaterThan(0);
|
|
273
|
+
const reader = yield index_1.Reader.fromAsset({
|
|
274
|
+
buffer: dest.buffer,
|
|
275
|
+
mimeType: 'jpeg',
|
|
276
|
+
});
|
|
277
|
+
const manifestStore = reader.json();
|
|
278
|
+
const activeManifest = reader.getActive();
|
|
279
|
+
expect(manifestStore.validation_status).toBeUndefined();
|
|
280
|
+
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
281
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
|
|
282
|
+
}));
|
|
283
|
+
it('should sign data with callback signer to buffer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
|
+
const dest = {
|
|
285
|
+
buffer: null,
|
|
286
|
+
};
|
|
287
|
+
const signerConfig = {
|
|
288
|
+
alg: 'es256',
|
|
289
|
+
certs: [publicKey],
|
|
290
|
+
reserveSize: 10000,
|
|
291
|
+
tsaUrl: undefined,
|
|
292
|
+
};
|
|
293
|
+
const testSigner = new TestSigner(privateKey);
|
|
294
|
+
const signer = index_1.CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
295
|
+
const bytes = yield builder.signAsync(signer, source, dest);
|
|
296
|
+
expect(bytes.length).toBeGreaterThan(0);
|
|
297
|
+
const reader = yield index_1.Reader.fromAsset({
|
|
298
|
+
buffer: dest.buffer,
|
|
299
|
+
mimeType: 'jpeg',
|
|
300
|
+
});
|
|
301
|
+
const manifestStore = reader.json();
|
|
302
|
+
const activeManifest = reader.getActive();
|
|
303
|
+
expect(manifestStore.validation_status).toBeUndefined();
|
|
304
|
+
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
305
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
// This file is licensed to you under the Apache License,
|
|
4
|
+
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
5
|
+
// or the MIT license (http://opensource.org/licenses/MIT),
|
|
6
|
+
// at your option.
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.IdentityAssertionSigner = exports.IdentityAssertionBuilder = void 0;
|
|
51
|
+
// Unless required by applicable law or agreed to in writing,
|
|
52
|
+
// this software is distributed on an "AS IS" BASIS, WITHOUT
|
|
53
|
+
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
54
|
+
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
55
|
+
// specific language governing permissions and limitations under
|
|
56
|
+
// each license.
|
|
57
|
+
const neon = __importStar(require("index.node"));
|
|
58
|
+
class IdentityAssertionBuilder {
|
|
59
|
+
constructor(_builder) {
|
|
60
|
+
this._builder = _builder;
|
|
61
|
+
}
|
|
62
|
+
static identityBuilderForCredentialHolder(credentialHolder) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const builder = neon.identityBuilderForCredentialHolder(credentialHolder.signer());
|
|
65
|
+
return new IdentityAssertionBuilder(builder);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
addReferencedAssertions(referencedAssertions) {
|
|
69
|
+
neon.identityBuilderAddReferencedAssertions.call(this._builder, referencedAssertions);
|
|
70
|
+
}
|
|
71
|
+
addRoles(roles) {
|
|
72
|
+
neon.identityBuilderAddRoles.call(this._builder, roles);
|
|
73
|
+
}
|
|
74
|
+
builder() {
|
|
75
|
+
return this._builder;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.IdentityAssertionBuilder = IdentityAssertionBuilder;
|
|
79
|
+
class IdentityAssertionSigner {
|
|
80
|
+
constructor(_signer) {
|
|
81
|
+
this._signer = _signer;
|
|
82
|
+
}
|
|
83
|
+
static new(signer) {
|
|
84
|
+
const identitySigner = neon.identitySignerNew(signer.signer());
|
|
85
|
+
return new IdentityAssertionSigner(identitySigner);
|
|
86
|
+
}
|
|
87
|
+
addIdentityAssertion(identityAssertionBuilder) {
|
|
88
|
+
neon.identitySignerAddIdentityAssertion.call(this._signer, identityAssertionBuilder.builder());
|
|
89
|
+
}
|
|
90
|
+
signer() {
|
|
91
|
+
return this._signer;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.IdentityAssertionSigner = IdentityAssertionSigner;
|