Skip to content

Commit 619f176

Browse files
authored
Generate UUID by crypto (#1082)
This PR replaces the use of the "uuid" library with Node’s built-in crypto module for generating UUIDs (nodejs >= v14.17.0). - Removed dependency on the "uuid" package in test and library files. - Replaced uuidv4() calls with crypto.randomUUID() calls for generating UUIDs. Reference: - https://nodejs.org/docs/latest-v22.x/api/crypto.html#cryptorandomuuidoptions Fix: #1081
1 parent 59d758c commit 619f176

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

lib/action/uuid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const ActionInterfaces = require('./interfaces.js');
18-
const { v4: uuidv4 } = require('uuid');
18+
const { randomUUID } = require('crypto');
1919

2020
/**
2121
* @class - Represents a unique identifier used by actions.
@@ -37,7 +37,7 @@ class ActionUuid {
3737
this._bytes = bytes;
3838
} else {
3939
// Generate random UUID.
40-
let uuid = uuidv4().replace(/-/g, '');
40+
let uuid = randomUUID().replace(/-/g, '');
4141
this._bytes = Uint8Array.from(Buffer.from(uuid, 'hex'));
4242
}
4343
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"nan": "^2.22.0",
8282
"prettier": "^3.4.2",
8383
"rimraf": "^6.0.1",
84-
"uuid": "^11.0.3",
8584
"walk": "^2.3.15"
8685
},
8786
"husky": {

test/test-action-client.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
const assert = require('assert');
1818
const sinon = require('sinon');
19-
const { v4: uuidv4 } = require('uuid');
2019
const assertUtils = require('./utils.js');
2120
const rclnodejs = require('../index.js');
2221
const { ActionUuid } = require('../index.js');

test/test-action-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
const assert = require('assert');
1818
const deepEqual = require('deep-equal');
19-
const { v4: uuidv4 } = require('uuid');
2019
const assertUtils = require('./utils.js');
20+
const { randomUUID } = require('crypto');
2121
const rclnodejs = require('../index.js');
2222

2323
describe('rclnodejs action server', function () {
@@ -34,7 +34,7 @@ describe('rclnodejs action server', function () {
3434
}
3535

3636
function createUuid() {
37-
let uuid = uuidv4().replace(/-/g, '');
37+
let uuid = randomUUID().replace(/-/g, '');
3838
let bytes = Uint8Array.from(Buffer.from(uuid, 'hex'));
3939

4040
let UUID = rclnodejs.require('unique_identifier_msgs/msg/UUID');

0 commit comments

Comments
 (0)